Skip to content

Commit fb89be9

Browse files
committed
Use TestCOnfig in check_test_output
1 parent 850f67e commit fb89be9

File tree

1 file changed

+37
-49
lines changed

1 file changed

+37
-49
lines changed

src/lib.rs

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,11 @@ fn run_test(build_manager: &BuildManager<'_>, mut config: TestConfig<'_>) -> Tes
610610
)?;
611611

612612
if let Mode::Run { .. } = *mode {
613-
return run_test_binary(mode, cmd, &config);
613+
run_test_binary(mode, cmd, config)
614+
} else {
615+
run_rustfix(output, config, *mode, extra_args)?;
616+
Ok(TestOk::Ok)
614617
}
615-
616-
run_rustfix(output, &config, *mode, extra_args)?;
617-
Ok(TestOk::Ok)
618618
}
619619

620620
fn run_command(mut cmd: Command) -> Result<(Command, Output), Errored> {
@@ -689,8 +689,14 @@ fn build_aux_files(
689689
Ok(extra_args)
690690
}
691691

692-
fn run_test_binary(mode: Spanned<Mode>, mut cmd: Command, config: &TestConfig) -> TestResult {
692+
fn run_test_binary(mode: Spanned<Mode>, mut cmd: Command, config: TestConfig) -> TestResult {
693693
let revision = config.extension("run");
694+
let config = TestConfig {
695+
config: config.config,
696+
revision: &revision,
697+
comments: config.comments,
698+
path: config.path,
699+
};
694700
cmd.arg("--print").arg("file-names");
695701
let output = cmd.output().unwrap();
696702
assert!(output.status.success());
@@ -711,15 +717,7 @@ fn run_test_binary(mode: Spanned<Mode>, mut cmd: Command, config: &TestConfig) -
711717

712718
let mut errors = vec![];
713719

714-
check_test_output(
715-
config.path,
716-
&mut errors,
717-
&revision,
718-
&config.config,
719-
config.comments,
720-
&output.stdout,
721-
&output.stderr,
722-
);
720+
check_test_output(&mut errors, &config, &output.stdout, &output.stderr);
723721

724722
errors.extend(mode.ok(output.status).err());
725723
if errors.is_empty() {
@@ -736,7 +734,7 @@ fn run_test_binary(mode: Spanned<Mode>, mut cmd: Command, config: &TestConfig) -
736734

737735
fn run_rustfix(
738736
output: Output,
739-
config: &TestConfig,
737+
config: TestConfig,
740738
mode: Mode,
741739
extra_args: Vec<OsString>,
742740
) -> Result<(), Errored> {
@@ -823,19 +821,22 @@ fn run_rustfix(
823821
))
824822
.collect(),
825823
};
824+
let config = TestConfig {
825+
config: config.config,
826+
revision: config.revision,
827+
comments: &rustfix_comments,
828+
path: config.path,
829+
};
826830

827831
let run = fixed_code.is_some();
828832
let mut errors = vec![];
829833
let rustfix_path = check_output(
830834
// Always check for `.fixed` files, even if there were reasons not to run rustfix.
831835
// We don't want to leave around stray `.fixed` files
832836
fixed_code.unwrap_or_default().as_bytes(),
833-
config.path,
834837
&mut errors,
835838
"fixed",
836-
&config.config,
837-
&rustfix_comments,
838-
config.revision,
839+
&config,
839840
);
840841
if !errors.is_empty() {
841842
return Err(Errored {
@@ -854,7 +855,7 @@ fn run_rustfix(
854855
&rustfix_path,
855856
&config.config,
856857
config.revision,
857-
&rustfix_comments,
858+
config.comments,
858859
)?;
859860
cmd.args(extra_args);
860861
// picking the crate name from the file name is problematic when `.revision_name` is inserted
@@ -904,15 +905,7 @@ fn check_test_result(
904905
let revision = config.revision;
905906
// Always remove annotation comments from stderr.
906907
let diagnostics = rustc_stderr::process(path, &output.stderr);
907-
check_test_output(
908-
path,
909-
&mut errors,
910-
revision,
911-
&config.config,
912-
comments,
913-
&output.stdout,
914-
&diagnostics.rendered,
915-
);
908+
check_test_output(&mut errors, config, &output.stdout, &diagnostics.rendered);
916909
// Check error annotations in the source against output
917910
check_annotations(
918911
diagnostics.messages,
@@ -934,19 +927,11 @@ fn check_test_result(
934927
}
935928
}
936929

937-
fn check_test_output(
938-
path: &Path,
939-
errors: &mut Vec<Error>,
940-
revision: &str,
941-
config: &Config,
942-
comments: &Comments,
943-
stdout: &[u8],
944-
stderr: &[u8],
945-
) {
930+
fn check_test_output(errors: &mut Vec<Error>, config: &TestConfig, stdout: &[u8], stderr: &[u8]) {
946931
// Check output files (if any)
947932
// Check output files against actual output
948-
check_output(stderr, path, errors, "stderr", config, comments, revision);
949-
check_output(stdout, path, errors, "stdout", config, comments, revision);
933+
check_output(stderr, errors, "stderr", config);
934+
check_output(stdout, errors, "stdout", config);
950935
}
951936

952937
fn check_annotations(
@@ -1115,25 +1100,28 @@ fn check_annotations(
11151100

11161101
fn check_output(
11171102
output: &[u8],
1118-
path: &Path,
11191103
errors: &mut Errors,
11201104
kind: &'static str,
1121-
config: &Config,
1122-
comments: &Comments,
1123-
revision: &str,
1105+
config: &TestConfig,
11241106
) -> PathBuf {
1125-
let target = config.target.as_ref().unwrap();
1126-
let output = normalize(output, comments, revision, kind);
1127-
let path = output_path(path, comments, revised(revision, kind), target, revision);
1128-
match &config.output_conflict_handling {
1107+
let target = config.config.target.as_ref().unwrap();
1108+
let output = normalize(output, config.comments, config.revision, kind);
1109+
let path = output_path(
1110+
config.path,
1111+
config.comments,
1112+
revised(config.revision, kind),
1113+
target,
1114+
config.revision,
1115+
);
1116+
match &config.config.output_conflict_handling {
11291117
OutputConflictHandling::Error => {
11301118
let expected_output = std::fs::read(&path).unwrap_or_default();
11311119
if output != expected_output {
11321120
errors.push(Error::OutputDiffers {
11331121
path: path.clone(),
11341122
actual: output.clone(),
11351123
expected: expected_output,
1136-
bless_command: config.bless_command.clone(),
1124+
bless_command: config.config.bless_command.clone(),
11371125
});
11381126
}
11391127
}

0 commit comments

Comments
 (0)