Skip to content

Commit bb20367

Browse files
committed
Rename ShouldPanic to ShouldFail
The old name was a holdover from libtest, but in compiletest we only use it for `//@ should-fail` tests, which are tests of compiletest itself.
1 parent 665dbb3 commit bb20367

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::directives::line::{DirectiveLine, line_directive};
1818
use crate::directives::needs::CachedNeedsConditions;
1919
use crate::edition::{Edition, parse_edition};
2020
use crate::errors::ErrorKind;
21-
use crate::executor::{CollectedTestDesc, ShouldPanic};
21+
use crate::executor::{CollectedTestDesc, ShouldFail};
2222
use crate::util::static_regex;
2323
use crate::{fatal, help};
2424

@@ -1366,18 +1366,18 @@ pub(crate) fn make_test_description(
13661366
// The `should-fail` annotation doesn't apply to pretty tests,
13671367
// since we run the pretty printer across all tests by default.
13681368
// If desired, we could add a `should-fail-pretty` annotation.
1369-
let should_panic = match config.mode {
1370-
TestMode::Pretty => ShouldPanic::No,
1371-
_ if should_fail => ShouldPanic::Yes,
1372-
_ => ShouldPanic::No,
1369+
let should_fail = if should_fail && config.mode != TestMode::Pretty {
1370+
ShouldFail::Yes
1371+
} else {
1372+
ShouldFail::No
13731373
};
13741374

13751375
CollectedTestDesc {
13761376
name,
13771377
filterable_path: filterable_path.to_owned(),
13781378
ignore,
13791379
ignore_message,
1380-
should_panic,
1380+
should_fail,
13811381
}
13821382
}
13831383

src/tools/compiletest/src/directives/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::directives::{
77
extract_llvm_version, extract_version_range, iter_directives, line_directive, parse_edition,
88
parse_normalize_rule,
99
};
10-
use crate::executor::{CollectedTestDesc, ShouldPanic};
10+
use crate::executor::{CollectedTestDesc, ShouldFail};
1111

1212
fn make_test_description(
1313
config: &Config,
@@ -247,9 +247,9 @@ fn should_fail() {
247247
let p = Utf8Path::new("a.rs");
248248

249249
let d = make_test_description(&config, tn.clone(), p, p, "", None);
250-
assert_eq!(d.should_panic, ShouldPanic::No);
250+
assert_eq!(d.should_fail, ShouldFail::No);
251251
let d = make_test_description(&config, tn, p, p, "//@ should-fail", None);
252-
assert_eq!(d.should_panic, ShouldPanic::Yes);
252+
assert_eq!(d.should_fail, ShouldFail::Yes);
253253
}
254254

255255
#[test]

src/tools/compiletest/src/executor.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn spawn_test_thread(
112112
config: Arc::clone(&test.config),
113113
testpaths: test.testpaths.clone(),
114114
revision: test.revision.clone(),
115-
should_panic: test.desc.should_panic,
115+
should_fail: test.desc.should_fail,
116116
completion_sender,
117117
};
118118
let thread_builder = thread::Builder::new().name(test.desc.name.clone());
@@ -127,7 +127,7 @@ struct TestThreadArgs {
127127
config: Arc<Config>,
128128
testpaths: TestPaths,
129129
revision: Option<String>,
130-
should_panic: ShouldPanic,
130+
should_fail: ShouldFail,
131131

132132
completion_sender: mpsc::Sender<TestCompletion>,
133133
}
@@ -170,11 +170,11 @@ fn test_thread_main(args: TestThreadArgs) {
170170
}
171171

172172
// Interpret the presence/absence of a panic as test failure/success.
173-
let outcome = match (args.should_panic, panic_payload) {
174-
(ShouldPanic::No, None) | (ShouldPanic::Yes, Some(_)) => TestOutcome::Succeeded,
175-
(ShouldPanic::No, Some(_)) => TestOutcome::Failed { message: None },
176-
(ShouldPanic::Yes, None) => {
177-
TestOutcome::Failed { message: Some("test did not panic as expected") }
173+
let outcome = match (args.should_fail, panic_payload) {
174+
(ShouldFail::No, None) | (ShouldFail::Yes, Some(_)) => TestOutcome::Succeeded,
175+
(ShouldFail::No, Some(_)) => TestOutcome::Failed { message: None },
176+
(ShouldFail::Yes, None) => {
177+
TestOutcome::Failed { message: Some("`//@ should-fail` test did not fail as expected") }
178178
}
179179
};
180180

@@ -338,7 +338,7 @@ pub(crate) struct CollectedTestDesc {
338338
pub(crate) filterable_path: Utf8PathBuf,
339339
pub(crate) ignore: bool,
340340
pub(crate) ignore_message: Option<Cow<'static, str>>,
341-
pub(crate) should_panic: ShouldPanic,
341+
pub(crate) should_fail: ShouldFail,
342342
}
343343

344344
/// Whether console output should be colored or not.
@@ -350,9 +350,10 @@ pub enum ColorConfig {
350350
NeverColor,
351351
}
352352

353-
/// Whether test is expected to panic or not.
353+
/// Tests with `//@ should-fail` are tests of compiletest itself, and should
354+
/// be reported as successful if and only if they would have _failed_.
354355
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
355-
pub(crate) enum ShouldPanic {
356+
pub(crate) enum ShouldFail {
356357
No,
357358
Yes,
358359
}

0 commit comments

Comments
 (0)