Skip to content

Commit 7df5cd0

Browse files
committed
Replace ignore with ignore-if.
`ignore` is a blunt tool. `ignore-if` allows users to be selective if/when they ignore tests. `ignore-if: true` is equivalent to the old `ignore`.
1 parent 5b62645 commit 7df5cd0

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

examples/rust_lang_tester/lang_tests/ignore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ignore: this test is intentionally ignored
1+
// ignore-if: true
22
// Compiler:
33
// status: success
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ignore-if: false
2+
// Run-time:
3+
// stdout: check
4+
5+
fn main() {
6+
println!("check");
7+
}

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,10 @@
159159
//! its `stderr` output should warn about an unused variable on line 12; and the resulting binary
160160
//! should succeed produce `Hello world` on `stdout`.
161161
//!
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:
163163
//!
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.
167166
//!
168167
//! `lang_tester`'s output is deliberately similar to Rust's normal testing output. Running the
169168
//! example `rust_lang_tester` in this crate produces the following output:

src/parser.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ pub(crate) fn parse_tests(test_str: &str) -> Tests {
1010
let lines = test_str.lines().collect::<Vec<_>>();
1111
let mut tests = HashMap::new();
1212
let mut line_off = 0;
13-
let mut ignore = false;
13+
let mut ignore_if = None;
1414
while line_off < lines.len() {
1515
let indent = indent_level(&lines, line_off);
1616
if indent == lines[line_off].len() {
1717
line_off += 1;
1818
continue;
1919
}
2020
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());
2323
line_off += 1;
2424
continue;
2525
}
@@ -120,7 +120,7 @@ pub(crate) fn parse_tests(test_str: &str) -> Tests {
120120
}
121121
}
122122
}
123-
Tests { ignore, tests }
123+
Tests { ignore_if, tests }
124124
}
125125

126126
fn indent_level(lines: &[&str], line_off: usize) -> usize {

src/tester.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a> TestCmd<'a> {
550550

551551
/// A collection of tests.
552552
pub(crate) struct Tests<'a> {
553-
pub ignore: bool,
553+
pub ignore_if: Option<String>,
554554
pub tests: HashMap<String, TestCmd<'a>>,
555555
}
556556

@@ -644,7 +644,18 @@ fn test_file(
644644
}
645645

646646
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) {
648659
write_ignored(test_fname.as_str(), "", inner);
649660
num_ignored.fetch_add(1, Ordering::Relaxed);
650661
return;

0 commit comments

Comments
 (0)