File tree 5 files changed +28
-11
lines changed
examples/rust_lang_tester/lang_tests
5 files changed +28
-11
lines changed Original file line number Diff line number Diff line change 1
- // ignore: this test is intentionally ignored
1
+ // ignore-if: true
2
2
// Compiler:
3
3
// status: success
4
4
Original file line number Diff line number Diff line change
1
+ // ignore-if: false
2
+ // Run-time:
3
+ // stdout: check
4
+
5
+ fn main ( ) {
6
+ println ! ( "check" ) ;
7
+ }
Original file line number Diff line number Diff line change 159
159
//! its `stderr` output should warn about an unused variable on line 12; and the resulting binary
160
160
//! should succeed produce `Hello world` on `stdout`.
161
161
//!
162
- //! A file's tests can be ignored entirely if a test command `ignore` is defined :
162
+ //! A file's tests can be ignored entirely with :
163
163
//!
164
- //! * `ignore: [<string>]` specifies that this file should be ignored for the reason set out in
165
- //! `<string>` (if any). Note that `<string>` is purely for user information and has no effect
166
- //! on the running of tests.
164
+ //! * `ignore-if: <cmd>` defines a shell command that will be run to determine whether to ignore
165
+ //! this test or not. If `<cmd>` returns 0 the test will be ignored, otherwise it will be run.
167
166
//!
168
167
//! `lang_tester`'s output is deliberately similar to Rust's normal testing output. Running the
169
168
//! example `rust_lang_tester` in this crate produces the following output:
Original file line number Diff line number Diff line change @@ -10,16 +10,16 @@ pub(crate) fn parse_tests(test_str: &str) -> Tests {
10
10
let lines = test_str. lines ( ) . collect :: < Vec < _ > > ( ) ;
11
11
let mut tests = HashMap :: new ( ) ;
12
12
let mut line_off = 0 ;
13
- let mut ignore = false ;
13
+ let mut ignore_if = None ;
14
14
while line_off < lines. len ( ) {
15
15
let indent = indent_level ( & lines, line_off) ;
16
16
if indent == lines[ line_off] . len ( ) {
17
17
line_off += 1 ;
18
18
continue ;
19
19
}
20
20
let ( test_name, val) = key_val ( & lines, line_off, indent) ;
21
- if test_name == "ignore" {
22
- ignore = true ;
21
+ if test_name == "ignore-if " {
22
+ ignore_if = Some ( val . into ( ) ) ;
23
23
line_off += 1 ;
24
24
continue ;
25
25
}
@@ -120,7 +120,7 @@ pub(crate) fn parse_tests(test_str: &str) -> Tests {
120
120
}
121
121
}
122
122
}
123
- Tests { ignore , tests }
123
+ Tests { ignore_if , tests }
124
124
}
125
125
126
126
fn indent_level ( lines : & [ & str ] , line_off : usize ) -> usize {
Original file line number Diff line number Diff line change @@ -550,7 +550,7 @@ impl<'a> TestCmd<'a> {
550
550
551
551
/// A collection of tests.
552
552
pub ( crate ) struct Tests < ' a > {
553
- pub ignore : bool ,
553
+ pub ignore_if : Option < String > ,
554
554
pub tests : HashMap < String , TestCmd < ' a > > ,
555
555
}
556
556
@@ -644,7 +644,18 @@ fn test_file(
644
644
}
645
645
646
646
let tests = parse_tests ( & test_str) ;
647
- if ( inner. ignored && !tests. ignore ) || ( !inner. ignored && tests. ignore ) {
647
+ let ignore = if let Some ( ignore_if) = tests. ignore_if {
648
+ Command :: new ( env:: var ( "SHELL" ) . unwrap_or_else ( |_| "/bin/sh" . to_owned ( ) ) )
649
+ . args ( [ "-c" , & ignore_if] )
650
+ . status ( )
651
+ . unwrap_or_else ( |_| {
652
+ fatal ( & format ! ( "Couldn't run ignore-if '{ignore_if}'" ) )
653
+ } )
654
+ . success ( )
655
+ } else {
656
+ false
657
+ } ;
658
+ if ( inner. ignored && !ignore) || ( !inner. ignored && ignore) {
648
659
write_ignored ( test_fname. as_str ( ) , "" , inner) ;
649
660
num_ignored. fetch_add ( 1 , Ordering :: Relaxed ) ;
650
661
return ;
You can’t perform that action at this time.
0 commit comments