From 6a1061c11a2859b0be7afea663c4d88d95b32665 Mon Sep 17 00:00:00 2001 From: Marco Ieni <11428655+MarcoIeni@users.noreply.github.com> Date: Fri, 16 Dec 2022 11:02:11 +0100 Subject: [PATCH 1/2] tests: support CARGO_TARGET_DIR env variable --- tests/tests.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 091a6d4..5b124d7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,10 +1,35 @@ +use std::env; +use std::path::PathBuf; use std::process::Command; use std::thread; use std::time; +fn target_dir() -> PathBuf { + env::var("CARGO_TARGET_DIR") + .unwrap_or_else(|_| "target".to_string()) + .into() +} + +fn examples_dir() -> PathBuf { + target_dir() + .join("debug") + .join("examples") +} + +fn server_command() -> Command { + let server_bin_path = examples_dir().join("server"); + Command::new(server_bin_path) +} + +fn client_command() -> Command { + let client_bin_path = examples_dir().join("client"); + println!("client_bin_path: {:?}", client_bin_path); + Command::new(client_bin_path) +} + #[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 +39,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 +62,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() From 794c9fa1addb9b93546e1f7bf3d0128507531a31 Mon Sep 17 00:00:00 2001 From: Marco Ieni <11428655+MarcoIeni@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:26:41 +0100 Subject: [PATCH 2/2] address pr comment --- tests/tests.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 5b124d7..f08b7cb 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -4,27 +4,21 @@ use std::process::Command; use std::thread; use std::time; -fn target_dir() -> PathBuf { - env::var("CARGO_TARGET_DIR") - .unwrap_or_else(|_| "target".to_string()) - .into() -} - fn examples_dir() -> PathBuf { - target_dir() + 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 { - let server_bin_path = examples_dir().join("server"); - Command::new(server_bin_path) + Command::new(examples_dir().join("server")) } fn client_command() -> Command { - let client_bin_path = examples_dir().join("client"); - println!("client_bin_path: {:?}", client_bin_path); - Command::new(client_bin_path) + Command::new(examples_dir().join("client")) } #[test]