2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2020-10-26 18:16:42 -07:00
|
|
|
|
|
|
|
test! {
|
|
|
|
name: then_branch_unevaluated,
|
|
|
|
justfile: "
|
|
|
|
foo:
|
|
|
|
echo {{ if 'a' == 'b' { `exit 1` } else { 'otherwise' } }}
|
|
|
|
",
|
|
|
|
stdout: "otherwise\n",
|
|
|
|
stderr: "echo otherwise\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: otherwise_branch_unevaluated,
|
|
|
|
justfile: "
|
|
|
|
foo:
|
|
|
|
echo {{ if 'a' == 'a' { 'then' } else { `exit 1` } }}
|
|
|
|
",
|
|
|
|
stdout: "then\n",
|
|
|
|
stderr: "echo then\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: otherwise_branch_unevaluated_inverted,
|
|
|
|
justfile: "
|
|
|
|
foo:
|
|
|
|
echo {{ if 'a' != 'b' { 'then' } else { `exit 1` } }}
|
|
|
|
",
|
|
|
|
stdout: "then\n",
|
|
|
|
stderr: "echo then\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: then_branch_unevaluated_inverted,
|
|
|
|
justfile: "
|
|
|
|
foo:
|
|
|
|
echo {{ if 'a' != 'a' { `exit 1` } else { 'otherwise' } }}
|
|
|
|
",
|
|
|
|
stdout: "otherwise\n",
|
|
|
|
stderr: "echo otherwise\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: complex_expressions,
|
|
|
|
justfile: "
|
|
|
|
foo:
|
|
|
|
echo {{ if 'a' + 'b' == `echo ab` { 'c' + 'd' } else { 'e' + 'f' } }}
|
|
|
|
",
|
|
|
|
stdout: "cd\n",
|
|
|
|
stderr: "echo cd\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: undefined_lhs,
|
|
|
|
justfile: "
|
|
|
|
a := if b == '' { '' } else { '' }
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{ a }}
|
|
|
|
",
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
|
|
|
error: Variable `b` not defined
|
2023-12-29 13:25:30 -08:00
|
|
|
——▶ justfile:1:9
|
|
|
|
│
|
|
|
|
1 │ a := if b == '' { '' } else { '' }
|
|
|
|
│ ^
|
2020-10-26 18:16:42 -07:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: undefined_rhs,
|
|
|
|
justfile: "
|
|
|
|
a := if '' == b { '' } else { '' }
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{ a }}
|
|
|
|
",
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
|
|
|
error: Variable `b` not defined
|
2023-12-29 13:25:30 -08:00
|
|
|
——▶ justfile:1:15
|
|
|
|
│
|
|
|
|
1 │ a := if '' == b { '' } else { '' }
|
|
|
|
│ ^
|
2020-10-26 18:16:42 -07:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: undefined_then,
|
|
|
|
justfile: "
|
|
|
|
a := if '' == '' { b } else { '' }
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{ a }}
|
|
|
|
",
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
|
|
|
error: Variable `b` not defined
|
2023-12-29 13:25:30 -08:00
|
|
|
——▶ justfile:1:20
|
|
|
|
│
|
|
|
|
1 │ a := if '' == '' { b } else { '' }
|
|
|
|
│ ^
|
2020-10-26 18:16:42 -07:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: undefined_otherwise,
|
|
|
|
justfile: "
|
|
|
|
a := if '' == '' { '' } else { b }
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{ a }}
|
|
|
|
",
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
|
|
|
error: Variable `b` not defined
|
2023-12-29 13:25:30 -08:00
|
|
|
——▶ justfile:1:32
|
|
|
|
│
|
|
|
|
1 │ a := if '' == '' { '' } else { b }
|
|
|
|
│ ^
|
2020-10-26 18:16:42 -07:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unexpected_op,
|
|
|
|
justfile: "
|
|
|
|
a := if '' a '' { '' } else { b }
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{ a }}
|
|
|
|
",
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
2022-06-25 02:39:06 -07:00
|
|
|
error: Expected '!=', '==', '=~', '+', or '/', but found identifier
|
2023-12-29 13:25:30 -08:00
|
|
|
——▶ justfile:1:12
|
|
|
|
│
|
|
|
|
1 │ a := if '' a '' { '' } else { b }
|
|
|
|
│ ^
|
2020-10-26 18:16:42 -07:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: dump,
|
|
|
|
justfile: "
|
|
|
|
a := if '' == '' { '' } else { '' }
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{ a }}
|
|
|
|
",
|
|
|
|
args: ("--dump"),
|
2021-06-08 01:01:27 -07:00
|
|
|
stdout: "
|
|
|
|
a := if '' == '' { '' } else { '' }
|
2020-10-26 18:16:42 -07:00
|
|
|
|
|
|
|
foo:
|
2021-06-08 01:01:27 -07:00
|
|
|
echo {{ a }}
|
|
|
|
",
|
2020-10-26 18:16:42 -07:00
|
|
|
}
|
2021-07-19 18:21:46 -07:00
|
|
|
|
|
|
|
test! {
|
|
|
|
name: if_else,
|
|
|
|
justfile: "
|
|
|
|
x := if '0' == '1' { 'a' } else if '0' == '0' { 'b' } else { 'c' }
|
|
|
|
|
|
|
|
foo:
|
|
|
|
echo {{ x }}
|
|
|
|
",
|
|
|
|
stdout: "b\n",
|
|
|
|
stderr: "echo b\n",
|
|
|
|
}
|
2022-06-30 03:34:11 -07:00
|
|
|
|
|
|
|
test! {
|
|
|
|
name: missing_else,
|
|
|
|
justfile: "
|
|
|
|
TEST := if path_exists('/bin/bash') == 'true' {'yes'}
|
|
|
|
",
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
|
|
|
error: Expected keyword `else` but found `end of line`
|
2023-12-29 13:25:30 -08:00
|
|
|
——▶ justfile:1:54
|
|
|
|
│
|
|
|
|
1 │ TEST := if path_exists('/bin/bash') == 'true' {'yes'}
|
|
|
|
│ ^
|
2022-06-30 03:34:11 -07:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: incorrect_else_identifier,
|
|
|
|
justfile: "
|
|
|
|
TEST := if path_exists('/bin/bash') == 'true' {'yes'} els {'no'}
|
|
|
|
",
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
|
|
|
error: Expected keyword `else` but found identifier `els`
|
2023-12-29 13:25:30 -08:00
|
|
|
——▶ justfile:1:55
|
|
|
|
│
|
|
|
|
1 │ TEST := if path_exists('/bin/bash') == 'true' {'yes'} els {'no'}
|
|
|
|
│ ^^^
|
2022-06-30 03:34:11 -07:00
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|