Skip to content

Commit 2c75eca

Browse files
committed
Disallow non-same compare-mode-nll
1 parent 07e7b43 commit 2c75eca

9 files changed

+48
-23
lines changed

src/test/ui/json-multiple.nll.stderr

-1
This file was deleted.

src/test/ui/json-multiple.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// build-pass
22
// ignore-pass (different metadata emitted in different modes)
33
// compile-flags: --json=diagnostic-short --json artifacts --error-format=json
4+
// ignore-compare-mode-nll
45

56
#![crate_type = "lib"]

src/test/ui/json-options.nll.stderr

-1
This file was deleted.

src/test/ui/json-options.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// build-pass
22
// ignore-pass (different metadata emitted in different modes)
33
// compile-flags: --json=diagnostic-short,artifacts --error-format=json
4+
// ignore-compare-mode-nll
45

56
#![crate_type = "lib"]

src/test/ui/rmeta/emit-artifact-notifications.nll.stderr

-1
This file was deleted.

src/test/ui/rmeta/emit-artifact-notifications.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// build-pass
33
// ignore-pass
44
// ^-- needed because `--pass check` does not emit the output needed.
5+
// ignore-compare-mode-nll
56

67
// A very basic test for the emission of artifact notifications in JSON output.
78

src/test/ui/save-analysis/emit-notifications.nll.stderr

-2
This file was deleted.

src/test/ui/save-analysis/emit-notifications.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
// compile-flags: --crate-type rlib --error-format=json
44
// ignore-pass
55
// ^-- needed because otherwise, the .stderr file changes with --pass check
6+
// ignore-compare-mode-nll
67

78
pub fn foo() {}

src/tools/compiletest/src/runtest.rs

+44-18
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,7 @@ impl<'test> TestCx<'test> {
31123112
let expected_fixed = self.load_expected_output(UI_FIXED);
31133113

31143114
let modes_to_prune = vec![CompareMode::Nll];
3115-
self.prune_duplicate_outputs(&modes_to_prune);
3115+
self.check_and_prune_duplicate_outputs(&proc_res, &[], &modes_to_prune);
31163116

31173117
let mut errors = self.load_compare_outputs(&proc_res, TestOutput::Compile, explicit);
31183118
let rustfix_input = json::rustfix_diagnostics_only(&proc_res.stderr);
@@ -3730,28 +3730,54 @@ impl<'test> TestCx<'test> {
37303730
if self.config.bless { 0 } else { 1 }
37313731
}
37323732

3733-
fn prune_duplicate_output(&self, mode: CompareMode, kind: &str, canon_content: &str) {
3734-
let examined_path = expected_output_path(&self.testpaths, self.revision, &Some(mode), kind);
3735-
3736-
let examined_content =
3737-
self.load_expected_output_from_path(&examined_path).unwrap_or_else(|_| String::new());
3733+
fn check_and_prune_duplicate_outputs(
3734+
&self,
3735+
proc_res: &ProcRes,
3736+
modes: &[CompareMode],
3737+
require_same_modes: &[CompareMode],
3738+
) {
3739+
for kind in UI_EXTENSIONS {
3740+
let canon_comparison_path =
3741+
expected_output_path(&self.testpaths, self.revision, &None, kind);
37383742

3739-
if canon_content == examined_content {
3740-
self.delete_file(&examined_path);
3741-
}
3742-
}
3743+
let canon = match self.load_expected_output_from_path(&canon_comparison_path) {
3744+
Ok(canon) => canon,
3745+
_ => continue,
3746+
};
3747+
let bless = self.config.bless;
3748+
let check_and_prune_duplicate_outputs = |mode: &CompareMode, require_same: bool| {
3749+
let examined_path =
3750+
expected_output_path(&self.testpaths, self.revision, &Some(mode.clone()), kind);
3751+
3752+
// If there is no output, there is nothing to do
3753+
let examined_content = match self.load_expected_output_from_path(&examined_path) {
3754+
Ok(content) => content,
3755+
_ => return,
3756+
};
37433757

3744-
fn prune_duplicate_outputs(&self, modes: &[CompareMode]) {
3745-
if self.config.bless {
3746-
for kind in UI_EXTENSIONS {
3747-
let canon_comparison_path =
3748-
expected_output_path(&self.testpaths, self.revision, &None, kind);
3758+
let is_duplicate = canon == examined_content;
37493759

3750-
if let Ok(canon) = self.load_expected_output_from_path(&canon_comparison_path) {
3751-
for mode in modes {
3752-
self.prune_duplicate_output(mode.clone(), kind, &canon);
3760+
match (bless, require_same, is_duplicate) {
3761+
// If we're blessing and the output is the same, then delete the file.
3762+
(true, _, true) => {
3763+
self.delete_file(&examined_path);
37533764
}
3765+
// If we want them to be the same, but they are different, then error.
3766+
// We do this wether we bless or not
3767+
(_, true, false) => {
3768+
self.fatal_proc_rec(
3769+
&format!("`{}` should not have different output from base test!", kind),
3770+
proc_res,
3771+
);
3772+
}
3773+
_ => {}
37543774
}
3775+
};
3776+
for mode in modes {
3777+
check_and_prune_duplicate_outputs(mode, false);
3778+
}
3779+
for mode in require_same_modes {
3780+
check_and_prune_duplicate_outputs(mode, true);
37553781
}
37563782
}
37573783
}

0 commit comments

Comments
 (0)