Skip to content

Commit cc503c0

Browse files
committed
Create TestConfig struct to hold all the metadata of the currently running test
1 parent 8db6a2e commit cc503c0

File tree

2 files changed

+71
-57
lines changed

2 files changed

+71
-57
lines changed

src/lib.rs

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use color_eyre::eyre::{eyre, Result};
1414
use crossbeam_channel::{unbounded, Receiver, Sender};
1515
use dependencies::{Build, BuildManager};
1616
use parser::{ErrorMatch, ErrorMatchKind, OptWithLine, Revisioned, Spanned};
17+
use per_test_config::TestConfig;
1718
use rustc_stderr::{Level, Message};
1819
use spanned::Span;
1920
use status_emitter::{StatusEmitter, TestStatus};
@@ -411,7 +412,14 @@ fn parse_and_test_file(
411412
built_deps = true;
412413
}
413414

414-
let result = status.run_test(build_manager, &config, &comments);
415+
let test_config = TestConfig {
416+
config: config.clone(),
417+
revision,
418+
comments: &comments,
419+
path: status.path(),
420+
};
421+
422+
let result = run_test(build_manager, test_config);
415423
TestRun { result, status }
416424
})
417425
.collect())
@@ -565,66 +573,62 @@ fn build_aux(
565573
Ok(extra_args)
566574
}
567575

568-
impl dyn TestStatus {
569-
fn run_test(
570-
&self,
571-
build_manager: &BuildManager<'_>,
572-
config: &Config,
573-
comments: &Comments,
574-
) -> TestResult {
575-
let path = self.path();
576-
let revision = self.revision();
577-
578-
let extra_args = build_aux_files(
579-
&path.parent().unwrap().join("auxiliary"),
580-
comments,
581-
revision,
582-
config,
583-
build_manager,
584-
)?;
585-
586-
let mut config = config.clone();
587-
588-
// Put aux builds into a separate directory per path so that multiple aux files
589-
// from different directories (but with the same file name) don't collide.
590-
let relative = strip_path_prefix(path.parent().unwrap(), &config.out_dir);
591-
592-
config.out_dir.extend(relative);
593-
594-
let mut cmd = build_command(path, &config, revision, comments)?;
595-
cmd.args(&extra_args);
596-
let stdin = path.with_extension(if revision.is_empty() {
597-
"stdin".into()
598-
} else {
599-
format!("{revision}.stdin")
600-
});
601-
if stdin.exists() {
602-
cmd.stdin(std::fs::File::open(stdin).unwrap());
603-
}
576+
fn run_test(
577+
build_manager: &BuildManager<'_>,
578+
TestConfig {
579+
mut config,
580+
revision,
581+
comments,
582+
path,
583+
}: TestConfig<'_>,
584+
) -> TestResult {
585+
let extra_args = build_aux_files(
586+
&path.parent().unwrap().join("auxiliary"),
587+
comments,
588+
revision,
589+
&config,
590+
build_manager,
591+
)?;
604592

605-
let (cmd, output) = run_command(cmd)?;
593+
// Put aux builds into a separate directory per path so that multiple aux files
594+
// from different directories (but with the same file name) don't collide.
595+
let relative = strip_path_prefix(path.parent().unwrap(), &config.out_dir);
606596

607-
let mode = comments.mode(revision)?;
608-
let (cmd, output) = check_test_result(
609-
cmd,
610-
match *mode {
611-
Mode::Run { .. } => Mode::Pass,
612-
_ => *mode,
613-
},
614-
path,
615-
&config,
616-
revision,
617-
comments,
618-
output,
619-
)?;
620-
621-
if let Mode::Run { .. } = *mode {
622-
return run_test_binary(mode, path, revision, comments, cmd, &config);
623-
}
597+
config.out_dir.extend(relative);
624598

625-
run_rustfix(output, path, comments, revision, &config, *mode, extra_args)?;
626-
Ok(TestOk::Ok)
599+
let mut cmd = build_command(path, &config, revision, comments)?;
600+
cmd.args(&extra_args);
601+
let stdin = path.with_extension(if revision.is_empty() {
602+
"stdin".into()
603+
} else {
604+
format!("{revision}.stdin")
605+
});
606+
if stdin.exists() {
607+
cmd.stdin(std::fs::File::open(stdin).unwrap());
608+
}
609+
610+
let (cmd, output) = run_command(cmd)?;
611+
612+
let mode = comments.mode(revision)?;
613+
let (cmd, output) = check_test_result(
614+
cmd,
615+
match *mode {
616+
Mode::Run { .. } => Mode::Pass,
617+
_ => *mode,
618+
},
619+
path,
620+
&config,
621+
revision,
622+
comments,
623+
output,
624+
)?;
625+
626+
if let Mode::Run { .. } = *mode {
627+
return run_test_binary(mode, path, revision, comments, cmd, &config);
627628
}
629+
630+
run_rustfix(output, path, comments, revision, &config, *mode, extra_args)?;
631+
Ok(TestOk::Ok)
628632
}
629633

630634
fn run_command(mut cmd: Command) -> Result<(Command, Output), Errored> {

src/per_test_config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@
33
//! in the files. These comments still overwrite the defaults, although
44
//! some boolean settings have no way to disable them.
55
6+
use std::path::Path;
7+
68
pub use crate::parser::{Comments, Condition, Revisioned};
79
pub use crate::rustc_stderr::Level;
10+
use crate::Config;
11+
12+
pub(crate) struct TestConfig<'a> {
13+
pub config: Config,
14+
pub revision: &'a str,
15+
pub comments: &'a Comments,
16+
pub path: &'a Path,
17+
}

0 commit comments

Comments
 (0)