Document NINJA_ENV usage and restore via OsString#120
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR enhances the documentation for NINJA_ENV by clarifying its usage scope and adding a doctest, and refactors tests to capture and restore environment variables using OsString for more robust handling. Sequence diagram for capturing and restoring NINJA_ENV in testssequenceDiagram
participant Test as Test Function
participant Env as std::env
Test->>Env: var_os(NINJA_ENV) // capture as OsString
Test->>Env: set_var(NINJA_ENV, new_value)
Test->>Env: remove_var(NINJA_ENV)
Test->>Env: set_var(NINJA_ENV, original_value) // restore
Class diagram for NINJA_ENV constant and its usageclassDiagram
class ninja_env {
<<constant>>
NINJA_ENV : &str = "NETSUKE_NINJA"
}
class std_env {
set_var(key: &str, value: &str)
var(key: &str) -> Result<String, VarError>
remove_var(key: &str)
}
ninja_env <.. std_env : uses
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
5e02eac
into
codex/add-envlock-and-mockable-env-for-ninja_env
There was a problem hiding this comment.
Hey there - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- Add behavioural and unit tests for the new or changed feature documentation example. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tests/ninja_env_tests.rs:33` </location>
<code_context>
#[rstest]
#[serial]
fn override_ninja_env_unset_removes_variable() {
- let before = std::env::var(NINJA_ENV).ok();
+ let before = std::env::var_os(NINJA_ENV);
{
let _lock = EnvLock::acquire();
</code_context>
<issue_to_address>
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.
</issue_to_address>
### Comment 2
<location> `tests/ninja_env_tests.rs:50` </location>
<code_context>
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());
+ assert!(std::env::var_os(NINJA_ENV).is_none());
// Restore original global state for isolation
</code_context>
<issue_to_address>
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.
</issue_to_address>
### Comment 3
<location> `ninja_env/src/lib.rs:8` </location>
<code_context>
/// Environment variable override for the Ninja executable.
+///
+/// # Examples
+///
+/// ```
</code_context>
<issue_to_address>
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.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| #[rstest] | ||
| #[serial] | ||
| fn override_ninja_env_unset_removes_variable() { | ||
| let before = std::env::var(NINJA_ENV).ok(); |
There was a problem hiding this comment.
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 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()); |
There was a problem hiding this comment.
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.
|
|
||
| /// Environment variable override for the Ninja executable. | ||
| /// | ||
| /// # Examples |
There was a problem hiding this comment.
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.
* Add guard for NINJA_ENV overrides * Quote NINJA_ENV in doc comment * Centralise NINJA_ENV and cover unset restoration * Remove manual NINJA_ENV cleanup in tests * Add crate for shared NINJA_ENV constant * Scope EnvLock in NINJA_ENV tests (#117) * Apply review suggestions for ninja env crate (#118) * Document NINJA_ENV and restore via OsString (#120) * Refine ninja env docs and tests (#121)
Summary
OsStringin testsTesting
make fmtmake lintmake testhttps://chatgpt.com/codex/tasks/task_e_689f064599b08322addd207d669a40a6
Summary by Sourcery
Enhance NINJA_ENV documentation with a doctest and update tests to capture and restore the environment variable using OsString
Enhancements:
Tests: