2017-11-30 10:38:44 -08:00
|
|
|
use executable_path::executable_path;
|
2018-12-08 14:29:41 -08:00
|
|
|
use std::{fs, path, process, str};
|
2019-07-06 20:55:46 -07:00
|
|
|
|
|
|
|
fn tempdir() -> tempfile::TempDir {
|
|
|
|
tempfile::Builder::new()
|
|
|
|
.prefix("just-test-tempdir")
|
|
|
|
.tempdir()
|
|
|
|
.expect("failed to create temporary directory")
|
|
|
|
}
|
2017-04-22 16:15:15 -07:00
|
|
|
|
|
|
|
fn search_test<P: AsRef<path::Path>>(path: P, args: &[&str]) {
|
2017-11-30 10:38:44 -08:00
|
|
|
let binary = executable_path("just");
|
2017-05-07 19:48:07 -07:00
|
|
|
|
2017-04-22 16:15:15 -07:00
|
|
|
let output = process::Command::new(binary)
|
|
|
|
.current_dir(path)
|
|
|
|
.args(args)
|
|
|
|
.output()
|
|
|
|
.expect("just invocation failed");
|
|
|
|
|
|
|
|
assert_eq!(output.status.code().unwrap(), 0);
|
|
|
|
|
|
|
|
let stdout = str::from_utf8(&output.stdout).unwrap();
|
|
|
|
assert_eq!(stdout, "ok\n");
|
|
|
|
|
|
|
|
let stderr = str::from_utf8(&output.stderr).unwrap();
|
|
|
|
assert_eq!(stderr, "echo ok\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_justfile_search() {
|
2019-07-06 20:55:46 -07:00
|
|
|
let tmp = tempdir();
|
2017-04-22 16:15:15 -07:00
|
|
|
let mut path = tmp.path().to_path_buf();
|
|
|
|
path.push("justfile");
|
2019-04-16 22:06:28 -07:00
|
|
|
fs::write(&path, "default:\n\techo ok").unwrap();
|
2017-04-22 16:15:15 -07:00
|
|
|
path.pop();
|
|
|
|
|
|
|
|
path.push("a");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
path.push("b");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
path.push("c");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
path.push("d");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
|
|
|
|
search_test(path, &[]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_capitalized_justfile_search() {
|
2019-07-06 20:55:46 -07:00
|
|
|
let tmp = tempdir();
|
2017-04-22 16:15:15 -07:00
|
|
|
let mut path = tmp.path().to_path_buf();
|
|
|
|
path.push("Justfile");
|
2019-04-16 22:06:28 -07:00
|
|
|
fs::write(&path, "default:\n\techo ok").unwrap();
|
2017-04-22 16:15:15 -07:00
|
|
|
path.pop();
|
|
|
|
|
|
|
|
path.push("a");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
path.push("b");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
path.push("c");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
path.push("d");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
|
|
|
|
search_test(path, &[]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_upwards_path_argument() {
|
2019-07-06 20:55:46 -07:00
|
|
|
let tmp = tempdir();
|
2017-04-22 16:15:15 -07:00
|
|
|
let mut path = tmp.path().to_path_buf();
|
|
|
|
path.push("justfile");
|
2019-04-16 22:06:28 -07:00
|
|
|
fs::write(&path, "default:\n\techo ok").unwrap();
|
2017-04-22 16:15:15 -07:00
|
|
|
path.pop();
|
|
|
|
|
|
|
|
path.push("a");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
|
|
|
|
path.push("justfile");
|
2019-04-16 22:06:28 -07:00
|
|
|
fs::write(&path, "default:\n\techo bad").unwrap();
|
2017-04-22 16:15:15 -07:00
|
|
|
path.pop();
|
|
|
|
|
|
|
|
search_test(&path, &["../"]);
|
|
|
|
search_test(&path, &["../default"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_downwards_path_argument() {
|
2019-07-06 20:55:46 -07:00
|
|
|
let tmp = tempdir();
|
2017-04-22 16:15:15 -07:00
|
|
|
let mut path = tmp.path().to_path_buf();
|
|
|
|
path.push("justfile");
|
2019-04-16 22:06:28 -07:00
|
|
|
fs::write(&path, "default:\n\techo bad").unwrap();
|
2017-04-22 16:15:15 -07:00
|
|
|
path.pop();
|
|
|
|
|
|
|
|
path.push("a");
|
|
|
|
fs::create_dir(&path).expect("test justfile search: failed to create intermediary directory");
|
|
|
|
|
|
|
|
path.push("justfile");
|
2019-04-16 22:06:28 -07:00
|
|
|
fs::write(&path, "default:\n\techo ok").unwrap();
|
2017-04-22 16:15:15 -07:00
|
|
|
path.pop();
|
|
|
|
path.pop();
|
|
|
|
|
|
|
|
search_test(&path, &["a/"]);
|
|
|
|
search_test(&path, &["a/default"]);
|
|
|
|
search_test(&path, &["./a/"]);
|
|
|
|
search_test(&path, &["./a/default"]);
|
|
|
|
search_test(&path, &["./a/"]);
|
|
|
|
search_test(&path, &["./a/default"]);
|
|
|
|
}
|