-
Notifications
You must be signed in to change notification settings - Fork 0
Document NINJA_ENV usage and restore via OsString #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,16 @@ | ||
| #![forbid(unsafe_code)] | ||
|
|
||
| //! Shared environment constants for netsuke tests. | ||
| //! Shared environment constants used across netsuke crates (library, tests, | ||
| //! and helpers). | ||
|
|
||
| /// Environment variable override for the Ninja executable. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use ninja_env::NINJA_ENV; | ||
| /// std::env::set_var(NINJA_ENV, "/usr/bin/ninja"); | ||
| /// assert_eq!(std::env::var(NINJA_ENV).unwrap(), "/usr/bin/ninja"); | ||
| /// std::env::remove_var(NINJA_ENV); | ||
| /// ``` | ||
| pub const NINJA_ENV: &str = "NETSUKE_NINJA"; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ fn override_ninja_env_sets_and_restores() { | |
| #[rstest] | ||
| #[serial] | ||
| fn override_ninja_env_unset_removes_variable() { | ||
| let before = std::env::var(NINJA_ENV).ok(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Good update to use var_os for capturing environment variable. Consider adding a test where NINJA_ENV is set to a non-UTF8 value to confirm correct handling. |
||
| let before = std::env::var_os(NINJA_ENV); | ||
| { | ||
| let _lock = EnvLock::acquire(); | ||
| // SAFETY: `EnvLock` serialises mutations during setup. | ||
|
|
@@ -47,7 +47,7 @@ fn override_ninja_env_unset_removes_variable() { | |
| let after = std::env::var(NINJA_ENV).expect("NINJA_ENV should be set after override"); | ||
| assert_eq!(after, target.to_string_lossy().as_ref()); | ||
| } | ||
| assert!(std::env::var(NINJA_ENV).is_err()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Assertion updated to use var_os for checking unset variable. Consider adding an assertion to verify that the environment variable is restored to its original value after the test, ensuring proper test isolation. |
||
| assert!(std::env::var_os(NINJA_ENV).is_none()); | ||
|
|
||
| // Restore original global state for isolation | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (review_instructions): Add behavioural and unit tests for the new or changed feature documentation example.
You have added an example for using the NINJA_ENV constant, but there are no corresponding behavioural or unit tests in the codebase to verify this functionality. Add tests that set, check, and remove the environment variable as shown in the example to ensure the feature works as documented.
Review instructions:
Path patterns:
**/*Instructions:
For any new feature or change to an existing feature, both behavioural and unit tests are required.