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 = "
|
|
|
|
expression := `EXPRESSION`
|
|
|
|
|
|
|
|
recipe default=`DEFAULT`:
|
|
|
|
{{expression}}
|
|
|
|
{{default}}
|
|
|
|
RECIPE
|
|
|
|
";
|
|
|
|
|
|
|
|
/// Test that --shell correctly sets the shell
|
|
|
|
#[test]
|
2019-11-10 23:17:47 -08:00
|
|
|
#[cfg_attr(windows, ignore)]
|
|
|
|
fn flag() {
|
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,
|
|
|
|
shell: "#!/usr/bin/env bash\necho \"$@\"",
|
|
|
|
};
|
|
|
|
|
|
|
|
let shell = tmp.path().join("shell");
|
|
|
|
|
2019-11-10 23:17:47 -08:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
{
|
|
|
|
let permissions = std::os::unix::fs::PermissionsExt::from_mode(0o700);
|
2023-10-16 20:07:09 -07:00
|
|
|
fs::set_permissions(&shell, permissions).unwrap();
|
2019-11-10 23:17:47 -08:00
|
|
|
}
|
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())
|
|
|
|
.arg("--shell")
|
|
|
|
.arg(shell)
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let stdout = "-cu -cu EXPRESSION\n-cu -cu DEFAULT\n-cu RECIPE\n";
|
2019-11-10 23:17:47 -08:00
|
|
|
assert_stdout(&output, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
const JUSTFILE_CMD: &str = r#"
|
|
|
|
|
|
|
|
set shell := ["cmd.exe", "/C"]
|
|
|
|
|
|
|
|
x := `Echo`
|
|
|
|
|
|
|
|
recipe:
|
|
|
|
REM foo
|
|
|
|
Echo "{{x}}"
|
|
|
|
"#;
|
|
|
|
|
|
|
|
/// Test that we can use `set shell` to use cmd.exe on windows
|
|
|
|
#[test]
|
|
|
|
#[cfg_attr(unix, ignore)]
|
|
|
|
fn cmd() {
|
2021-07-03 14:26:59 -07:00
|
|
|
let tmp = temptree! {
|
2019-11-10 23:17:47 -08:00
|
|
|
justfile: JUSTFILE_CMD,
|
|
|
|
};
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let stdout = "\\\"ECHO is on.\\\"\r\n";
|
|
|
|
|
|
|
|
assert_stdout(&output, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
const JUSTFILE_POWERSHELL: &str = r#"
|
|
|
|
|
|
|
|
set shell := ["powershell.exe", "-c"]
|
|
|
|
|
|
|
|
x := `Write-Host "Hello, world!"`
|
|
|
|
|
|
|
|
recipe:
|
|
|
|
For ($i=0; $i -le 10; $i++) { Write-Host $i }
|
|
|
|
Write-Host "{{x}}"
|
|
|
|
"#;
|
|
|
|
|
|
|
|
/// Test that we can use `set shell` to use cmd.exe on windows
|
|
|
|
#[test]
|
|
|
|
#[cfg_attr(unix, ignore)]
|
|
|
|
fn powershell() {
|
2021-07-03 14:26:59 -07:00
|
|
|
let tmp = temptree! {
|
2019-11-10 23:17:47 -08:00
|
|
|
justfile: JUSTFILE_POWERSHELL,
|
|
|
|
};
|
|
|
|
|
|
|
|
let output = Command::new(executable_path("just"))
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let stdout = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\nHello, world!\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
|
|
|
|
|
|
|
assert_stdout(&output, stdout);
|
|
|
|
}
|
2021-03-28 22:38:07 -07:00
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_args,
|
|
|
|
justfile: "
|
|
|
|
default:
|
|
|
|
echo A${foo}A
|
|
|
|
",
|
|
|
|
args: ("--shell-arg", "-c"),
|
|
|
|
stdout: "AA\n",
|
|
|
|
stderr: "echo A${foo}A\n",
|
|
|
|
shell: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_override,
|
|
|
|
justfile: "
|
|
|
|
set shell := ['foo-bar-baz']
|
|
|
|
|
|
|
|
default:
|
|
|
|
echo hello
|
|
|
|
",
|
|
|
|
args: ("--shell", "bash"),
|
|
|
|
stdout: "hello\n",
|
|
|
|
stderr: "echo hello\n",
|
|
|
|
shell: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shell_arg_override,
|
|
|
|
justfile: "
|
|
|
|
set shell := ['foo-bar-baz']
|
|
|
|
|
|
|
|
default:
|
|
|
|
echo hello
|
|
|
|
",
|
|
|
|
args: ("--shell-arg", "-cu"),
|
|
|
|
stdout: "hello\n",
|
|
|
|
stderr: "echo hello\n",
|
|
|
|
shell: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: set_shell,
|
|
|
|
justfile: "
|
|
|
|
set shell := ['echo', '-n']
|
|
|
|
|
|
|
|
x := `bar`
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{x}}
|
|
|
|
echo foo
|
|
|
|
",
|
|
|
|
args: (),
|
|
|
|
stdout: "echo barecho foo",
|
|
|
|
stderr: "echo bar\necho foo\n",
|
|
|
|
shell: false,
|
|
|
|
}
|
2024-06-11 13:10:32 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn recipe_shell_not_found_error_message() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
foo:
|
|
|
|
@echo bar
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.shell(false)
|
|
|
|
.args(["--shell", "NOT_A_REAL_SHELL"])
|
|
|
|
.stderr_regex(
|
|
|
|
"error: Recipe `foo` could not be run because just could not find the shell: .*\n",
|
|
|
|
)
|
|
|
|
.status(1)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn backtick_recipe_shell_not_found_error_message() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
bar := `echo bar`
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{bar}}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.shell(false)
|
|
|
|
.args(["--shell", "NOT_A_REAL_SHELL"])
|
|
|
|
.stderr_regex("(?s)error: Backtick could not be run because just could not find the shell:.*")
|
|
|
|
.status(1)
|
|
|
|
.run();
|
|
|
|
}
|