2022-06-19 07:56:31 +03:00
|
|
|
use super::*;
|
2019-11-20 10:07:44 +03:00
|
|
|
|
2022-02-23 22:47:43 +03:00
|
|
|
const EXPECTED: &str = "default:\n echo 'Hello, world!'\n";
|
2019-11-20 10:07:44 +03:00
|
|
|
|
|
|
|
#[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() {
|
2023-01-13 22:03:14 +03:00
|
|
|
let output = Test::new()
|
2021-07-26 11:26:06 +03:00
|
|
|
.no_justfile()
|
2019-11-20 10:07:44 +03:00
|
|
|
.arg("--init")
|
2021-07-26 11:26:06 +03:00
|
|
|
.stderr_regex("Wrote justfile to `.*`\n")
|
|
|
|
.run();
|
2019-11-20 10:07:44 +03:00
|
|
|
|
2023-01-13 22:03:14 +03:00
|
|
|
Test::with_tempdir(output.tempdir)
|
2021-07-26 11:26:06 +03:00
|
|
|
.no_justfile()
|
2019-11-20 10:07:44 +03:00
|
|
|
.arg("--init")
|
2021-07-26 11:26:06 +03:00
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr_regex("error: Justfile `.*` already exists\n")
|
|
|
|
.run();
|
|
|
|
}
|
2019-11-20 10:07:44 +03:00
|
|
|
|
2021-07-26 11:26:06 +03:00
|
|
|
#[test]
|
|
|
|
fn write_error() {
|
|
|
|
let test = Test::new();
|
|
|
|
|
|
|
|
let justfile_path = test.justfile_path();
|
|
|
|
|
2022-12-16 03:53:21 +03:00
|
|
|
fs::create_dir(justfile_path).unwrap();
|
2021-07-26 11:26:06 +03:00
|
|
|
|
|
|
|
test
|
|
|
|
.no_justfile()
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["--init"])
|
2021-07-26 11:26:06 +03:00
|
|
|
.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();
|
2019-11-20 10:07:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invocation_directory() {
|
2021-07-04 00:26:59 +03:00
|
|
|
let tmp = temptree! {
|
2019-11-20 10:07:44 +03:00
|
|
|
".git": {},
|
|
|
|
};
|
|
|
|
|
2021-07-26 11:26:06 +03:00
|
|
|
let test = Test::with_tempdir(tmp);
|
2019-11-20 10:07:44 +03:00
|
|
|
|
2021-07-26 11:26:06 +03:00
|
|
|
let justfile_path = test.justfile_path();
|
2019-11-20 10:07:44 +03:00
|
|
|
|
2021-07-26 11:26:06 +03:00
|
|
|
let _tmp = test
|
|
|
|
.no_justfile()
|
|
|
|
.stderr_regex("Wrote justfile to `.*`\n")
|
|
|
|
.arg("--init")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
assert_eq!(fs::read_to_string(justfile_path).unwrap(), EXPECTED);
|
2019-11-20 10:07:44 +03:00
|
|
|
}
|
|
|
|
|
2019-11-20 10:35:29 +03:00
|
|
|
#[test]
|
|
|
|
fn parent_dir() {
|
2021-07-04 00:26:59 +03:00
|
|
|
let tmp = temptree! {
|
2019-11-20 10:35:29 +03:00
|
|
|
".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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-20 10:07:44 +03:00
|
|
|
#[test]
|
|
|
|
fn alternate_marker() {
|
2021-07-04 00:26:59 +03:00
|
|
|
let tmp = temptree! {
|
2019-11-20 10:07:44 +03:00
|
|
|
"_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() {
|
2021-07-04 00:26:59 +03:00
|
|
|
let tmp = temptree! {
|
2019-11-20 10:07:44 +03:00
|
|
|
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() {
|
2021-07-04 00:26:59 +03:00
|
|
|
let tmp = temptree! {
|
2019-11-20 10:07:44 +03:00
|
|
|
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() {
|
2021-07-04 00:26:59 +03:00
|
|
|
let tmp = temptree! {
|
2019-11-20 10:07:44 +03:00
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
2022-02-23 22:47:43 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fmt_compatibility() {
|
2023-01-13 22:03:14 +03:00
|
|
|
let output = Test::new()
|
2022-02-23 22:47:43 +03:00
|
|
|
.no_justfile()
|
|
|
|
.arg("--init")
|
|
|
|
.stderr_regex("Wrote justfile to `.*`\n")
|
|
|
|
.run();
|
2023-01-13 22:03:14 +03:00
|
|
|
Test::with_tempdir(output.tempdir)
|
2022-02-23 22:47:43 +03:00
|
|
|
.no_justfile()
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--check")
|
|
|
|
.arg("--fmt")
|
|
|
|
.status(EXIT_SUCCESS)
|
|
|
|
.run();
|
|
|
|
}
|