-
Notifications
You must be signed in to change notification settings - Fork 0
Promote test support to crate #114
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
Merged
leynos
merged 5 commits into
main
from
codex/promote-tests/support-to-test_support-crate
Aug 13, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1e10a84
Promote test support to crate
leynos 9a6a4da
Format process steps imports
leynos 24b6f28
Harden test_support crate and update tests
leynos d1ef402
Refine fake_ninja helper and update call sites
leynos da4ff81
Serialise NINJA_ENV edits and document PathGuard
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [package] | ||
| name = "test_support" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| rust-version = "1.85.0" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| tempfile = "3.8.0" | ||
| mockable = { version = "0.3", features = ["mock"] } | ||
|
|
||
| [dev-dependencies] | ||
| rstest = "0.18.0" | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| //! Test-support crate for Netsuke. | ||
| //! | ||
| //! This crate provides test-only utilities for: | ||
| //! - creating fake executables for process-related tests | ||
| //! - manipulating PATH safely (PathGuard) | ||
| //! - serialising environment mutation across tests (EnvLock) | ||
| //! | ||
| //! All items are intended for use in tests within this workspace; avoid using | ||
| //! them in production code. | ||
| //! | ||
| //! Platform notes: fake executables are implemented for Unix and Windows. | ||
|
|
||
| pub mod check_ninja; | ||
| pub mod env; | ||
| pub mod env_lock; | ||
| pub mod path_guard; | ||
| /// Re-export of [`PathGuard`] for crate-level ergonomics in tests. | ||
| pub use path_guard::PathGuard; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| use std::fs::{self, File}; | ||
| use std::io::Write; | ||
| use std::path::PathBuf; | ||
| use tempfile::TempDir; | ||
|
|
||
| /// Create a fake Ninja executable that exits with `exit_code`. | ||
| /// | ||
| /// Returns the temporary directory and the path to the executable. | ||
| /// | ||
| /// The returned [`TempDir`] must be kept alive for the executable to remain on | ||
| /// disk. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ```rust,ignore | ||
| /// use test_support::fake_ninja; | ||
| /// | ||
| /// // Create a fake `ninja` that exits with code 1 | ||
| /// let (dir, ninja_path) = fake_ninja(1u8); | ||
| /// | ||
| /// // Prepend `dir.path()` to PATH via your env helper, then spawn `ninja`. | ||
| /// // When `dir` is dropped, the fake executable is removed. | ||
| /// ``` | ||
| pub fn fake_ninja(exit_code: u8) -> (TempDir, PathBuf) { | ||
| let dir = TempDir::new() | ||
| .unwrap_or_else(|e| panic!("fake_ninja: failed to create temporary directory: {e}")); | ||
|
|
||
| #[cfg(unix)] | ||
| let path = dir.path().join("ninja"); | ||
| #[cfg(windows)] | ||
| let path = dir.path().join("ninja.cmd"); | ||
|
|
||
| #[cfg(unix)] | ||
| { | ||
| let mut file = File::create(&path).unwrap_or_else(|e| { | ||
| panic!( | ||
| "fake_ninja: failed to create script {}: {e}", | ||
| path.display() | ||
| ) | ||
| }); | ||
| writeln!(file, "#!/bin/sh\nexit {}", exit_code).unwrap_or_else(|e| { | ||
| panic!("fake_ninja: failed to write script {}: {e}", path.display()) | ||
| }); | ||
| use std::os::unix::fs::PermissionsExt; | ||
| let mut perms = fs::metadata(&path) | ||
| .unwrap_or_else(|e| { | ||
| panic!( | ||
| "fake_ninja: failed to read metadata {}: {e}", | ||
| path.display() | ||
| ) | ||
| }) | ||
| .permissions(); | ||
| perms.set_mode(0o755); | ||
| fs::set_permissions(&path, perms).unwrap_or_else(|e| { | ||
| panic!( | ||
| "fake_ninja: failed to set permissions {}: {e}", | ||
| path.display() | ||
| ) | ||
| }); | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| { | ||
| let mut file = File::create(&path).unwrap_or_else(|e| { | ||
| panic!( | ||
| "fake_ninja: failed to create batch file {}: {e}", | ||
| path.display() | ||
| ) | ||
| }); | ||
| writeln!(file, "@echo off\r\nexit /B {}", exit_code).unwrap_or_else(|e| { | ||
| panic!( | ||
| "fake_ninja: failed to write batch file {}: {e}", | ||
| path.display() | ||
| ) | ||
| }); | ||
| } | ||
|
|
||
| (dir, path) | ||
| } | ||
|
|
||
| // Additional helpers can be added here as the test suite evolves. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.