2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
|
|
|
|
const JUSTFILE: &str = "Yooooooo, hopefully this never becomes valid syntax.";
|
|
|
|
|
|
|
|
/// Test that --edit doesn't require a valid justfile
|
|
|
|
#[test]
|
|
|
|
fn invalid_justfile() {
|
2021-07-03 14:26:59 -07:00
|
|
|
let tmp = temptree! {
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
justfile: JUSTFILE,
|
|
|
|
};
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(!output.status.success());
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.arg("--edit")
|
|
|
|
.env("VISUAL", "cat")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_stdout(&output, JUSTFILE);
|
|
|
|
}
|
|
|
|
|
2021-07-26 01:26:06 -07:00
|
|
|
#[test]
|
|
|
|
fn invoke_error() {
|
|
|
|
let tmp = temptree! {
|
|
|
|
justfile: JUSTFILE,
|
|
|
|
};
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(!output.status.success());
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.arg("--edit")
|
|
|
|
.env("VISUAL", "/")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&output.stderr),
|
|
|
|
if cfg!(windows) {
|
2022-12-15 16:53:21 -08:00
|
|
|
"error: Editor `/` invocation failed: program path has no file name\n"
|
2021-07-26 01:26:06 -07:00
|
|
|
} else {
|
|
|
|
"error: Editor `/` invocation failed: Permission denied (os error 13)\n"
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn status_error() {
|
|
|
|
let tmp = temptree! {
|
|
|
|
justfile: JUSTFILE,
|
|
|
|
"exit-2": "#!/usr/bin/env bash\nexit 2\n",
|
|
|
|
};
|
|
|
|
|
2024-06-17 19:42:16 -07:00
|
|
|
let output = Command::new("chmod")
|
|
|
|
.arg("+x")
|
|
|
|
.arg(tmp.path().join("exit-2"))
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(output.status.success());
|
2021-07-26 01:26:06 -07:00
|
|
|
|
|
|
|
let path = env::join_paths(
|
|
|
|
iter::once(tmp.path().to_owned()).chain(env::split_paths(&env::var_os("PATH").unwrap())),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.arg("--edit")
|
|
|
|
.env("PATH", path)
|
|
|
|
.env("VISUAL", "exit-2")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
2021-08-27 17:01:50 -07:00
|
|
|
assert!(
|
|
|
|
Regex::new("^error: Editor `exit-2` failed: exit (code|status): 2\n$")
|
|
|
|
.unwrap()
|
2023-10-16 20:18:25 -07:00
|
|
|
.is_match(str::from_utf8(&output.stderr).unwrap())
|
2021-07-26 01:26:06 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(output.status.code().unwrap(), 2);
|
|
|
|
}
|
|
|
|
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
/// Test that editor is $VISUAL, $EDITOR, or "vim" in that order
|
|
|
|
#[test]
|
|
|
|
fn editor_precedence() {
|
2021-07-03 14:26:59 -07:00
|
|
|
let tmp = temptree! {
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
justfile: JUSTFILE,
|
|
|
|
};
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.arg("--edit")
|
|
|
|
.env("VISUAL", "cat")
|
|
|
|
.env("EDITOR", "this-command-doesnt-exist")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_stdout(&output, JUSTFILE);
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.arg("--edit")
|
|
|
|
.env_remove("VISUAL")
|
|
|
|
.env("EDITOR", "cat")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_stdout(&output, JUSTFILE);
|
|
|
|
|
|
|
|
let cat = which("cat").unwrap();
|
2023-10-16 20:07:09 -07:00
|
|
|
let vim = tmp.path().join(format!("vim{EXE_SUFFIX}"));
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
std::os::unix::fs::symlink(cat, vim).unwrap();
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
std::os::windows::fs::symlink_file(cat, vim).unwrap();
|
|
|
|
|
|
|
|
let path = env::join_paths(
|
|
|
|
iter::once(tmp.path().to_owned()).chain(env::split_paths(&env::var_os("PATH").unwrap())),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.arg("--edit")
|
|
|
|
.env("PATH", path)
|
|
|
|
.env_remove("VISUAL")
|
|
|
|
.env_remove("EDITOR")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_stdout(&output, JUSTFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test that editor working directory is the same as edited justfile
|
|
|
|
#[cfg(unix)]
|
|
|
|
#[test]
|
|
|
|
fn editor_working_directory() {
|
2021-07-03 14:26:59 -07:00
|
|
|
let tmp = temptree! {
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
justfile: JUSTFILE,
|
|
|
|
child: {},
|
|
|
|
editor: "#!/usr/bin/env sh\ncat $1\npwd",
|
|
|
|
};
|
|
|
|
|
|
|
|
let editor = tmp.path().join("editor");
|
|
|
|
|
|
|
|
let permissions = std::os::unix::fs::PermissionsExt::from_mode(0o700);
|
2023-06-12 09:53:55 -07:00
|
|
|
fs::set_permissions(&editor, permissions).unwrap();
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path().join("child"))
|
|
|
|
.arg("--edit")
|
|
|
|
.env("VISUAL", &editor)
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let want = format!(
|
2023-06-12 09:53:55 -07:00
|
|
|
"{JUSTFILE}{}\n",
|
Gargantuan refactor (#522)
- 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.
2019-11-09 21:43:20 -08:00
|
|
|
tmp.path().canonicalize().unwrap().display()
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_stdout(&output, &want);
|
|
|
|
}
|