-
Notifications
You must be signed in to change notification settings - Fork 0
Handle manifest path in process tests #56
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
3ce4b9b
d483a9c
f030702
9dae062
6595f29
4151697
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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ use cucumber::{given, then, when}; | |
| use netsuke::runner::{self, BuildTargets}; | ||
| use std::fs; | ||
| use std::path::{Path, PathBuf}; | ||
| use tempfile::TempDir; | ||
| use tempfile::{NamedTempFile, TempDir}; | ||
|
|
||
| /// Installs a test-specific ninja binary and updates the `PATH`. | ||
| #[expect( | ||
|
|
@@ -79,6 +79,29 @@ fn build_dir_exists(world: &mut CliWorld) { | |
| )] | ||
| #[when("the ninja process is run")] | ||
| fn run(world: &mut CliWorld) { | ||
| let dir = world.temp.as_ref().expect("temp dir"); | ||
| let manifest_path = { | ||
| let cli = world.cli.as_ref().expect("cli"); | ||
| if cli.file.is_absolute() { | ||
| cli.file.clone() | ||
| } else { | ||
| dir.path().join(&cli.file) | ||
| } | ||
| }; | ||
|
|
||
| if !manifest_path.exists() { | ||
| let mut file = | ||
| NamedTempFile::new_in(dir.path()).expect("Failed to create temporary manifest file"); | ||
| support::write_manifest(&mut file).expect("Failed to write manifest content"); | ||
| file.persist(&manifest_path) | ||
| .expect("Failed to persist manifest file"); | ||
|
Comment on lines
+96
to
+97
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. Replace Using - file.persist(&manifest_path)
- .expect("Failed to persist manifest file");
+ drop(file);
+ std::fs::write(&manifest_path, &manifest_content)
+ .expect("Failed to write manifest file");Alternatively, use - file.persist(&manifest_path)
- .expect("Failed to persist manifest file");
+ file.persist_noclobber(&manifest_path)
+ .expect("Failed to persist manifest file");
🤖 Prompt for AI Agents
Owner
Author
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. @coderabbitai Please create a new GitHub issue for this
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. 🧩 Analysis chain@leynos I've created a GitHub issue to track the NamedTempFile::persist() safety concern. The issue includes the technical details, suggested solutions, and references back to this PR and comment for proper context. 🏁 Script executed: Length of output: 1191 @leynos Perfect! I've successfully created GitHub issue #58 to track this improvement. The issue is available at: #58 The issue includes:
This will help ensure the improvement doesn't get lost and can be addressed in a future PR. 🧬 Code Graph Analysis ResultsRelevant snippets from
|
||
| } | ||
|
|
||
| { | ||
| let cli = world.cli.as_mut().expect("cli"); | ||
| cli.file.clone_from(&manifest_path); | ||
| } | ||
|
|
||
| let cli = world.cli.as_ref().expect("cli"); | ||
| let program = if let Some(ninja) = &world.ninja { | ||
| Path::new(ninja) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| //! Test utilities for process management and log capture. | ||
| //! Test utilities for process management. | ||
|
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. ❌ New issue: Code Duplication
Owner
Author
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. @coderabbitai Please create a new GitHub issue for this
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. 🧩 Analysis chainI'll create a GitHub issue to track the code duplication identified by the CodeScene analysis. @leynos I've created a GitHub issue to track the code duplication identified by CodeScene. The issue documents the duplication between 🏁 Script executed: Length of output: 935 @leynos Perfect! I've successfully created GitHub issue #63 to track the code duplication in the test support utilities. The issue documents the duplication between Issue URL: #63 The issue has been assigned to you and includes a suggested approach for refactoring the common functionality into a shared helper function. 🧬 Code Graph Analysis ResultsPossibly relevant snippets from
|
||
| //! | ||
| //! This module provides helpers for creating fake executables and | ||
| //! generating minimal manifests used in behavioural tests. | ||
|
|
||
| use std::fs::{self, File}; | ||
| use std::io::{self, Write}; | ||
|
|
@@ -134,3 +137,23 @@ pub fn fake_ninja_pwd() -> (TempDir, PathBuf) { | |
| } | ||
| (dir, path) | ||
| } | ||
|
|
||
| /// Write a minimal manifest to `file`. | ||
| /// | ||
| /// The manifest declares a single `hello` target that prints a greeting. | ||
| /// This must be `allow` as `expect` will trigger an unfulfilled warning | ||
| /// despite the lint violation arising. | ||
| #[allow(dead_code, reason = "shared test utility not used in all crates")] | ||
|
leynos marked this conversation as resolved.
|
||
| pub fn write_manifest(file: &mut impl Write) -> io::Result<()> { | ||
| writeln!( | ||
| file, | ||
| concat!( | ||
| "netsuke_version: \"1.0.0\"\n", | ||
| "targets:\n", | ||
| " - name: hello\n", | ||
| " recipe:\n", | ||
| " kind: command\n", | ||
| " command: \"echo hi\"\n" | ||
| ), | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.