From 4d512afdaef0505cd19f1fd895060d8990487db2 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Thu, 23 Apr 2020 13:29:10 -0400 Subject: [PATCH] refactor: update arg tests to use new binary env --- tests/arg_tests.rs | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/tests/arg_tests.rs b/tests/arg_tests.rs index 0cf0cd45..ff760f9e 100644 --- a/tests/arg_tests.rs +++ b/tests/arg_tests.rs @@ -1,29 +1,18 @@ -use std::process::Command; - use assert_cmd::prelude::*; use predicates::prelude::*; +use std::process::Command; // These tests are mostly here just to ensure that invalid results will be caught when passing arguments... -// TODO: [TEST] Allow for release testing. Do this with paths. - //======================RATES======================// -fn get_os_binary_loc() -> String { - if cfg!(target_os = "linux") { - "./target/x86_64-unknown-linux-gnu/debug/btm".to_string() - } else if cfg!(target_os = "windows") { - "./target/x86_64-pc-windows-msvc/debug/btm".to_string() - } else if cfg!(target_os = "macos") { - "./target/x86_64-apple-darwin/debug/btm".to_string() - } else { - "".to_string() - } +fn get_binary_location() -> String { + env!("CARGO_BIN_EXE_btm").to_string() } #[test] fn test_small_rate() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-r") .arg("249") .assert() @@ -36,7 +25,7 @@ fn test_small_rate() -> Result<(), Box> { #[test] fn test_large_default_time() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-t") .arg("18446744073709551616") .assert() @@ -49,7 +38,7 @@ fn test_large_default_time() -> Result<(), Box> { #[test] fn test_small_default_time() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-t") .arg("900") .assert() @@ -62,7 +51,7 @@ fn test_small_default_time() -> Result<(), Box> { #[test] fn test_large_delta_time() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-d") .arg("18446744073709551616") .assert() @@ -75,7 +64,7 @@ fn test_large_delta_time() -> Result<(), Box> { #[test] fn test_small_delta_time() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-d") .arg("900") .assert() @@ -88,7 +77,7 @@ fn test_small_delta_time() -> Result<(), Box> { #[test] fn test_large_rate() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-r") .arg("18446744073709551616") .assert() @@ -102,7 +91,7 @@ fn test_large_rate() -> Result<(), Box> { #[test] fn test_negative_rate() -> Result<(), Box> { // This test should auto fail due to how clap works - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-r") .arg("-1000") .assert() @@ -116,7 +105,7 @@ fn test_negative_rate() -> Result<(), Box> { #[test] fn test_invalid_rate() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-r") .arg("100-1000") .assert() @@ -128,7 +117,7 @@ fn test_invalid_rate() -> Result<(), Box> { #[test] fn test_conflicting_temps() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("-c") .arg("-f") .assert() @@ -142,7 +131,7 @@ fn test_conflicting_temps() -> Result<(), Box> { #[test] fn test_invalid_default_widget_1() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("--default_widget_type") .arg("fake_widget") .assert() @@ -154,7 +143,7 @@ fn test_invalid_default_widget_1() -> Result<(), Box> { #[test] fn test_invalid_default_widget_2() -> Result<(), Box> { - Command::new(get_os_binary_loc()) + Command::new(get_binary_location()) .arg("--default_widget_type") .arg("cpu") .arg("--default_widget_count")