Allow justfile to be named Justfile
(#19)
Priority is given to `justfile` to match the behavior of GNU make.
This commit is contained in:
parent
adef254b23
commit
9a742e6336
@ -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
|
||||||
|
14
src/app.rs
14
src/app.rs
@ -92,15 +92,21 @@ 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"] {
|
||||||
|
match fs::metadata(candidate) {
|
||||||
|
Ok(metadata) => if metadata.is_file() {
|
||||||
|
name = *candidate;
|
||||||
|
break 'outer;
|
||||||
|
},
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
if error.kind() != io::ErrorKind::NotFound {
|
if error.kind() != io::ErrorKind::NotFound {
|
||||||
die!("Error fetching justfile metadata: {}", error)
|
die!("Error fetching justfile metadata: {}", error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match env::current_dir() {
|
match env::current_dir() {
|
||||||
Ok(pathbuf) => if pathbuf.as_os_str() == "/" { die!("No justfile found."); },
|
Ok(pathbuf) => if pathbuf.as_os_str() == "/" { die!("No justfile found."); },
|
||||||
@ -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));
|
||||||
|
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user