aefdcea7d0
- Instead of changing the current directory with `env::set_current_dir` to be implicitly inherited by subprocesses, we now use `Command::current_dir` to set it explicitly. This feels much better, since we aren't dependent on the implicit state of the process's current directory. - Subcommand execution is much improved. - Added a ton of tests for config parsing, config execution, working dir, and search dir. - Error messages are improved. Many more will be colored. - The Config is now onwed, instead of borrowing from the arguments and the `clap::ArgMatches` object. This is a huge ergonomic improvement, especially in tests, and I don't think anyone will notice. - `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order, matching git, which I think is what most people will expect. - Added a cute `tmptree!{}` macro, for creating temporary directories populated with directories and files for tests. - Admitted that grammer is LL(k) and I don't know what `k` is.
124 lines
2.4 KiB
Rust
124 lines
2.4 KiB
Rust
use executable_path::executable_path;
|
|
use std::{path, process, str};
|
|
|
|
use test_utilities::tmptree;
|
|
|
|
fn search_test<P: AsRef<path::Path>>(path: P, args: &[&str]) {
|
|
let binary = executable_path("just");
|
|
|
|
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() {
|
|
let tmp = tmptree! {
|
|
justfile: "default:\n\techo ok",
|
|
a: {
|
|
b: {
|
|
c: {
|
|
d: {},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
search_test(tmp.path().join("a/b/c/d"), &[]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_capitalized_justfile_search() {
|
|
let tmp = tmptree! {
|
|
Justfile: "default:\n\techo ok",
|
|
a: {
|
|
b: {
|
|
c: {
|
|
d: {},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
search_test(tmp.path().join("a/b/c/d"), &[]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_upwards_path_argument() {
|
|
let tmp = tmptree! {
|
|
justfile: "default:\n\techo ok",
|
|
a: {
|
|
justfile: "default:\n\techo bad",
|
|
},
|
|
};
|
|
|
|
search_test(&tmp.path().join("a"), &["../"]);
|
|
search_test(&tmp.path().join("a"), &["../default"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_downwards_path_argument() {
|
|
let tmp = tmptree! {
|
|
justfile: "default:\n\techo bad",
|
|
a: {
|
|
justfile: "default:\n\techo ok",
|
|
},
|
|
};
|
|
|
|
let path = tmp.path();
|
|
|
|
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"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_upwards_multiple_path_argument() {
|
|
let tmp = tmptree! {
|
|
justfile: "default:\n\techo ok",
|
|
a: {
|
|
b: {
|
|
justfile: "default:\n\techo bad",
|
|
},
|
|
},
|
|
};
|
|
|
|
let path = tmp.path().join("a").join("b");
|
|
search_test(&path, &["../../"]);
|
|
search_test(&path, &["../../default"]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_downwards_multiple_path_argument() {
|
|
let tmp = tmptree! {
|
|
justfile: "default:\n\techo bad",
|
|
a: {
|
|
b: {
|
|
justfile: "default:\n\techo ok",
|
|
},
|
|
},
|
|
};
|
|
|
|
let path = tmp.path();
|
|
|
|
search_test(&path, &["a/b/"]);
|
|
search_test(&path, &["a/b/default"]);
|
|
search_test(&path, &["./a/b/"]);
|
|
search_test(&path, &["./a/b/default"]);
|
|
search_test(&path, &["./a/b/"]);
|
|
search_test(&path, &["./a/b/default"]);
|
|
}
|