From 8a0480358071c2024aca6e2506d9a1ac43eb0211 Mon Sep 17 00:00:00 2001 From: la10736 Date: Sun, 29 Sep 2024 11:35:01 +0200 Subject: [PATCH] Removed the useless build rerun variable and add some notes about using build.rs. --- rstest/src/lib.rs | 17 +++++++++++++++-- rstest_macros/src/parse/rstest/files.rs | 3 --- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/rstest/src/lib.rs b/rstest/src/lib.rs index 1a448b1..d394186 100644 --- a/rstest/src/lib.rs +++ b/rstest/src/lib.rs @@ -980,7 +980,7 @@ pub use rstest_macros::fixture; /// `valid_call.yaml` in the folder `../test_cases` (from your crate root) a test name could be /// `path_1__UP_test_cases_valid_call_yaml`. /// -/// Sometimes you want to change the base path for the test files. You can do that by using +/// If you want to change the base path for the test files. You can do that by using /// `#[base_dir = "..."]` attribute. The `base_dir` is resolved relative to the crate root /// (similar to the `files` attribute without `base_dir`). If you want to use an absolute /// path you can use `#[base_dir = "/path/to/your/files"]`. @@ -989,7 +989,20 @@ pub use rstest_macros::fixture; /// `$VAR` or `${VAR}`. If the environment variable is not set, the attribute will cause /// an error. This can be ignored using the `#[ignore_missing_env_vars]` attribute. A /// default value can be provided for the environment variable using the syntax -/// `${VAR:-default}` (similar to bash). +/// `${VAR:-default}` (similar to bash). This can be really useful when you want to override +/// the cargo root on some environments: use `#[base_dir = "BASE_TEST_DIR:-"]` do the trick. +/// +/// Finally, often you would to recompile tests sources when file the folders or the +/// environment variables changed. In this case you should provide a `build.rs` script file +/// that tell to the compiler what to look in order to recompile the tests. For instance +/// follow a simple example: +/// +/// ``` +/// pub fn main() { +/// println!("cargo::rerun-if-changed=tests/resources"); +/// println!("cargo::rerun-if-env-changed=BASE_TEST_DIR"); +/// } +/// ``` /// /// ## Use Parametrize definition in more tests /// diff --git a/rstest_macros/src/parse/rstest/files.rs b/rstest_macros/src/parse/rstest/files.rs index c6105d1..8cedf8f 100644 --- a/rstest_macros/src/parse/rstest/files.rs +++ b/rstest_macros/src/parse/rstest/files.rs @@ -86,9 +86,6 @@ impl FilesGlobReferences { } }; - // Make sure cargo would rerun if the value of this environment variable changes. - println!("cargo::rerun-if-env-changed={var_name}"); - result.push_str(&haystack[last_match..match_all.start()]); result.push_str(&replacement); last_match = match_all.end();