Skip to content

Commit 3d8b381

Browse files
committed
Actually handle run and rustfix status emitters
Previously we didn't run `done` on them
1 parent d88a761 commit 3d8b381

File tree

10 files changed

+118
-77
lines changed

10 files changed

+118
-77
lines changed

src/aux_builds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ impl Build for AuxBuilder {
109109
config,
110110
comments: &comments,
111111
aux_dir: self.aux_file.parent().unwrap(),
112-
status: &SilentStatus {
112+
status: Box::new(SilentStatus {
113113
revision: String::new(),
114114
path: self.aux_file.content.clone(),
115-
},
115+
}),
116116
};
117117

118118
config.patch_out_dir();

src/custom_flags.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::{
55
process::{Command, Output},
66
};
77

8-
use crate::{build_manager::BuildManager, per_test_config::TestConfig, Config, Errored};
8+
use crate::{
9+
build_manager::BuildManager, per_test_config::TestConfig, test_result::TestRun, Config, Errored,
10+
};
911

1012
#[cfg(feature = "rustc")]
1113
pub mod run;
@@ -32,15 +34,15 @@ pub trait Flag: Send + Sync + UnwindSafe + RefUnwindSafe + std::fmt::Debug {
3234
}
3335

3436
/// Run an action after a test is finished.
35-
/// Returns `false` if no action was taken.
37+
/// Returns `None` if no action was taken.
3638
fn post_test_action(
3739
&self,
3840
_config: &TestConfig<'_>,
3941
_cmd: &mut Command,
4042
_output: &Output,
4143
_build_manager: &BuildManager<'_>,
42-
) -> Result<bool, Errored> {
43-
Ok(false)
44+
) -> Result<Option<TestRun>, Errored> {
45+
Ok(None)
4446
}
4547

4648
/// Whether the flag gets overridden by the same flag in revisions.

src/custom_flags/run.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::{
77
process::{Command, Output},
88
};
99

10-
use crate::{build_manager::BuildManager, per_test_config::TestConfig, Error, Errored};
10+
use crate::{
11+
build_manager::BuildManager, per_test_config::TestConfig, test_result::TestRun, Error, Errored,
12+
TestOk,
13+
};
1114

1215
use super::Flag;
1316

@@ -30,14 +33,14 @@ impl Flag for Run {
3033
cmd: &mut Command,
3134
_output: &Output,
3235
_build_manager: &BuildManager<'_>,
33-
) -> Result<bool, Errored> {
36+
) -> Result<Option<TestRun>, Errored> {
3437
let exit_code = self.exit_code;
3538
let revision = config.extension("run");
3639
let config = TestConfig {
3740
config: config.config.clone(),
3841
comments: config.comments,
3942
aux_dir: config.aux_dir,
40-
status: &config.status.for_revision(&revision),
43+
status: config.status.for_revision(&revision),
4144
};
4245
cmd.arg("--print").arg("file-names");
4346
let output = cmd.output().unwrap();
@@ -77,16 +80,19 @@ impl Flag for Run {
7780
},
7881
})
7982
}
80-
if errors.is_empty() {
81-
Ok(true)
82-
} else {
83-
Err(Errored {
84-
command: format!("{exe:?}"),
85-
errors,
86-
stderr: output.stderr,
87-
stdout: output.stdout,
88-
})
89-
}
83+
Ok(Some(TestRun {
84+
result: if errors.is_empty() {
85+
Ok(TestOk::Ok)
86+
} else {
87+
Err(Errored {
88+
command: format!("{exe:?}"),
89+
errors,
90+
stderr: output.stderr,
91+
stdout: output.stdout,
92+
})
93+
},
94+
status: config.status,
95+
}))
9096
}
9197
}
9298

src/custom_flags/rustfix.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::{
1111
build_manager::BuildManager,
1212
parser::OptWithLine,
1313
per_test_config::{Comments, Revisioned, TestConfig},
14-
Error, Errored,
14+
test_result::TestRun,
15+
Error, Errored, TestOk,
1516
};
1617

