Skip to content

Commit

Permalink
Show the unnormalized output on output mismatch failure
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 25, 2025
1 parent a9a8ea0 commit bfa3597
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
18 changes: 13 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl AbortCheck {
}

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

impl Config {
/// Create a blank configuration that doesn't do anything interesting
Expand Down Expand Up @@ -484,15 +484,16 @@ impl Config {
/// test.
pub fn error_on_output_conflict(
path: &Path,
actual: Vec<u8>,
normalized: Vec<u8>,
output: &[u8],
errors: &mut Errors,
config: &Config,
) {
let expected = std::fs::read(path).unwrap_or_default();
if actual != expected {
if normalized != expected {
errors.push(Error::OutputDiffers {
path: path.to_path_buf(),
actual,
actual: output.to_vec(),
expected,
bless_command: config.bless_command.clone(),
});
Expand All @@ -503,14 +504,21 @@ pub fn error_on_output_conflict(
pub fn ignore_output_conflict(
_path: &Path,
_actual: Vec<u8>,
_output: &[u8],
_errors: &mut Errors,
_config: &Config,
) {
}

/// Instead of erroring if the stderr/stdout differs from the expected
/// automatically replace it with the found output (after applying filters).
pub fn bless_output_files(path: &Path, actual: Vec<u8>, _errors: &mut Errors, _config: &Config) {
pub fn bless_output_files(
path: &Path,
actual: Vec<u8>,
_output: &[u8],
_errors: &mut Errors,
_config: &Config,
) {
if actual.is_empty() {
let _ = std::fs::remove_file(path);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/per_test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ impl TestConfig {
}

pub(crate) fn check_output(&self, output: &[u8], errors: &mut Errors, kind: &str) -> PathBuf {
let output = self.normalize(output, kind);
let normalized = self.normalize(output, kind);
let path = self.output_path(kind);
(self.config.output_conflict_handling)(&path, output, errors, &self.config);
(self.config.output_conflict_handling)(&path, normalized, output, errors, &self.config);
path
}

Expand Down
19 changes: 16 additions & 3 deletions tests/integrations/basic-fail/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/ba
+++ <stderr output>
error[E0308]: mismatched types
--> tests/actual_tests/bad_pattern.rs:4:9
... 10 lines skipped ...
... 5 lines skipped ...
|
note: function defined here
- --> $DIR/tests/integrations/basic-fail/src/lib.rs:LL:CC
+ --> $DIR/tests/integrations/basic-fail/src/lib.rs:LL:CC

Check failure on line 37 in tests/integrations/basic-fail/Cargo.stdout

View workflow job for this annotation

GitHub Actions / tests (macos-latest, x86_64-apple-darwin)

actual output differs from expected

this line was expected to be `- --> $DIR/tests/integrations/basic-fail/src/lib.rs:1:8`
|
1 | pub fn add(left: usize, right: usize) -> usize {
| ^^^

-error: aborting due to previous error
Expand Down Expand Up @@ -227,7 +233,13 @@ Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/fo
+++ <stderr output>
error[E0308]: mismatched types
--> tests/actual_tests/foomp2.rs:4:9
... 10 lines skipped ...
... 5 lines skipped ...
|
note: function defined here
- --> $DIR/tests/integrations/basic-fail/src/lib.rs:LL:CC
+ --> $DIR/tests/integrations/basic-fail/src/lib.rs:LL:CC
|
1 | pub fn add(left: usize, right: usize) -> usize {
| ^^^

-error: aborting due to previous error
Expand Down Expand Up @@ -1429,7 +1441,8 @@ Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/ru
- | --- ^^^^ expected `usize`, found `&str`
+ | ^^^^^^^^^^ use of undeclared crate or module `basic_fail`

thread 'rustc' panicked
-thread 'rustc' panicked
+thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:


error: `mismatched types` not found in diagnostics on line 8
Expand Down

0 comments on commit bfa3597

Please sign in to comment.