diff --git a/tests/steps/process_steps.rs b/tests/steps/process_steps.rs index be67517a..7edbc961 100644 --- a/tests/steps/process_steps.rs +++ b/tests/steps/process_steps.rs @@ -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"); + } + + { + 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) diff --git a/tests/support/mod.rs b/tests/support/mod.rs index bd051cd2..caba6283 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -1,4 +1,7 @@ -//! Test utilities for process management and log capture. +//! Test utilities for process management. +//! +//! 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")] +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" + ), + ) +}