@@ -4,7 +4,10 @@ use std::path::Path;
44
55use 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
1013pub 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.
96103pub 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<()> {
111122fn 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) ? {
0 commit comments