diff --git a/tests/tests.rs b/tests/tests.rs index 091a6d4..f08b7cb 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,10 +1,29 @@ +use std::env; +use std::path::PathBuf; use std::process::Command; use std::thread; use std::time; +fn examples_dir() -> PathBuf { + let target_dir: PathBuf = env::var("CARGO_TARGET_DIR") + .unwrap_or_else(|_| "target".to_string()) + .into(); + target_dir + .join("debug") + .join("examples") +} + +fn server_command() -> Command { + Command::new(examples_dir().join("server")) +} + +fn client_command() -> Command { + Command::new(examples_dir().join("client")) +} + #[test] fn client() { - let rc = Command::new("target/debug/examples/client") + let rc = client_command() .arg("https://google.com") .output() .expect("cannot run client example"); @@ -14,7 +33,7 @@ fn client() { #[test] fn server() { - let mut srv = Command::new("target/debug/examples/server") + let mut srv = server_command() .arg("1337") .spawn() .expect("cannot run server example"); @@ -37,14 +56,14 @@ fn server() { #[test] fn custom_ca_store() { - let mut srv = Command::new("target/debug/examples/server") + let mut srv = server_command() .arg("1338") .spawn() .expect("cannot run server example"); thread::sleep(time::Duration::from_secs(1)); - let rc = Command::new("target/debug/examples/client") + let rc = client_command() .arg("https://localhost:1338") .arg("examples/sample.pem") .output()