1718
use super::Flag;
@@ -46,17 +47,15 @@ impl Flag for RustfixMode {
4647
_cmd: &mut Command,
4748
output: &Output,
4849
build_manager: &BuildManager<'_>,
49-
) -> Result<bool, Errored> {
50+
) -> Result<Option<TestRun>, Errored> {
5051
let global_rustfix = match config.exit_status()? {
5152
Some(Spanned {
5253
content: 101 | 0, ..
5354
}) => RustfixMode::Disabled,
5455
_ => *self,
5556
};
56-
5757
let output = output.clone();
5858
let no_run_rustfix = config.find_one_custom("no-rustfix")?;
59-
6059
let fixed_code = (no_run_rustfix.is_none() && global_rustfix.enabled())
6160
.then_some(())
6261
.and_then(|()| {
@@ -130,12 +129,6 @@ impl Flag for RustfixMode {
130129
))
131130
.collect(),
132131
};
133-
let config = TestConfig {
134-
config: config.config.clone(),
135-
comments: &rustfix_comments,
136-
aux_dir: config.aux_dir,
137-
status: config.status,
138-
};
139132

140133
let run = fixed_code.is_some();
141134
let mut errors = vec![];
@@ -156,30 +149,38 @@ impl Flag for RustfixMode {
156149
.to_str()
157150
.unwrap()
158151
.replace('-', "_");
159-
let config = TestConfig {
160-
config: config.config,
161-
comments: &rustfix_comments,
162-
aux_dir: config.aux_dir,
163-
status: &config.status.for_path(&rustfix_path),
164-
};
152+
165153
if !errors.is_empty() {
166-
return Err(Errored {
167-
command: format!("checking {}", config.status.path().display()),
168-
errors,
169-
stderr: vec![],
170-
stdout: vec![],
171-
});
154+
return Ok(Some(TestRun {
155+
result: Err(Errored {
156+
command: format!("checking {}", config.status.path().display()),
157+
errors,
158+
stderr: vec![],
159+
stdout: vec![],
160+
}),
161+
status: config.status.for_path(&rustfix_path),
162+
}));
172163
}
173164

174165
if !run {
175-
return Ok(false);
166+
return Ok(None);
176167
}
177168

169+
let config = TestConfig {
170+
config: config.config.clone(),
171+
comments: &rustfix_comments,
172+
aux_dir: config.aux_dir,
173+
status: config.status.for_path(&rustfix_path),
174+
};
175+
178176
let mut cmd = config.build_command(build_manager)?;
179177
cmd.arg("--crate-name").arg(crate_name);
180178
let output = cmd.output().unwrap();
181179
if output.status.success() {
182-
Ok(false)
180+
Ok(Some(TestRun {
181+
result: Ok(TestOk::Ok),
182+
status: config.status,
183+
}))
183184
} else {
184185
let diagnostics = config.process(&output.stderr);
185186
Err(Errored {

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ pub fn test_command(mut config: Config, path: &Path) -> Result<Command> {
142142
config,
143143
comments: &comments,
144144
aux_dir: &path.parent().unwrap().join("auxiliary"),
145-
status: &SilentStatus {
145+
status: Box::new(SilentStatus {
146146
revision: String::new(),
147147
path: path.to_path_buf(),
148-
},
148+
}),
149149
};
150150
let build_manager = BuildManager::new(&(), config.config.clone());
151151

@@ -333,15 +333,18 @@ fn parse_and_test_file(
333333
continue;
334334
}
335335

336-
let test_config = TestConfig {
336+
let mut test_config = TestConfig {
337337
config: config.clone(),
338338
comments: &comments,
339339
aux_dir: &status.path().parent().unwrap().join("auxiliary"),
340-
status: &status,
340+
status,
341341
};
342342

343-
let result = test_config.run_test(build_manager);
344-
runs.push(TestRun { result, status })
343+
let result = test_config.run_test(build_manager, &mut runs);
344+
runs.push(TestRun {
345+
result,
346+
status: test_config.status,
347+
})
345348
}
346349
Ok(runs)
347350
}

src/per_test_config.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::diagnostics::{Diagnostics, Message};
1818
pub use crate::parser::{Comments, Condition, Revisioned};
1919
use crate::parser::{ErrorMatch, ErrorMatchKind, OptWithLine};
2020
use crate::status_emitter::TestStatus;
21-
use crate::test_result::{Errored, TestOk, TestResult};
21+
use crate::test_result::{Errored, TestOk, TestResult, TestRun};
2222
use crate::{core::strip_path_prefix, Config, Error, Errors, OutputConflictHandling};
2323

2424
/// All information needed to run a single test
@@ -29,7 +29,7 @@ pub struct TestConfig<'a> {
2929
/// The path to the folder where to look for aux files
3030
pub aux_dir: &'a Path,
3131
/// When doing long-running operations, you can inform the user about it here.
32-
pub status: &'a dyn TestStatus,
32+
pub status: Box<dyn TestStatus>,
3333
}
3434

3535
impl TestConfig<'_> {
@@ -400,7 +400,11 @@ impl TestConfig<'_> {
400400
Ok(())
401401
}
402402

403-
pub(crate) fn run_test(mut self, build_manager: &BuildManager<'_>) -> TestResult {
403+
pub(crate) fn run_test(
404+
&mut self,
405+
build_manager: &BuildManager<'_>,
406+
runs: &mut Vec<TestRun>,
407+
) -> TestResult {
404408
self.patch_out_dir();
405409

406410
let mut cmd = self.build_command(build_manager)?;
@@ -416,7 +420,10 @@ impl TestConfig<'_> {
416420
for rev in self.comments() {
417421
for custom in rev.custom.values() {
418422
for flag in &custom.content {
419-
if flag.post_test_action(&self, &mut cmd, &output, build_manager)? {
423+
if let Some(result) =
424+
flag.post_test_action(&self, &mut cmd, &output, build_manager)?
425+
{
426+
runs.push(result);
420427
return Ok(TestOk::Ok);
421428
}
422429
}

src/test_result.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ impl Errored {
3939
}
4040
}
4141

42-
pub(crate) struct TestRun {
43-
pub(crate) result: TestResult,
44-
pub(crate) status: Box<dyn TestStatus>,
42+
/// Result of an actual test or sub-test (revision, fixed, run, ...) including its status.
43+
pub struct TestRun {
44+
/// Actual test run output.
45+
pub result: TestResult,
46+
/// Usually created via `for_revsion` or `for_path`
47+
pub status: Box<dyn TestStatus>,
4548
}

src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ macro_rules! config {
2424
config: $config,
2525
comments: &comments,
2626
aux_dir: Path::new("unused_doesnt_exist"),
27-
status: &crate::status_emitter::SilentStatus {
27+
status: Box::new(crate::status_emitter::SilentStatus {
2828
path: path.to_path_buf(),
2929
revision: String::new(),
30-
},
30+
}),
3131
};
3232
};
3333
}

0 commit comments

Comments
 (0)