Skip to content

Commit 2edee31

Browse files
authored
Merge pull request #306 from oli-obk/push-zpmkrqzlzpot
Show the unnormalized output on output mismatch failure
2 parents a9a8ea0 + 4989e9b commit 2edee31

File tree

16 files changed

+115
-74
lines changed

16 files changed

+115
-74
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Removed
1717

18+
## [0.29.0] - 2025-02-25
19+
20+
### Added
21+
22+
### Fixed
23+
24+
### Changed
25+
26+
* output conflict handling now only takes the unnormalized output and is expected to normalize itself if desired.
27+
28+
### Removed
29+
1830
## [0.28.0] - 2025-01-27
1931

2032
### Added

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ui_test"
3-
version = "0.28.0"
3+
version = "0.29.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "A test framework for testing rustc diagnostics output"

src/config.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
use crate::{
88
diagnostics::{self, Diagnostics},
99
parser::CommandParserFunc,
10-
per_test_config::{Comments, Condition},
10+
per_test_config::{Comments, Condition, TestConfig},
1111
CommandBuilder, Error, Errored, Errors,
1212
};
1313
use color_eyre::eyre::Result;
@@ -85,7 +85,7 @@ impl AbortCheck {
8585
}
8686

8787
/// Function that performs the actual output conflict handling.
88-
pub type OutputConflictHandling = fn(&Path, Vec<u8>, &mut Errors, &Config);
88+
pub type OutputConflictHandling = fn(&Path, &[u8], &mut Errors, &TestConfig);
8989

