Skip to content

Commit 2de49ab

Browse files
authored
Merge pull request #259 from oli-obk/update_status
Remove `update_status`
2 parents bbe74aa + 2f3a770 commit 2de49ab

File tree

7 files changed

+71
-48
lines changed

7 files changed

+71
-48
lines changed

CHANGELOG.md

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

2121
### Removed
2222

23+
* `TestStatus::update_status`, instead use a revision if you want to run subcommands
24+
2325
## [0.25.0] - 2024-07-24
2426

2527
### Added

src/build_manager.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::{
66
sync::{Arc, OnceLock, RwLock},
77
};
88

9-
use crate::{status_emitter::StatusEmitter, Config, Errored};
9+
use crate::{
10+
status_emitter::{RevisionStyle, StatusEmitter},
11+
Config, Errored,
12+
};
1013

1114
/// A build shared between all tests of the same `BuildManager`
1215
pub trait Build {
@@ -83,7 +86,7 @@ impl<'a> BuildManager<'a> {
8386
let build = self
8487
.status_emitter
8588
.register_test(what.description().into())
86-
.for_revision("");
89+
.for_revision("", RevisionStyle::Parent);
8790
let res = what.build(self).map_err(|e| err = Some(e));
8891
build.done(
8992
&res.as_ref()

src/custom_flags/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use spanned::Spanned;
55
use std::process::{Command, Output};
66

77
use crate::{
8-
build_manager::BuildManager, display, per_test_config::TestConfig, Error, Errored, TestOk,
9-
TestRun,
8+
build_manager::BuildManager, display, per_test_config::TestConfig,
9+
status_emitter::RevisionStyle, Error, Errored, TestOk, TestRun,
1010
};
1111

1212
use super::Flag;
@@ -37,7 +37,7 @@ impl Flag for Run {
3737
config: config.config.clone(),
3838
comments: config.comments,
3939
aux_dir: config.aux_dir,
40-
status: config.status.for_revision(&revision),
40+
status: config.status.for_revision(&revision, RevisionStyle::Show),
4141
};
4242
cmd.arg("--print").arg("file-names");
4343
let output = cmd.output().unwrap();

src/dependencies.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use crate::{
1515
build_manager::{Build, BuildManager},
1616
custom_flags::Flag,
1717
per_test_config::TestConfig,
18+
status_emitter::RevisionStyle,
1819
test_result::Errored,
19-
CommandBuilder, Config, OutputConflictHandling,
20+
CommandBuilder, Config, OutputConflictHandling, TestOk,
2021
};
2122

2223
#[derive(Default, Debug)]
@@ -390,13 +391,23 @@ impl Flag for DependencyBuilder {
390391
config: &TestConfig<'_>,
391392
build_manager: &BuildManager<'_>,
392393
) -> Result<(), Errored> {
393-
config
394-
.status
395-
.update_status("waiting for dependencies to finish building".into());
396-
let extra_args = build_manager.build(self.clone())?;
397-
cmd.args(extra_args);
398-
config.status.update_status(String::new());
399-
Ok(())
394+
let status = config.status.for_revision(
395+
"waiting for dependencies to finish building",
396+
RevisionStyle::Quiet,
397+
);
398+
match build_manager.build(self.clone()) {
399+
Ok(extra_args) => {
400+
cmd.args(extra_args);
401+
status.done(&Ok(TestOk::Ok));
402+
Ok(())
403+
}
404+
Err(err) => {
405+
let err = Err(err);
406+
status.done(&err);
407+
#[allow(clippy::unnecessary_literal_unwrap)]
408+
Err(err.unwrap_err())
409+
}
410+
}
400411
}
401412
}
402413

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub use core::CrateType;
1818
pub use filter::Match;
1919
use per_test_config::TestConfig;
2020
use spanned::Spanned;
21+
use status_emitter::RevisionStyle;
2122
use status_emitter::{StatusEmitter, TestStatus};
2223
use std::collections::VecDeque;
2324
use std::path::Path;
@@ -326,7 +327,7 @@ fn parse_and_test_file(
326327
let revisions = comments.revisions.as_deref().unwrap_or(EMPTY);
327328
let mut runs = vec![];
328329
for revision in revisions {
329-
let status = status.for_revision(revision);
330+
let status = status.for_revision(revision, RevisionStyle::Show);
330331
// Ignore file if only/ignore rules do (not) apply
331332
if !config.test_file_conditions(&comments, revision) {
332333
runs.push(TestRun {

src/status_emitter.rs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,22 @@ pub trait StatusEmitter: Sync + RefUnwindSafe {
4343
) -> Box<dyn Summary>;
4444
}
4545

46+
/// Some configuration options for revisions
47+
#[derive(Debug, Clone, Copy)]
48+
pub enum RevisionStyle {
49+
/// Things like dependencies or aux files building are noise in non-interactif mode
50+
/// and thus silenced.
51+
Quiet,
52+
/// Always show them, even if rendering to a file
53+
Show,
54+
/// The parent, only show in indicatif mode and on failure
55+
Parent,
56+
}
57+
4658
/// Information about a specific test run.
4759
pub trait TestStatus: Send + Sync + RefUnwindSafe {
4860
/// Create a copy of this test for a new revision.
49-
fn for_revision(&self, revision: &str) -> Box<dyn TestStatus>;
61+
fn for_revision(&self, revision: &str, style: RevisionStyle) -> Box<dyn TestStatus>;
5062

5163
/// Create a copy of this test for a new path.
5264
fn for_path(&self, path: &Path) -> Box<dyn TestStatus>;
@@ -60,9 +72,6 @@ pub trait TestStatus: Send + Sync + RefUnwindSafe {
6072
stdout: &'a [u8],
6173
) -> Box<dyn Debug + 'a>;
6274

63-
/// Change the status of the test while it is running to supply some kind of progress
64-
fn update_status(&self, msg: String);
65-
6675
/// A test has finished, handle the result immediately.
6776
fn done(&self, _result: &TestResult) {}
6877

@@ -111,7 +120,7 @@ pub struct SilentStatus {
111120
}
112121

113122
impl TestStatus for SilentStatus {
114-
fn for_revision(&self, revision: &str) -> Box<dyn TestStatus> {
123+
fn for_revision(&self, revision: &str, _style: RevisionStyle) -> Box<dyn TestStatus> {
115124
Box::new(SilentStatus {
116125
revision: revision.into(),
117126
path: self.path.clone(),
@@ -134,8 +143,6 @@ impl TestStatus for SilentStatus {
134143
Box::new(())
135144
}
136145

137-
fn update_status(&self, _msg: String) {}
138-
139146
fn path(&self) -> &Path {
140147
&self.path
141148
}
@@ -179,7 +186,6 @@ enum Msg {
179186
Inc,
180187
IncLength,
181188
Finish,
182-
Status(String, String),
183189
}
184190

185191
impl Text {
@@ -212,9 +218,6 @@ impl Text {
212218
spinner.finish_and_clear();
213219
}
214220
}
215-
Msg::Status(msg, status) => {
216-
threads.get_mut(&msg).unwrap().set_message(status);
217-
}
218221
Msg::Push(msg) => {
219222
let spinner =
220223
bars.add(ProgressBar::new_spinner().with_prefix(msg.clone()));
@@ -295,6 +298,7 @@ struct TextTest {
295298
path: PathBuf,
296299
revision: String,
297300
first: AtomicBool,
301+
style: RevisionStyle,
298302
}
299303

300304
impl TextTest {
@@ -322,17 +326,23 @@ impl TestStatus for TextTest {
322326
let old_msg = self.msg();
323327
let msg = format!("... {result}");
324328
if ProgressDrawTarget::stdout().is_hidden() {
325-
println!("{old_msg} {msg}");
326-
std::io::stdout().flush().unwrap();
329+
match self.style {
330+
RevisionStyle::Quiet => {}
331+
RevisionStyle::Show | RevisionStyle::Parent => {
332+
let revision = if self.revision.is_empty() {
333+
String::new()
334+
} else {
335+
format!(" (revision `{}`)", self.revision)
336+
};
337+
println!("{}{revision} {msg}", display(&self.path));
338+
std::io::stdout().flush().unwrap();
339+
}
340+
}
327341
}
328342
self.text.sender.send(Msg::Pop(old_msg, Some(msg))).unwrap();
329343
}
330344
}
331345

332-
fn update_status(&self, msg: String) {
333-
self.text.sender.send(Msg::Status(self.msg(), msg)).unwrap();
334-
}
335-
336346
fn failed_test<'a>(
337347
&self,
338348
cmd: &str,
@@ -373,7 +383,7 @@ impl TestStatus for TextTest {
373383
&self.path
374384
}
375385

376-
fn for_revision(&self, revision: &str) -> Box<dyn TestStatus> {
386+
fn for_revision(&self, revision: &str, style: RevisionStyle) -> Box<dyn TestStatus> {
377387
if !self.first.swap(false, std::sync::atomic::Ordering::Relaxed)
378388
&& self.text.is_quiet_output()
379389
{
@@ -385,6 +395,7 @@ impl TestStatus for TextTest {
385395
path: self.path.clone(),
386396
revision: revision.to_owned(),
387397
first: AtomicBool::new(false),
398+
style,
388399
};
389400
self.text.sender.send(Msg::Push(text.msg())).unwrap();
390401
Box::new(text)
@@ -396,6 +407,7 @@ impl TestStatus for TextTest {
396407
path: path.to_path_buf(),
397408
revision: self.revision.clone(),
398409
first: AtomicBool::new(false),
410+
style: RevisionStyle::Show,
399411
};
400412
self.text.sender.send(Msg::Push(text.msg())).unwrap();
401413
Box::new(text)
@@ -416,6 +428,7 @@ impl StatusEmitter for Text {
416428
path,
417429
revision: String::new(),
418430
first: AtomicBool::new(true),
431+
style: RevisionStyle::Parent,
419432
})
420433
}
421434

@@ -917,7 +930,7 @@ impl<const GROUP: bool> TestStatus for PathAndRev<GROUP> {
917930
&self.path
918931
}
919932

920-
fn for_revision(&self, revision: &str) -> Box<dyn TestStatus> {
933+
fn for_revision(&self, revision: &str, _style: RevisionStyle) -> Box<dyn TestStatus> {
921934
Box::new(Self {
922935
path: self.path.clone(),
923936
revision: revision.to_owned(),
@@ -946,8 +959,6 @@ impl<const GROUP: bool> TestStatus for PathAndRev<GROUP> {
946959
fn revision(&self) -> &str {
947960
&self.revision
948961
}
949-
950-
fn update_status(&self, _msg: String) {}
951962
}
952963

953964
impl<const GROUP: bool> StatusEmitter for Gha<GROUP> {
@@ -1050,18 +1061,16 @@ impl<T: TestStatus, U: TestStatus> TestStatus for (T, U) {
10501061
rev
10511062
}
10521063

1053-
fn for_revision(&self, revision: &str) -> Box<dyn TestStatus> {
1054-
Box::new((self.0.for_revision(revision), self.1.for_revision(revision)))
1064+
fn for_revision(&self, revision: &str, style: RevisionStyle) -> Box<dyn TestStatus> {
1065+
Box::new((
1066+
self.0.for_revision(revision, style),
1067+
self.1.for_revision(revision, style),
1068+
))
10551069
}
10561070

10571071
fn for_path(&self, path: &Path) -> Box<dyn TestStatus> {
10581072
Box::new((self.0.for_path(path), self.1.for_path(path)))
10591073
}
1060-
1061-
fn update_status(&self, msg: String) {
1062-
self.0.update_status(msg.clone());
1063-
self.1.update_status(msg)
1064-
}
10651074
}
10661075

10671076
impl<T: StatusEmitter, U: StatusEmitter> StatusEmitter for (T, U) {
@@ -1099,8 +1108,8 @@ impl<T: TestStatus + ?Sized> TestStatus for Box<T> {
10991108
(**self).revision()
11001109
}
11011110

1102-
fn for_revision(&self, revision: &str) -> Box<dyn TestStatus> {
1103-
(**self).for_revision(revision)
1111+
fn for_revision(&self, revision: &str, style: RevisionStyle) -> Box<dyn TestStatus> {
1112+
(**self).for_revision(revision, style)
11041113
}
11051114

11061115
fn for_path(&self, path: &Path) -> Box<dyn TestStatus> {
@@ -1115,10 +1124,6 @@ impl<T: TestStatus + ?Sized> TestStatus for Box<T> {
11151124
) -> Box<dyn Debug + 'a> {
11161125
(**self).failed_test(cmd, stderr, stdout)
11171126
}
1118-
1119-
fn update_status(&self, msg: String) {
1120-
(**self).update_status(msg)
1121-
}
11221127
}
11231128

11241129
impl<T: StatusEmitter + ?Sized> StatusEmitter for Box<T> {

src/test_result.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{status_emitter::TestStatus, Error};
44
use color_eyre::eyre::Result;
55

66
/// The possible non-failure results a single test can have.
7+
#[derive(Debug)]
78
pub enum TestOk {
89
/// The test passed
910
Ok,

0 commit comments

Comments
 (0)