Skip to content

Commit 7de3b0e

Browse files
committed
tests: hide simulator output by default, indent when showing
The test output was almost impossible to read with all the simulator output being dumped alongside the test output. Now this is hidden. With `--nocapture` it is shown indented below each test.
1 parent f06c57c commit 7de3b0e

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

README-rust.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ To run them, use:
2020

2121
cargo test --features=simulator,tokio -- --test-threads 1
2222

23+
Use `--nocapture` to also see some useful simulator output.
24+
25+
cargo test --features=simulator,tokio -- --test-threads 1 --nocapture
26+
2327
If you want to test against a custom simulator build (e.g. when developing new firmware features),
2428
you can run:
2529

ci.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cargo fmt --check
2424

2525
for feature_set in "${features[@]}"; do
2626
echo $feature_set
27-
cargo test --tests --locked --features="$feature_set" -- --nocapture --test-threads 1
27+
cargo test --tests --locked --features="$feature_set" -- --nocapture --test-threads 1 --nocapture
2828
cargo clippy --tests --locked --features="$feature_set" -- -D warnings -A clippy::empty-docs
2929
done
3030

tests/util/mod.rs

+30-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use bitcoin::hashes::Hash;
77
use reqwest::Client;
88
use serde::{Deserialize, Serialize};
9+
use std::io::BufRead;
910
use std::os::unix::fs::PermissionsExt;
1011
use std::path::{Path, PathBuf};
1112
use std::process::{Child, Command};
@@ -37,11 +38,33 @@ struct Server(Child);
3738

3839
impl Server {
3940
fn launch(filename: &str) -> Self {
40-
Self(
41-
Command::new(filename)
42-
.spawn()
43-
.expect("failed to start server"),
44-
)
41+
//let mut command = Command::new(filename);
42+
43+
let mut command = Command::new("stdbuf");
44+
command
45+
.arg("-oL") // Line buffering for stdout
46+
.arg(filename)
47+
.stdout(std::process::Stdio::piped());
48+
49+
command.stdout(std::process::Stdio::piped()); // Capture stdout
50+
51+
let mut child = command.spawn().expect("failed to start server");
52+
53+
// Take stdout handle from child
54+
let stdout = child.stdout.take().unwrap();
55+
56+
// Spawn a thread to process the output, so we can print it indented for clarity.
57+
std::thread::spawn(move || {
58+
let reader = std::io::BufReader::new(stdout);
59+
for line in reader.lines() {
60+
match line {
61+
Ok(line) => println!("\t\t{}", line),
62+
Err(e) => eprintln!("Error reading line: {}", e),
63+
}
64+
}
65+
});
66+
67+
Self(child)
4568
}
4669
}
4770

@@ -127,7 +150,8 @@ pub async fn test_simulators_after_pairing(
127150
download_simulators().await.unwrap()
128151
};
129152
for simulator_filename in simulator_filenames {
130-
println!("Simulator tests using {}", simulator_filename);
153+
println!();
154+
println!("\tSimulator tests using {}", simulator_filename);
131155
let _server = Server::launch(&simulator_filename);
132156
let noise_config = Box::new(bitbox_api::NoiseConfigNoCache {});
133157
let bitbox = bitbox_api::BitBox::<bitbox_api::runtime::TokioRuntime>::from_simulator(

0 commit comments

Comments
 (0)