Skip to content

Instantly share code, notes, and snippets.

@jamesmunns
Created September 9, 2019 12:04
Show Gist options
  • Save jamesmunns/51389a60bea580d0420eff464b45bea4 to your computer and use it in GitHub Desktop.
Save jamesmunns/51389a60bea580d0420eff464b45bea4 to your computer and use it in GitHub Desktop.
james@archx1c6g ➜ write-test git:(master) ✗ cat ./src/main.rs
use std::io::Write;
fn main() {
for _ in 0..10 {
writeln!(
::std::io::stdout().lock(),
"Hello, world!"
).unwrap_or_else(|_| {
eprintln!("stderr: Hello, stderr!");
});
// This panics
// println!("Hello, world!");
::std::thread::sleep_ms(1000);
}
eprintln!("stderr: Test Over in Rust!");
}
james@archx1c6g ➜ write-test git:(master) ✗ cat ./test.sh
set -euxo pipefail
cargo build
./target/debug/write-test | head -n 5
echo "Test Passed!"
james@archx1c6g ➜ write-test git:(master) ✗ ./test.sh
+ cargo build
Compiling write-test v0.1.0 (/tmp/write-test)
warning: use of deprecated item 'std::thread::sleep_ms': replaced by `std::thread::sleep`
--> src/main.rs:13:9
|
13 | ::std::thread::sleep_ms(1000);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.22s
+ ./target/debug/write-test
+ head -n 5
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
stderr: Hello, stderr!
stderr: Hello, stderr!
stderr: Hello, stderr!
stderr: Hello, stderr!
stderr: Test Over in Rust!
+ echo 'Test Passed!'
Test Passed!
james@archx1c6g ➜ write-test git:(master) ✗
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment