2022-06-19 07:56:31 +03:00
|
|
|
use super::*;
|
2020-10-27 04:16:42 +03:00
|
|
|
|
2022-12-20 11:44:19 +03:00
|
|
|
test! {
|
2023-11-22 07:17:38 +03:00
|
|
|
name: invalid_alias_attribute,
|
|
|
|
justfile: "[private]\n[linux]\nalias t := test\n\ntest:\n",
|
|
|
|
stderr: "
|
2024-01-13 05:44:13 +03:00
|
|
|
error: Alias `t` has invalid attribute `linux`
|
2023-12-30 00:25:30 +03:00
|
|
|
——▶ justfile:3:7
|
|
|
|
│
|
|
|
|
3 │ alias t := test
|
|
|
|
│ ^
|
2023-11-22 07:17:38 +03:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
2022-12-20 11:44:19 +03:00
|
|
|
}
|
|
|
|
|
2020-10-27 04:16:42 +03:00
|
|
|
test! {
|
|
|
|
name: expected_keyword,
|
|
|
|
justfile: "foo := if '' == '' { '' } arlo { '' }",
|
|
|
|
stderr: "
|
|
|
|
error: Expected keyword `else` but found identifier `arlo`
|
2023-12-30 00:25:30 +03:00
|
|
|
——▶ justfile:1:27
|
|
|
|
│
|
|
|
|
1 │ foo := if '' == '' { '' } arlo { '' }
|
|
|
|
│ ^^^^
|
2020-10-27 04:16:42 +03:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unexpected_character,
|
2023-01-13 06:25:28 +03:00
|
|
|
justfile: "&~",
|
2020-10-27 04:16:42 +03:00
|
|
|
stderr: "
|
2023-01-13 06:25:28 +03:00
|
|
|
error: Expected character `&`
|
2023-12-30 00:25:30 +03:00
|
|
|
——▶ justfile:1:2
|
|
|
|
│
|
|
|
|
1 │ &~
|
|
|
|
│ ^
|
2020-10-27 04:16:42 +03:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
2021-07-29 04:27:47 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn argument_count_mismatch() {
|
|
|
|
Test::new()
|
|
|
|
.justfile("foo a b:")
|
2023-01-04 09:31:56 +03:00
|
|
|
.args(["foo"])
|
2021-07-29 04:27:47 +03:00
|
|
|
.stderr(
|
|
|
|
"
|
|
|
|
error: Recipe `foo` got 0 arguments but takes 2
|
|
|
|
usage:
|
|
|
|
just foo a b
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.run();
|
|
|
|
}
|
2023-11-22 07:17:38 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn file_path_is_indented_if_justfile_is_long() {
|
|
|
|
Test::new()
|
|
|
|
.justfile("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nfoo")
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr(
|
|
|
|
"
|
|
|
|
error: Expected '*', ':', '$', identifier, or '+', but found end of file
|
2023-12-30 00:25:30 +03:00
|
|
|
——▶ justfile:20:4
|
|
|
|
│
|
|
|
|
20 │ foo
|
|
|
|
│ ^
|
2023-11-22 07:17:38 +03:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn file_paths_are_relative() {
|
|
|
|
Test::new()
|
2023-12-20 07:31:51 +03:00
|
|
|
.justfile("import 'foo/bar.just'")
|
2023-11-22 07:17:38 +03:00
|
|
|
.write("foo/bar.just", "baz")
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr(format!(
|
|
|
|
"
|
|
|
|
error: Expected '*', ':', '$', identifier, or '+', but found end of file
|
2024-07-28 01:00:19 +03:00
|
|
|
——▶ foo{MAIN_SEPARATOR}bar.just:1:4
|
2023-12-30 00:25:30 +03:00
|
|
|
│
|
|
|
|
1 │ baz
|
|
|
|
│ ^
|
2023-11-22 07:17:38 +03:00
|
|
|
",
|
|
|
|
))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-12-30 00:25:30 +03:00
|
|
|
#[cfg(not(windows))]
|
2023-11-22 07:17:38 +03:00
|
|
|
fn file_paths_not_in_subdir_are_absolute() {
|
|
|
|
Test::new()
|
2023-12-20 07:31:51 +03:00
|
|
|
.write("foo/justfile", "import '../bar.just'")
|
2023-11-22 07:17:38 +03:00
|
|
|
.write("bar.just", "baz")
|
|
|
|
.no_justfile()
|
2023-12-20 07:31:51 +03:00
|
|
|
.args(["--justfile", "foo/justfile"])
|
2023-11-22 07:17:38 +03:00
|
|
|
.status(EXIT_FAILURE)
|
2023-12-30 00:25:30 +03:00
|
|
|
.stderr_regex(
|
|
|
|
r"error: Expected '\*', ':', '\$', identifier, or '\+', but found end of file
|
|
|
|
——▶ /.*/bar.just:1:4
|
|
|
|
│
|
|
|
|
1 │ baz
|
|
|
|
│ \^
|
2023-11-22 07:17:38 +03:00
|
|
|
",
|
2023-12-30 00:25:30 +03:00
|
|
|
)
|
2023-11-22 07:17:38 +03:00
|
|
|
.run();
|
|
|
|
}
|
2024-09-13 11:45:32 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn redefinition_errors_properly_swap_types() {
|
|
|
|
Test::new()
|
|
|
|
.write("foo.just", "foo:")
|
|
|
|
.justfile("foo:\n echo foo\n\nmod foo 'foo.just'")
|
|
|
|
.status(EXIT_FAILURE)
|
|
|
|
.stderr(
|
|
|
|
"
|
|
|
|
error: Recipe `foo` defined on line 1 is redefined as a module on line 4
|
|
|
|
——▶ justfile:4:5
|
|
|
|
│
|
|
|
|
4 │ mod foo 'foo.just'
|
|
|
|
│ ^^^
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|