2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2021-04-04 16:41:02 -07:00
|
|
|
|
|
|
|
test! {
|
|
|
|
name: raw_string,
|
|
|
|
justfile: r#"
|
|
|
|
export EXPORTED_VARIABLE := '\z'
|
|
|
|
|
|
|
|
recipe:
|
|
|
|
printf "$EXPORTED_VARIABLE"
|
|
|
|
"#,
|
|
|
|
stdout: "\\z",
|
|
|
|
stderr: "printf \"$EXPORTED_VARIABLE\"\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: multiline_raw_string,
|
|
|
|
justfile: "
|
|
|
|
string := 'hello
|
|
|
|
whatever'
|
|
|
|
|
|
|
|
a:
|
|
|
|
echo '{{string}}'
|
|
|
|
",
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "hello
|
|
|
|
whatever
|
|
|
|
",
|
|
|
|
stderr: "echo 'hello
|
|
|
|
whatever'
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: multiline_backtick,
|
|
|
|
justfile: "
|
|
|
|
string := `echo hello
|
|
|
|
echo goodbye
|
|
|
|
`
|
|
|
|
|
|
|
|
a:
|
|
|
|
echo '{{string}}'
|
|
|
|
",
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "hello\ngoodbye\n",
|
|
|
|
stderr: "echo 'hello
|
|
|
|
goodbye'
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: multiline_cooked_string,
|
|
|
|
justfile: r#"
|
|
|
|
string := "hello
|
|
|
|
whatever"
|
|
|
|
|
|
|
|
a:
|
|
|
|
echo '{{string}}'
|
|
|
|
"#,
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "hello
|
|
|
|
whatever
|
|
|
|
",
|
|
|
|
stderr: "echo 'hello
|
|
|
|
whatever'
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
2021-04-05 21:28:37 -07:00
|
|
|
test! {
|
|
|
|
name: cooked_string_suppress_newline,
|
|
|
|
justfile: r#"
|
|
|
|
a := """
|
|
|
|
foo\
|
|
|
|
bar
|
|
|
|
"""
|
|
|
|
|
|
|
|
@default:
|
|
|
|
printf %s '{{a}}'
|
|
|
|
"#,
|
|
|
|
stdout: "
|
|
|
|
foobar
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
2021-04-04 16:41:02 -07:00
|
|
|
test! {
|
|
|
|
name: invalid_escape_sequence,
|
|
|
|
justfile: r#"x := "\q"
|
|
|
|
a:"#,
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
|
|
|
stderr: "error: `\\q` is not a valid escape sequence
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:6
|
2021-04-04 16:41:02 -07:00
|
|
|
|
|
|
|
|
1 | x := \"\\q\"
|
|
|
|
| ^^^^
|
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: error_line_after_multiline_raw_string,
|
|
|
|
justfile: "
|
|
|
|
string := 'hello
|
|
|
|
|
|
|
|
whatever' + 'yo'
|
|
|
|
|
|
|
|
a:
|
|
|
|
echo '{{foo}}'
|
|
|
|
",
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
|
|
|
stderr: "error: Variable `foo` not defined
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:6:11
|
2021-04-04 16:41:02 -07:00
|
|
|
|
|
2021-04-05 21:28:37 -07:00
|
|
|
6 | echo '{{foo}}'
|
2021-04-04 16:41:02 -07:00
|
|
|
| ^^^
|
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: error_column_after_multiline_raw_string,
|
|
|
|
justfile: "
|
|
|
|
string := 'hello
|
|
|
|
|
|
|
|
whatever' + bar
|
|
|
|
|
|
|
|
a:
|
|
|
|
echo '{{string}}'
|
|
|
|
",
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
|
|
|
stderr: "error: Variable `bar` not defined
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:3:13
|
2021-04-04 16:41:02 -07:00
|
|
|
|
|
2021-04-05 21:28:37 -07:00
|
|
|
3 | whatever' + bar
|
2021-04-04 16:41:02 -07:00
|
|
|
| ^^^
|
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: multiline_raw_string_in_interpolation,
|
|
|
|
justfile: r#"
|
|
|
|
a:
|
|
|
|
echo '{{"a" + '
|
|
|
|
' + "b"}}'
|
|
|
|
"#,
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "
|
|
|
|
a
|
|
|
|
b
|
|
|
|
",
|
|
|
|
stderr: "
|
|
|
|
echo 'a
|
|
|
|
b'
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: error_line_after_multiline_raw_string_in_interpolation,
|
|
|
|
justfile: r#"
|
|
|
|
a:
|
|
|
|
echo '{{"a" + '
|
|
|
|
' + "b"}}'
|
|
|
|
|
|
|
|
echo {{b}}
|
|
|
|
"#,
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
|
|
|
stderr: "error: Variable `b` not defined
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:5:10
|
2021-04-04 16:41:02 -07:00
|
|
|
|
|
2021-04-05 21:28:37 -07:00
|
|
|
5 | echo {{b}}
|
2021-04-04 16:41:02 -07:00
|
|
|
| ^
|
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unterminated_raw_string,
|
|
|
|
justfile: "
|
2021-04-05 21:28:37 -07:00
|
|
|
a b= ':
|
|
|
|
",
|
2021-04-04 16:41:02 -07:00
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
2021-04-05 21:28:37 -07:00
|
|
|
stderr: "
|
|
|
|
error: Unterminated string
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:6
|
2021-04-05 21:28:37 -07:00
|
|
|
|
|
|
|
|
1 | a b= ':
|
|
|
|
| ^
|
|
|
|
",
|
2021-04-04 16:41:02 -07:00
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unterminated_string,
|
|
|
|
justfile: r#"
|
2021-04-05 21:28:37 -07:00
|
|
|
a b= ":
|
|
|
|
"#,
|
2021-04-04 16:41:02 -07:00
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
2021-04-05 21:28:37 -07:00
|
|
|
stderr: r#"
|
|
|
|
error: Unterminated string
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:6
|
2021-04-05 21:28:37 -07:00
|
|
|
|
|
|
|
|
1 | a b= ":
|
|
|
|
| ^
|
|
|
|
"#,
|
2021-04-04 16:41:02 -07:00
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unterminated_backtick,
|
|
|
|
justfile: "
|
2021-04-05 21:28:37 -07:00
|
|
|
foo a=\t`echo blaaaaaah:
|
|
|
|
echo {{a}}
|
|
|
|
",
|
2021-04-04 16:41:02 -07:00
|
|
|
stderr: r#"
|
|
|
|
error: Unterminated backtick
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:8
|
2021-04-04 16:41:02 -07:00
|
|
|
|
|
2021-04-05 21:28:37 -07:00
|
|
|
1 | foo a= `echo blaaaaaah:
|
2021-04-04 16:41:02 -07:00
|
|
|
| ^
|
|
|
|
"#,
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
2021-04-05 21:28:37 -07:00
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unterminated_indented_raw_string,
|
|
|
|
justfile: "
|
|
|
|
a b= ''':
|
|
|
|
",
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
|
|
|
stderr: "
|
|
|
|
error: Unterminated string
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:6
|
2021-04-05 21:28:37 -07:00
|
|
|
|
|
|
|
|
1 | a b= ''':
|
|
|
|
| ^^^
|
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unterminated_indented_string,
|
|
|
|
justfile: r#"
|
|
|
|
a b= """:
|
|
|
|
"#,
|
|
|
|
args: ("a"),
|
|
|
|
stdout: "",
|
|
|
|
stderr: r#"
|
|
|
|
error: Unterminated string
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:6
|
2021-04-05 21:28:37 -07:00
|
|
|
|
|
|
|
|
1 | a b= """:
|
|
|
|
| ^^^
|
|
|
|
"#,
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: unterminated_indented_backtick,
|
|
|
|
justfile: "
|
|
|
|
foo a=\t```echo blaaaaaah:
|
|
|
|
echo {{a}}
|
|
|
|
",
|
|
|
|
stderr: r#"
|
|
|
|
error: Unterminated backtick
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:8
|
2021-04-05 21:28:37 -07:00
|
|
|
|
|
|
|
|
1 | foo a= ```echo blaaaaaah:
|
|
|
|
| ^^^
|
|
|
|
"#,
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_raw_string_contents_indentation_removed,
|
|
|
|
justfile: "
|
|
|
|
a := '''
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
'''
|
|
|
|
|
|
|
|
@default:
|
|
|
|
printf '{{a}}'
|
|
|
|
",
|
|
|
|
stdout: "
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_cooked_string_contents_indentation_removed,
|
|
|
|
justfile: r#"
|
|
|
|
a := """
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
"""
|
|
|
|
|
|
|
|
@default:
|
|
|
|
printf '{{a}}'
|
|
|
|
"#,
|
|
|
|
stdout: "
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_backtick_string_contents_indentation_removed,
|
|
|
|
justfile: r#"
|
|
|
|
a := ```
|
|
|
|
printf '
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
'
|
|
|
|
```
|
|
|
|
|
|
|
|
@default:
|
|
|
|
printf '{{a}}'
|
|
|
|
"#,
|
|
|
|
stdout: "\n\nfoo\nbar",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_raw_string_escapes,
|
2023-10-08 19:34:05 -07:00
|
|
|
justfile: r"
|
2021-04-05 21:28:37 -07:00
|
|
|
a := '''
|
|
|
|
foo\n
|
|
|
|
bar
|
|
|
|
'''
|
|
|
|
|
|
|
|
@default:
|
|
|
|
printf %s '{{a}}'
|
2023-10-08 19:34:05 -07:00
|
|
|
",
|
|
|
|
stdout: r"
|
2021-04-05 21:28:37 -07:00
|
|
|
foo\n
|
|
|
|
bar
|
2023-10-08 19:34:05 -07:00
|
|
|
",
|
2021-04-05 21:28:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_cooked_string_escapes,
|
|
|
|
justfile: r#"
|
|
|
|
a := """
|
|
|
|
foo\n
|
|
|
|
bar
|
|
|
|
"""
|
|
|
|
|
|
|
|
@default:
|
|
|
|
printf %s '{{a}}'
|
|
|
|
"#,
|
|
|
|
stdout: "
|
|
|
|
foo
|
|
|
|
|
|
|
|
bar
|
|
|
|
",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_backtick_string_escapes,
|
2023-10-08 19:34:05 -07:00
|
|
|
justfile: r"
|
2021-04-05 21:28:37 -07:00
|
|
|
a := ```
|
|
|
|
printf %s '
|
|
|
|
foo\n
|
|
|
|
bar
|
|
|
|
'
|
|
|
|
```
|
|
|
|
|
|
|
|
@default:
|
|
|
|
printf %s '{{a}}'
|
2023-10-08 19:34:05 -07:00
|
|
|
",
|
2021-04-05 21:28:37 -07:00
|
|
|
stdout: "\n\nfoo\\n\nbar",
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: shebang_backtick,
|
|
|
|
justfile: "
|
|
|
|
x := `#!/usr/bin/env sh`
|
|
|
|
",
|
|
|
|
stderr: "
|
|
|
|
error: Backticks may not start with `#!`
|
2023-11-21 20:17:38 -08:00
|
|
|
--> justfile:1:6
|
2021-04-05 21:28:37 -07:00
|
|
|
|
|
|
|
|
1 | x := `#!/usr/bin/env sh`
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^
|
|
|
|
",
|
|
|
|
status: EXIT_FAILURE,
|
|
|
|
}
|