Skip to content

Commit 725f0f1

Browse files
committed
tests: add all examples to test
Add async-example and async-stream-example to test. Signed-off-by: Tim Zhang <tim@hyper.sh>
1 parent ae3bead commit 725f0f1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tests/sync-test.rs renamed to tests/run-examples.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ use std::{
44
time::Duration,
55
};
66

7-
#[test]
8-
fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
7+
fn run_example(server: &str, client: &str) -> Result<(), Box<dyn std::error::Error>> {
98
// start the server and give it a moment to start.
10-
let mut server = run_example("server").spawn().unwrap();
9+
let mut server = do_run_example(server).spawn().unwrap();
1110
std::thread::sleep(Duration::from_secs(2));
1211

13-
let mut client = run_example("client").spawn().unwrap();
12+
let mut client = do_run_example(client).spawn().unwrap();
1413
let mut client_succeeded = false;
1514
let start = std::time::Instant::now();
1615
let timeout = Duration::from_secs(600);
@@ -56,7 +55,7 @@ fn run_sync_example() -> Result<(), Box<dyn std::error::Error>> {
5655
Ok(())
5756
}
5857

59-
fn run_example(example: &str) -> Command {
58+
fn do_run_example(example: &str) -> Command {
6059
let mut cmd = Command::new("cargo");
6160
cmd.arg("run")
6261
.arg("--example")
@@ -81,3 +80,14 @@ fn wait_with_output(name: &str, cmd: Child) {
8180
println!("==== {name} output end");
8281
}
8382
}
83+
84+
#[test]
85+
fn run_examples() -> Result<(), Box<dyn std::error::Error>> {
86+
run_example("server", "client")?;
87+
#[cfg(unix)]
88+
run_example("async-server", "async-client")?;
89+
#[cfg(unix)]
90+
run_example("async-stream-server", "async-stream-client")?;
91+
92+
Ok(())
93+
}

0 commit comments

Comments
 (0)