Allow justfile to be named Justfile (#19)

Priority is given to `justfile` to match the behavior of GNU make.
This commit is contained in:
Casey Rodarmor 2016-11-05 01:25:36 -07:00 committed by GitHub
parent adef254b23
commit 9a742e6336
3 changed files with 108 additions and 11 deletions

View File

@ -5,7 +5,7 @@ just
`just` is a handy way to save and run commands. `just` is a handy way to save and run commands.
Commands are stored in a file called `justfile` with syntax inspired by `make`: Commands are stored in a file called `justfile` or `Justfile` with syntax inspired by `make`:
```make ```make
test-all: build test-all: build

View File

@ -92,12 +92,18 @@ pub fn app() {
die!("Error changing directory to {}: {}", directory, error); die!("Error changing directory to {}: {}", directory, error);
} }
} else { } else {
loop { let name;
match fs::metadata("justfile") { 'outer: loop {
Ok(metadata) => if metadata.is_file() { break; }, for candidate in &["justfile", "Justfile"] {
Err(error) => { match fs::metadata(candidate) {
if error.kind() != io::ErrorKind::NotFound { Ok(metadata) => if metadata.is_file() {
die!("Error fetching justfile metadata: {}", error) name = *candidate;
break 'outer;
},
Err(error) => {
if error.kind() != io::ErrorKind::NotFound {
die!("Error fetching justfile metadata: {}", error)
}
} }
} }
} }
@ -112,7 +118,7 @@ pub fn app() {
} }
} }
text = fs::File::open("justfile") text = fs::File::open(name)
.unwrap_or_else(|error| die!("Error opening justfile: {}", error)) .unwrap_or_else(|error| die!("Error opening justfile: {}", error))
.slurp() .slurp()
.unwrap_or_else(|error| die!("Error reading justfile: {}", error)); .unwrap_or_else(|error| die!("Error reading justfile: {}", error));

View File

@ -3,7 +3,7 @@ extern crate brev;
extern crate regex; extern crate regex;
use tempdir::TempDir; use tempdir::TempDir;
use super::std::process::Command; use super::std::{fs, path, process};
fn integration_test( fn integration_test(
args: &[&str], args: &[&str],
@ -13,13 +13,13 @@ fn integration_test(
expected_stderr: &str, expected_stderr: &str,
) { ) {
let tmp = TempDir::new("just-integration") let tmp = TempDir::new("just-integration")
.unwrap_or_else(|err| panic!("tmpdir: failed to create temporary directory: {}", err)); .unwrap_or_else(|err| panic!("integration test: failed to create temporary directory: {}", err));
let mut path = tmp.path().to_path_buf(); let mut path = tmp.path().to_path_buf();
path.push("justfile"); path.push("justfile");
brev::dump(path, justfile); brev::dump(path, justfile);
let mut binary = super::std::env::current_dir().unwrap(); let mut binary = super::std::env::current_dir().unwrap();
binary.push("./target/debug/just"); binary.push("./target/debug/just");
let output = Command::new(binary) let output = process::Command::new(binary)
.current_dir(tmp.path()) .current_dir(tmp.path())
.args(args) .args(args)
.output() .output()
@ -50,6 +50,97 @@ fn integration_test(
} }
} }
fn search_test<P: AsRef<path::Path>>(path: P) {
let mut binary = super::std::env::current_dir().unwrap();
binary.push("./target/debug/just");
let output = process::Command::new(binary)
.current_dir(path)
.output()
.expect("just invocation failed");
assert_eq!(output.status.code().unwrap(), 0);
let stdout = super::std::str::from_utf8(&output.stdout).unwrap();
assert_eq!(stdout, "ok\n");
let stderr = super::std::str::from_utf8(&output.stderr).unwrap();
assert_eq!(stderr, "echo ok\n");
}
#[test]
fn test_justfile_search() {
let tmp = TempDir::new("just-test-justfile-search")
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("justfile");
brev::dump(&path, "default:\n\techo ok");
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() {
let tmp = TempDir::new("just-test-justfile-search")
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("Justfile");
brev::dump(&path, "default:\n\techo ok");
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_capitalization_priority() {
let tmp = TempDir::new("just-test-justfile-search")
.expect("test justfile search: failed to create temporary directory");
let mut path = tmp.path().to_path_buf();
path.push("justfile");
brev::dump(&path, "default:\n\techo ok");
path.pop();
path.push("Justfile");
brev::dump(&path, "default:\n\techo fail");
path.pop();
// if we see "default\n\techo fail" in `justfile` then we're running
// in a case insensitive filesystem, so just bail
path.push("justfile");
if brev::slurp(&path) == "default:\n\techo fail" {
return;
}
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] #[test]
fn default() { fn default() {
integration_test( integration_test(