From 100b0413d958531e40ade2c1c51f762e2e792770 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Wed, 5 Apr 2023 22:52:47 +0200 Subject: [PATCH] Check for .exe on Windows Avoids always rebuilding the executable on Windows. Thanks @epage! --- src/main.rs | 11 ++++++++++- tests/data/script-using-env.rs | 4 ++++ tests/tests/script.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/data/script-using-env.rs diff --git a/src/main.rs b/src/main.rs index 134ee15..7a4f7e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -339,7 +339,16 @@ impl InputAction { let built_binary_path = platform::binary_cache_path() .join(if release_mode { "release" } else { "debug" }) - .join(&self.bin_name); + .join({ + #[cfg(windows)] + { + format!("{}.exe", &self.bin_name) + } + #[cfg(not(windows))] + { + &self.bin_name + } + }); let manifest_path = self.manifest_path(); diff --git a/tests/data/script-using-env.rs b/tests/data/script-using-env.rs new file mode 100644 index 0000000..3a09108 --- /dev/null +++ b/tests/data/script-using-env.rs @@ -0,0 +1,4 @@ +let msg = option_env!("_RUST_SCRIPT_TEST_MESSAGE").unwrap_or("undefined"); + +println!("--output--"); +println!("msg = {}", msg); \ No newline at end of file diff --git a/tests/tests/script.rs b/tests/tests/script.rs index f25690a..bdfa523 100644 --- a/tests/tests/script.rs +++ b/tests/tests/script.rs @@ -186,6 +186,34 @@ fn test_whitespace_before_main() { .unwrap() } +#[test] +fn test_force_rebuild() { + for option in ["-f", "--force"] { + std::env::remove_var("_RUST_SCRIPT_TEST_MESSAGE"); + + let script_path = "tests/data/script-using-env.rs"; + let out = rust_script!(option, script_path).unwrap(); + scan!(out.stdout_output(); + ("msg = undefined") => () + ) + .unwrap(); + + std::env::set_var("_RUST_SCRIPT_TEST_MESSAGE", "hello"); + + let out = rust_script!(script_path).unwrap(); + scan!(out.stdout_output(); + ("msg = undefined") => () + ) + .unwrap(); + + let out = rust_script!(option, script_path).unwrap(); + scan!(out.stdout_output(); + ("msg = hello") => () + ) + .unwrap(); + } +} + #[test] #[ignore] fn test_stable_toolchain() {