mirror of
https://github.com/casey/just.git
synced 2024-11-26 23:27:26 +03:00
1b0fafea75
This commit adds a `Loader` type, which can be used to load multiple source strings. This was done to support the work on modules, but coincidentally enabled consolidating errors, since now `Config::run` can take a `&Loader`, and in the event of an error, return and `Error` that borrows from loaded strings. Multiple error types have been consolidated, and a bunch of ad-hoc error printing was removed.
191 lines
3.5 KiB
Rust
191 lines
3.5 KiB
Rust
use crate::common::*;
|
|
|
|
const EXPECTED: &str = "default:\n\techo 'Hello, world!'\n";
|
|
|
|
#[test]
|
|
fn current_dir() {
|
|
let tmp = tempdir();
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.current_dir(tmp.path())
|
|
.arg("--init")
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert_eq!(
|
|
fs::read_to_string(tmp.path().join("justfile")).unwrap(),
|
|
EXPECTED
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn exists() {
|
|
let tempdir = Test::new()
|
|
.no_justfile()
|
|
.arg("--init")
|
|
.stderr_regex("Wrote justfile to `.*`\n")
|
|
.run();
|
|
|
|
Test::with_tempdir(tempdir)
|
|
.no_justfile()
|
|
.arg("--init")
|
|
.status(EXIT_FAILURE)
|
|
.stderr_regex("error: Justfile `.*` already exists\n")
|
|
.run();
|
|
}
|
|
|
|
#[test]
|
|
fn write_error() {
|
|
let test = Test::new();
|
|
|
|
let justfile_path = test.justfile_path();
|
|
|
|
fs::create_dir(&justfile_path).unwrap();
|
|
|
|
test
|
|
.no_justfile()
|
|
.args(&["--init"])
|
|
.status(EXIT_FAILURE)
|
|
.stderr_regex(if cfg!(windows) {
|
|
r"error: Failed to write justfile to `.*`: Access is denied. \(os error 5\)\n"
|
|
} else {
|
|
r"error: Failed to write justfile to `.*`: Is a directory \(os error 21\)\n"
|
|
})
|
|
.run();
|
|
}
|
|
|
|
#[test]
|
|
fn invocation_directory() {
|
|
let tmp = temptree! {
|
|
".git": {},
|
|
};
|
|
|
|
let test = Test::with_tempdir(tmp);
|
|
|
|
let justfile_path = test.justfile_path();
|
|
|
|
let _tmp = test
|
|
.no_justfile()
|
|
.stderr_regex("Wrote justfile to `.*`\n")
|
|
.arg("--init")
|
|
.run();
|
|
|
|
assert_eq!(fs::read_to_string(justfile_path).unwrap(), EXPECTED);
|
|
}
|
|
|
|
#[test]
|
|
fn parent_dir() {
|
|
let tmp = temptree! {
|
|
".git": {},
|
|
sub: {},
|
|
};
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.current_dir(tmp.path().join("sub"))
|
|
.arg("--init")
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert_eq!(
|
|
fs::read_to_string(tmp.path().join("justfile")).unwrap(),
|
|
EXPECTED
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn alternate_marker() {
|
|
let tmp = temptree! {
|
|
"_darcs": {},
|
|
};
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.current_dir(tmp.path())
|
|
.arg("--init")
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert_eq!(
|
|
fs::read_to_string(tmp.path().join("justfile")).unwrap(),
|
|
EXPECTED
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn search_directory() {
|
|
let tmp = temptree! {
|
|
sub: {
|
|
".git": {},
|
|
},
|
|
};
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.current_dir(tmp.path())
|
|
.arg("--init")
|
|
.arg("sub/")
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert_eq!(
|
|
fs::read_to_string(tmp.path().join("sub/justfile")).unwrap(),
|
|
EXPECTED
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn justfile() {
|
|
let tmp = temptree! {
|
|
sub: {
|
|
".git": {},
|
|
},
|
|
};
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.current_dir(tmp.path().join("sub"))
|
|
.arg("--init")
|
|
.arg("--justfile")
|
|
.arg(tmp.path().join("justfile"))
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert_eq!(
|
|
fs::read_to_string(tmp.path().join("justfile")).unwrap(),
|
|
EXPECTED
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn justfile_and_working_directory() {
|
|
let tmp = temptree! {
|
|
sub: {
|
|
".git": {},
|
|
},
|
|
};
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
.current_dir(tmp.path().join("sub"))
|
|
.arg("--init")
|
|
.arg("--justfile")
|
|
.arg(tmp.path().join("justfile"))
|
|
.arg("--working-directory")
|
|
.arg("/")
|
|
.output()
|
|
.unwrap();
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert_eq!(
|
|
fs::read_to_string(tmp.path().join("justfile")).unwrap(),
|
|
EXPECTED
|
|
);
|
|
}
|