Refine ninja env docs and tests#121
Conversation
|
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 (
|
Reviewer's GuideRefined ninja_env documentation and tests by introducing a reusable rstest fixture for the Ninja temp directory, switching to OsString-based environment variable checks, cleaning up comments, and reflowing doc comments and code examples. Sequence diagram for test setup with rstest fixture and OsString environment variablesequenceDiagram
participant TestRunner
participant RstestFixture
participant Env
TestRunner->>RstestFixture: Request ninja_temp_dir
RstestFixture-->>TestRunner: Provide ninja_temp_dir
TestRunner->>Env: Set NINJA_ENV using OsString
TestRunner->>Env: Run test with NINJA_ENV
TestRunner->>Env: Remove NINJA_ENV after test
Class diagram for updated ninja_env test structureclassDiagram
class NinjaEnvTest {
+ninja_temp_dir: PathBuf
+ninja_env_var: OsString
+test_ninja_env()
}
class RstestFixture {
+ninja_temp_dir: PathBuf
}
NinjaEnvTest --> RstestFixture : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
a60869b
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 they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tests/ninja_env_tests.rs:11` </location>
<code_context>
use test_support::{env::override_ninja_env, env_lock::EnvLock};
+#[fixture]
+fn ninja_tmp() -> PathBuf {
+ std::env::temp_dir().join("ninja")
+}
</code_context>
<issue_to_address>
Consider cleaning up the temp directory after tests.
Since 'ninja_tmp' may accumulate files or directories during tests, add cleanup logic to remove the temp directory after each test to maintain test isolation.
Suggested implementation:
```rust
use std::fs;
use std::ops::Deref;
/// Wrapper struct to clean up temp directory after test
pub struct NinjaTmp(PathBuf);
impl Deref for NinjaTmp {
type Target = PathBuf;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Drop for NinjaTmp {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
#[fixture]
fn ninja_tmp() -> NinjaTmp {
let path = std::env::temp_dir().join("ninja");
// Ensure the directory exists for the test
let _ = fs::create_dir_all(&path);
NinjaTmp(path)
}
```
```rust
fn override_ninja_env_sets_and_restores(ninja_tmp: NinjaTmp) {
```
If there are other tests in this file using the `ninja_tmp` fixture, update their signatures to accept `NinjaTmp` instead of `PathBuf`. Also, update any usage of `ninja_tmp` in the test bodies to use `*ninja_tmp` or `ninja_tmp.deref()` if a `PathBuf` is needed.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| use test_support::{env::override_ninja_env, env_lock::EnvLock}; | ||
|
|
||
| #[fixture] | ||
| fn ninja_tmp() -> PathBuf { |
There was a problem hiding this comment.
suggestion (testing): Consider cleaning up the temp directory after tests.
Since 'ninja_tmp' may accumulate files or directories during tests, add cleanup logic to remove the temp directory after each test to maintain test isolation.
Suggested implementation:
use std::fs;
use std::ops::Deref;
/// Wrapper struct to clean up temp directory after test
pub struct NinjaTmp(PathBuf);
impl Deref for NinjaTmp {
type Target = PathBuf;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Drop for NinjaTmp {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
#[fixture]
fn ninja_tmp() -> NinjaTmp {
let path = std::env::temp_dir().join("ninja");
// Ensure the directory exists for the test
let _ = fs::create_dir_all(&path);
NinjaTmp(path)
}fn override_ninja_env_sets_and_restores(ninja_tmp: NinjaTmp) {If there are other tests in this file using the ninja_tmp fixture, update their signatures to accept NinjaTmp instead of PathBuf. Also, update any usage of ninja_tmp in the test bodies to use *ninja_tmp or ninja_tmp.deref() if a PathBuf is needed.
* 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
NINJA_ENVwithOsStringand share temp path via rstest fixtureTesting
make fmtmake lintmake testhttps://chatgpt.com/codex/tasks/task_e_689f13d1b0488322ba63228624031770
Summary by Sourcery
Refine ninja_env crate by updating documentation formatting and improving tests for NINJA_ENV override behavior.
Enhancements:
Documentation:
Tests: