Skip to content

Commit

Permalink
log stdout and stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jul 31, 2023
1 parent 4c61886 commit 40a5da0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tools/example-showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,17 @@ fn main() {
}

let before = Instant::now();
let result = cmd.run();
if report_details {
cmd = cmd.ignore_status();
}
let result = cmd.output();

let duration = before.elapsed();
println!("took {duration:?}");

if result.is_ok() {
if (!report_details && result.is_ok())
|| (report_details && result.as_ref().unwrap().status.success())
{
if screenshot {
let _ = fs::create_dir_all(Path::new("screenshots").join(&to_run.category));
let renamed_screenshot = fs::rename(
Expand All @@ -276,6 +282,19 @@ fn main() {
failed_examples.push((to_run, duration));
}

if report_details {
let result = result.unwrap();
let stdout = String::from_utf8_lossy(&result.stdout);
let stderr = String::from_utf8_lossy(&result.stderr);
println!("{}", stdout);
println!("{}", stderr);
let mut file = File::create(format!("{}.log", example)).unwrap();
file.write_all(b"==== stdout ====\n").unwrap();
file.write_all(stdout.as_bytes()).unwrap();
file.write_all(b"\n==== stderr ====\n").unwrap();
file.write_all(stderr.as_bytes()).unwrap();
}

thread::sleep(Duration::from_secs(1));
pb.inc();
}
Expand Down

0 comments on commit 40a5da0

Please sign in to comment.