just/tests/working_directory.rs
Casey Rodarmor 49ab423592
Refactor lexer tests (#498)
- Refactor the lexer tests to be more readable, abandoning the
  previous string-based summary DSL in favor of a more obvious
  sequence of `TokenKinds` with optional lexemes. The new tests
  also test that token lexemes are correct.

- Move duplicated `unindent` function into a shared crate,
  `test-utilities`. This new versionless dev-dependency will
  prevent publishing to crates.io, at least until rust-lang/cargo/pull/7333
  makes it into stable. If we publish a new version before then,
  test-utilities will need to be published to crates.io, so we can depend
  on it by version.
2019-10-17 20:04:54 -07:00

66 lines
1.6 KiB
Rust

use std::{error::Error, fs, process::Command};
use executable_path::executable_path;
use test_utilities::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(())
}