mirror of
https://github.com/casey/just.git
synced 2024-11-27 09:15:08 +03:00
11c253a213
Adds an `unindent()` function that strips common leading indentation from strings, and apply it to integration test case strings, so that they can be written in a more readable style.
69 lines
1.6 KiB
Rust
69 lines
1.6 KiB
Rust
mod testing;
|
|
|
|
use std::{error::Error, fs, process::Command};
|
|
|
|
use executable_path::executable_path;
|
|
|
|
use testing::tempdir;
|
|
|
|
/// Test that just runs with the correct working directory when invoked with
|
|
/// `--justfile` but not `--working-directory`
|
|
#[test]
|
|
fn justfile_without_working_directory() -> Result<(), Box<dyn Error>> {
|
|
let tmp = tempdir();
|
|
let justfile = tmp.path().join("justfile");
|
|
let data = tmp.path().join("data");
|
|
fs::write(
|
|
&justfile,
|
|
"foo = `cat data`\ndefault:\n echo {{foo}}\n cat data",
|
|
)?;
|
|
fs::write(&data, "found it")?;
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.arg("--justfile")
|
|
.arg(&justfile)
|
|
.output()?;
|
|
|
|
if !output.status.success() {
|
|
panic!()
|
|
}
|
|
|
|
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(stdout, "found it\nfound it");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Test that just invokes commands from the directory in which the justfile is found
|
|
#[test]
|
|
fn change_working_directory_to_justfile_parent() -> Result<(), Box<dyn Error>> {
|
|
let tmp = tempdir();
|
|
|
|
let justfile = tmp.path().join("justfile");
|
|
fs::write(
|
|
&justfile,
|
|
"foo = `cat data`\ndefault:\n echo {{foo}}\n cat data",
|
|
)?;
|
|
|
|
let data = tmp.path().join("data");
|
|
fs::write(&data, "found it")?;
|
|
|
|
let subdir = tmp.path().join("subdir");
|
|
fs::create_dir(&subdir)?;
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.current_dir(subdir)
|
|
.output()?;
|
|
|
|
if !output.status.success() {
|
|
panic!("just invocation failed: {}", output.status)
|
|
}
|
|
|
|
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(stdout, "found it\nfound it");
|
|
|
|
Ok(())
|
|
}
|