9090
impl Config {
9191
/// Create a blank configuration that doesn't do anything interesting
@@ -484,36 +484,39 @@ impl Config {
484484
/// test.
485485
pub fn error_on_output_conflict(
486486
path: &Path,
487-
actual: Vec<u8>,
487+
output: &[u8],
488488
errors: &mut Errors,
489-
config: &Config,
489+
config: &TestConfig,
490490
) {
491+
let normalized = config.normalize(output, &path.extension().unwrap().to_string_lossy());
491492
let expected = std::fs::read(path).unwrap_or_default();
492-
if actual != expected {
493+
if normalized != expected {
493494
errors.push(Error::OutputDiffers {
494495
path: path.to_path_buf(),
495-
actual,
496+
actual: normalized,
497+
output: output.to_vec(),
496498
expected,
497-
bless_command: config.bless_command.clone(),
499+
bless_command: config.config.bless_command.clone(),
498500
});
499501
}
500502
}
501503

502504
/// Ignore mismatches in the stderr/stdout files.
503505
pub fn ignore_output_conflict(
504506
_path: &Path,
505-
_actual: Vec<u8>,
507+
_output: &[u8],
506508
_errors: &mut Errors,
507-
_config: &Config,
509+
_config: &TestConfig,
508510
) {
509511
}
510512

511513
/// Instead of erroring if the stderr/stdout differs from the expected
512514
/// automatically replace it with the found output (after applying filters).
513-
pub fn bless_output_files(path: &Path, actual: Vec<u8>, _errors: &mut Errors, _config: &Config) {
514-
if actual.is_empty() {
515+
pub fn bless_output_files(path: &Path, output: &[u8], _errors: &mut Errors, config: &TestConfig) {
516+
if output.is_empty() {
515517
let _ = std::fs::remove_file(path);
516518
} else {
517-
std::fs::write(path, &actual).unwrap();
519+
let actual = config.normalize(output, &path.extension().unwrap().to_string_lossy());
520+
std::fs::write(path, actual).unwrap();
518521
}
519522
}

src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ pub enum Error {
4444
OutputDiffers {
4545
/// The file containing the expected output that differs from the actual output.
4646
path: PathBuf,
47-
/// The output from the command.
47+
/// The normalized output from the command.
4848
actual: Vec<u8>,
49+
/// The unnormalized output from the command.
50+
output: Vec<u8>,
4951
/// The contents of the file.
5052
expected: Vec<u8>,
5153
/// A command, that when run, causes the output to get blessed instead of erroring.

src/per_test_config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@ impl TestConfig {
186186
}
187187

188188
pub(crate) fn check_output(&self, output: &[u8], errors: &mut Errors, kind: &str) -> PathBuf {
189-
let output = self.normalize(output, kind);
190189
let path = self.output_path(kind);
191-
(self.config.output_conflict_handling)(&path, output, errors, &self.config);
190+
(self.config.output_conflict_handling)(&path, output, errors, self);
192191
path
193192
}
194193

src/status_emitter/gha.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fn gha_error(error: &Error, test_path: &str, revision: &str) {
5858
Error::OutputDiffers {
5959
path: output_path,
6060
actual,
61+
output: _,
6162
expected,
6263
bless_command,
6364
} => {

src/status_emitter/text.rs

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -706,27 +706,54 @@ fn print_error(error: &Error, path: &Path) {
706706
Error::OutputDiffers {
707707
path: output_path,
708708
actual,
709+
output,
709710
expected,
710711
bless_command,
711712
} => {
712-
print_error_header("actual output differed from expected");
713-
if let Some(bless_command) = bless_command {
713+
let bless = || {
714+
if let Some(bless_command) = bless_command {
715+
println!(
716+
"Execute `{}` to update `{}` to the actual output",
717+
bless_command,
718+
display(output_path)
719+
);
720+
}
721+
};
722+
if expected.is_empty() {
723+
print_error_header("no output was expected");
724+
bless();
714725
println!(
715-
"Execute `{}` to update `{}` to the actual output",
716-
bless_command,
717-
display(output_path)
726+
"{}",
727+
format!(
728+
"+++ <{} output>",
729+
output_path.extension().unwrap().to_str().unwrap()
730+
)
731+
.green()
718732
);
733+
println!("{}", String::from_utf8_lossy(output));
734+
} else if output.is_empty() {
735+
print_error_header("no output was emitted");
736+
if let Some(bless_command) = bless_command {
737+
println!(
738+
"Execute `{}` to remove `{}`",
739+
bless_command,
740+
display(output_path)
741+
);
742+
}
743+
} else {
744+
print_error_header("actual output differed from expected");
745+
bless();
746+
println!("{}", format!("--- {}", display(output_path)).red());
747+
println!(
748+
"{}",
749+
format!(
750+
"+++ <{} output>",
751+
output_path.extension().unwrap().to_str().unwrap()
752+
)
753+
.green()
754+
);
755+
crate::diff::print_diff(expected, actual);
719756
}
720-
println!("{}", format!("--- {}", display(output_path)).red());
721-
println!(
722-
"{}",
723-
format!(
724-
"+++ <{} output>",
725-
output_path.extension().unwrap().to_str().unwrap()
726-
)
727-
.green()
728-
);
729-
crate::diff::print_diff(expected, actual);
730757
}
731758
Error::ErrorsWithoutPattern { path, msgs } => {
732759
if let Some((path, _)) = path.as_ref() {

tests/integrations/basic-bin/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic-fail-mode/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic-fail/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic-fail/Cargo.stdout

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,19 @@ error: test got exit status: 1, but expected 0
104104
| ^^^ compilation failed, but was expected to succeed
105105
|
106106

107-
error: actual output differed from expected
107+
error: no output was expected
108108
Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/executable_compile_err.stderr` to the actual output
109-
--- tests/actual_tests/executable_compile_err.stderr
110109
+++ <stderr output>
111-
+error: this file contains an unclosed delimiter
112-
+ --> tests/actual_tests/executable_compile_err.rs:4:2
113-
+ |
114-
+3 | fn main() {
115-
+ | - unclosed delimiter
116-
+4 |
117-
+ | ^
118-
+
119-
+error: aborting due to 1 previous error
120-
+
110+
error: this file contains an unclosed delimiter
111+
--> tests/actual_tests/executable_compile_err.rs:4:2
112+
|
113+
3 | fn main() {
114+
| - unclosed delimiter
115+
4 |
116+
| ^
117+
118+
error: aborting due to 1 previous error
119+
121120

122121

123122
full stderr:
@@ -1206,19 +1205,18 @@ error: test got exit status: 1, but expected 0
12061205
| ^^^ compilation failed, but was expected to succeed
12071206
|
12081207

1209-
error: actual output differed from expected
1208+
error: no output was expected
12101209
Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/executable.stderr` to the actual output
1211-
--- tests/actual_tests/executable.stderr
12121210
+++ <stderr output>
1213-
+error[E0432]: unresolved import `basic_fail`
1214-
+ --> tests/actual_tests/executable.rs:1:5
1215-
+ |
1216-
+1 | use basic_fail::add;
1217-
+ | ^^^^^^^^^^ use of undeclared crate or module `basic_fail`
1218-
+
1219-
+error: aborting due to 1 previous error
1220-
+
1221-
+For more information about this error, try `rustc --explain E0432`.
1211+
error[E0432]: unresolved import `basic_fail`
1212+
--> tests/actual_tests/executable.rs:1:5
1213+
|
1214+
1 | use basic_fail::add;
1215+
| ^^^^^^^^^^ use of undeclared crate or module `basic_fail`
1216+
1217+
error: aborting due to 1 previous error
1218+
1219+
For more information about this error, try `rustc --explain E0432`.
12221220

12231221

12241222

@@ -1232,20 +1230,19 @@ error: test got exit status: 1, but expected 0
12321230
| ^^^ compilation failed, but was expected to succeed
12331231
|
12341232

1235-
error: actual output differed from expected
1233+
error: no output was expected
12361234
Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/executable_compile_err.stderr` to the actual output
1237-
--- tests/actual_tests/executable_compile_err.stderr
12381235
+++ <stderr output>
1239-
+error: this file contains an unclosed delimiter
1240-
+ --> tests/actual_tests/executable_compile_err.rs:4:2
1241-
+ |
1242-
+3 | fn main() {
1243-
+ | - unclosed delimiter
1244-
+4 |
1245-
+ | ^
1246-
+
1247-
+error: aborting due to 1 previous error
1248-
+
1236+
error: this file contains an unclosed delimiter
1237+
--> tests/actual_tests/executable_compile_err.rs:4:2
1238+
|
1239+
3 | fn main() {
1240+
| - unclosed delimiter
1241+
4 |
1242+
| ^
1243+
1244+
error: aborting due to 1 previous error
1245+
12491246

12501247

12511248

tests/integrations/basic/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/cargo-run/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/dep-fail/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/ui_test_dep_bug/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)