just/tests/working_directory.rs
Casey Rodarmor 11c253a213
Add unindent() for nicer integration test strings (#481)
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.
2019-10-07 00:32:51 -07:00

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(())
}