Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 8ec1cd7

Browse files
committed
Fix some auto-unignore issues.
1 parent 1d1a878 commit 8ec1cd7

3 files changed

Lines changed: 48 additions & 12 deletions

File tree

xtask/src/file_analyzer.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::path::Path;
44

55
use anyhow::ensure;
66

7-
use crate::run_cargo::{CargoTestArgs, LogFilterLevel};
7+
use crate::{
8+
run_cargo,
9+
run_cargo::{CargoTestArgs, LogFilterLevel},
10+
};
811

912
/// Command builder for running tests/base.rs
1013
pub struct TestBaseArgs<'a> {
@@ -16,7 +19,7 @@ impl<'a> TestBaseArgs<'a> {
1619
/// Create an empty TestBaseArgs.
1720
pub fn new() -> Self {
1821
Self {
19-
inner: CargoTestArgs::new("stc_ts_file_analyzer").with_test("base"),
22+
inner: CargoTestArgs::new("stc_ts_file_analyzer").with_test("base").with_lib(true),
2023
ignored: false,
2124
}
2225
}
@@ -42,6 +45,13 @@ impl<'a> TestBaseArgs<'a> {
4245
self
4346
}
4447

48+
/// Set cargo test --lib to run the unit tests in the library
49+
#[must_use]
50+
pub fn with_lib(mut self, lib: bool) -> Self {
51+
self.inner = self.inner.with_lib(lib);
52+
self
53+
}
54+
4555
/// cargo test --ignored: Whether to run ignored tests. Used by
4656
/// auto-unignore.
4757
#[must_use]
@@ -60,11 +70,7 @@ impl<'a> TestBaseArgs<'a> {
6070
pub fn to_command(&self) -> std::process::Command {
6171
let mut cmd = self.inner.to_command();
6272

63-
cmd.env("UPDATE", "1")
64-
.arg("--lib")
65-
.arg("--")
66-
.arg("-Zunstable-options")
67-
.arg("--report-time");
73+
cmd.env("UPDATE", "1").arg("--").arg("-Zunstable-options").arg("--report-time");
6874

6975
if self.ignored {
7076
cmd.arg("--ignored");
@@ -85,22 +91,27 @@ impl<'a> TestBaseArgs<'a> {
8591
// appropriate println!("cargo:rerun-if-changed=<path>");
8692

8793
let mut cmd = self.to_command();
94+
println!("{cmd:?}");
8895

8996
let status = cmd.status()?;
90-
ensure!(status.success(), "test base failed: {status}");
97+
ensure!(status.success(), "analyzer test base failed: {status}");
9198
Ok(())
9299
}
93100
}
94101

95-
/// Implements xtask auto-unignore
102+
/// Implements xtask auto-unignore: un-ignore tests that pass.
96103
pub fn auto_unignore() -> anyhow::Result<()> {
97104
// Remove any ignored tests cached outputs so they are re-run.
98105
// (shouldn't all tests be re-run?)
99106
unignore_cleanup()?;
100107

101108
// Ignore the result of testing, we just want the updated .tsc-errors.json as a
102109
// side-effect.
103-
let _ = TestBaseArgs::new().with_ignored().run();
110+
let _ = TestBaseArgs::new()
111+
.with_log_max_level(LogFilterLevel::Off)
112+
.with_lib(false)
113+
.with_ignored()
114+
.run();
104115

105116
// Remove failed tests caches again, only successful tests should be committed.
106117
unignore_cleanup()?;
@@ -111,7 +122,7 @@ pub fn auto_unignore() -> anyhow::Result<()> {
111122
fn unignore_cleanup() -> anyhow::Result<()> {
112123
println!("Deleting cache for ignored tests");
113124
// find ./tests/tsc -name '\.*.tsc-errors.json' -type f -delete
114-
return walk(Path::new("crates/stc_ts_file_analyzer/tests/tsc"));
125+
return walk(&run_cargo::root_dir().join("crates/stc_ts_file_analyzer/tests/tsc"));
115126

116127
fn walk(dir: &Path) -> anyhow::Result<()> {
117128
for entry in std::fs::read_dir(dir)? {

xtask/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct Cli {
1818
enum Command {
1919
/// Run tests for stc_ts_file_analyzer
2020
TestAnalyzer(TestAnalyzerArgs),
21-
/// Automatically find a test to work on.
21+
/// Automatically unignore stc_ts_file_analyzer tests that pass.
2222
AutoUnignore,
2323
/// Run tests for stc_ts_type_checker
2424
TestChecker(TestCheckerArgs),

xtask/src/run_cargo.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Provide general helpers to run a nested cargo command.
22
3+
use std::path::PathBuf;
4+
35
/// tracing static filter level, to improve performance at the cost of needing
46
/// to rebuild.
57
#[derive(Debug)]
@@ -47,6 +49,7 @@ pub struct CargoTestArgs<'a> {
4749
log_max_level: Option<LogFilterLevel>,
4850
log: Option<&'a str>,
4951
package: &'a str,
52+
lib: bool,
5053
test: Option<&'a str>,
5154
name: Option<&'a str>,
5255
}
@@ -61,6 +64,7 @@ impl<'a> CargoTestArgs<'a> {
6164
log_max_level: None,
6265
log: None,
6366
package,
67+
lib: false,
6468
test: None,
6569
name: None,
6670
}
@@ -82,6 +86,13 @@ impl<'a> CargoTestArgs<'a> {
8286
self
8387
}
8488

89+
/// Set cargo test --lib to run the unit tests in the library
90+
#[must_use]
91+
pub fn with_lib(mut self, lib: bool) -> Self {
92+
self.lib = lib;
93+
self
94+
}
95+
8596
/// Set cargo test --test file to run, e.g. base or prof
8697
#[must_use]
8798
pub fn with_test(mut self, test: &'a str) -> Self {
@@ -99,6 +110,9 @@ impl<'a> CargoTestArgs<'a> {
99110
/// Return a Command that can be further configured and run.
100111
pub fn to_command(&self) -> std::process::Command {
101112
let mut cmd = std::process::Command::new("cargo");
113+
// normalize working dir
114+
cmd.current_dir(root_dir());
115+
102116
if let Some(log) = self.log {
103117
cmd.env("RUST_LOG", log);
104118
}
@@ -114,6 +128,9 @@ impl<'a> CargoTestArgs<'a> {
114128
if let Some(level) = &self.log_max_level {
115129
cmd.arg("--features").arg(level.as_max_level_feature());
116130
}
131+
if self.lib {
132+
cmd.arg("--lib");
133+
}
117134
if let Some(test) = self.test {
118135
cmd.arg("--test").arg(test);
119136
}
@@ -123,3 +140,11 @@ impl<'a> CargoTestArgs<'a> {
123140
cmd
124141
}
125142
}
143+
144+
pub fn root_dir() -> PathBuf {
145+
let mut manifest_dir =
146+
PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR not set: are you using 'cargo xtask ...'?"));
147+
// xtask manifest should be at: <root>/xtask/Cargo.toml
148+
manifest_dir.pop();
149+
manifest_dir
150+
}

0 commit comments

Comments
 (0)