Skip to content

Commit f08371e

Browse files
committed
./y Test: improve verbose output formatting
Signed-off-by: xizheyin <[email protected]>
1 parent 763d3eb commit f08371e

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

bootstrap/src/manifest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use color_print::cprintln;
33
use std::path::{Path, PathBuf};
44
use std::process::Command;
55

6+
#[derive(Debug)]
67
pub struct Manifest {
78
pub verbose: bool,
89
pub release: bool,

bootstrap/src/test.rs

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,76 @@ impl Run for TestCommand {
2727
cprintln!("<r,s>Test failed</r,s>: {}", info);
2828
}));
2929

30+
if manifest.verbose {
31+
cprintln!("<b>[TEST]</b> preparing to run tests with manifest: {:?}", manifest);
32+
}
33+
3034
cprintln!("<b>[TEST]</b> running cargo test");
3135
let mut command = std::process::Command::new("cargo");
3236
command.args(["test", "--manifest-path", "crates/Cargo.toml"]);
37+
if manifest.verbose {
38+
cprintln!("<b>[TEST]</b> executing command: {:?}", command);
39+
}
3340
log::debug!("running {:?}", command);
3441
assert!(command.status().unwrap().success(), "failed to run {:?}", command);
3542

3643
let testcases = self.collect_testcases(manifest);
3744
cprintln!("<b>[TEST]</b> found {} testcases", testcases.len());
45+
if manifest.verbose {
46+
for case in &testcases {
47+
cprintln!("<b>[TEST]</b> found test: {} ({:?})", case.name, case.test);
48+
}
49+
}
3850

3951
let filechecker = FileChecker::new();
4052
for testcase in testcases {
4153
match testcase.test {
4254
TestType::FileCheck => {
43-
cprint!("File checking {}...", testcase.name);
55+
if manifest.verbose {
56+
cprintln!("<b>[TEST]</b> file checking <cyan>{}</cyan>", testcase.name);
57+
cprintln!(" source: {}", testcase.source.display());
58+
cprintln!(" output: {}", testcase.output_file.display());
59+
} else {
60+
cprint!("File checking {}... ", testcase.name);
61+
}
4462
testcase.build(manifest);
4563
filechecker.run(&testcase);
4664
}
4765
TestType::Bless => {
48-
cprint!("Blessing {}...", testcase.name);
66+
if manifest.verbose {
67+
cprintln!("<b>[TEST]</b> blessing <cyan>{}</cyan>", testcase.name);
68+
cprintln!(" source: {}", testcase.source.display());
69+
cprintln!(" output: {}", testcase.output_file.display());
70+
} else {
71+
cprint!("Blessing {}... ", testcase.name);
72+
}
4973
testcase.build(manifest);
5074
bless(self.bless, &testcase);
5175
}
5276
TestType::Compile => {
53-
cprint!("Compiling {}...", testcase.name);
77+
if manifest.verbose {
78+
cprintln!("<b>[TEST]</b> compiling <cyan>{}</cyan>", testcase.name);
79+
cprintln!(" source: {}", testcase.source.display());
80+
cprintln!(" output: {}", testcase.output_file.display());
81+
} else {
82+
cprint!("Compiling {}... ", testcase.name);
83+
}
5484
testcase.build(manifest);
5585
}
5686
TestType::CompileLib => {
57-
cprint!("Compiling lib {}...", testcase.name);
87+
if manifest.verbose {
88+
cprintln!("<b>[TEST]</b> compiling lib <cyan>{}</cyan>", testcase.name);
89+
cprintln!(" source: {}", testcase.source.display());
90+
cprintln!(" output: {}", testcase.output_file.display());
91+
} else {
92+
cprint!("Compiling lib {}... ", testcase.name);
93+
}
5894
testcase.build_lib(manifest);
5995
}
6096
}
61-
cprintln!("<g>OK</g>");
97+
if !manifest.verbose {
98+
cprintln!("<g>OK</g>");
99+
}
62100
}
63101
}
64102
}
@@ -116,6 +154,7 @@ impl TestCommand {
116154
}
117155
}
118156

157+
#[derive(Debug)]
119158
pub enum TestType {
120159
/// Test an executable can be compiled
121160
Compile,
@@ -145,8 +184,16 @@ impl TestCase {
145184
.arg(&self.source)
146185
.arg("-o")
147186
.arg(&self.output_file);
187+
if manifest.verbose {
188+
cprintln!(" command: {}", format!("{:?}", command).replace('"', ""));
189+
}
148190
log::debug!("running {:?}", command);
149-
command.status().unwrap();
191+
let status = command.status().unwrap();
192+
if manifest.verbose {
193+
if status.success() {
194+
cprintln!(" <g>success</g>");
195+
}
196+
}
150197
}
151198

152199
pub fn build_lib(&self, manifest: &Manifest) {
@@ -157,10 +204,18 @@ impl TestCase {
157204
.args(["--crate-type", "lib"])
158205
.arg("-O")
159206
.arg(&self.source)
160-
.arg("--out-dir") // we use `--out-dir` to integrate with the default name convention
161-
.arg(output_dir); // so here we ignore the filename and just use the directory
207+
.arg("--out-dir")
208+
.arg(output_dir);
209+
if manifest.verbose {
210+
cprintln!(" command: {}", format!("{:?}", command).replace('"', ""));
211+
}
162212
log::debug!("running {:?}", command);
163-
command.status().unwrap();
213+
let status = command.status().unwrap();
214+
if manifest.verbose {
215+
if status.success() {
216+
cprintln!(" <g>success</g>");
217+
}
218+
}
164219
}
165220

166221
/// Get the generated C file f

0 commit comments

Comments
 (0)