env: adjust to test after the improvement on the error message

This commit is contained in:
Sylvestre Ledru 2025-06-17 21:50:45 +02:00
parent 625dec0be1
commit 576bd6f565
3 changed files with 44 additions and 27 deletions

View file

@ -917,6 +917,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
#[cfg(test)]
mod tests {
use super::*;
use uucore::locale;
#[test]
fn test_split_string_environment_vars_test() {
@ -951,12 +952,14 @@ mod tests {
#[test]
fn test_error_cases() {
let _ = locale::setup_localization("env");
// Test EnvBackslashCNotAllowedInDoubleQuotes
let result = parse_args_from_str(&NCvt::convert(r#"sh -c "echo \c""#));
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
"'\\c' must not appear in double-quoted -S string"
"'\\c' must not appear in double-quoted -S string at position 13"
);
// Test EnvInvalidBackslashAtEndOfStringInMinusS
@ -964,7 +967,7 @@ mod tests {
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
"no terminating quote in -S string"
"no terminating quote in -S string at position 13 for quote '\"'"
);
// Test EnvInvalidSequenceBackslashXInMinusS
@ -982,7 +985,7 @@ mod tests {
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
"no terminating quote in -S string"
"no terminating quote in -S string at position 12 for quote '\"'"
);
// Test variable-related errors

View file

@ -522,7 +522,7 @@ fn test_split_string_into_args_s_escaped_c_not_allowed() {
let out = scene.ucmd().args(&[r#"-S"\c""#]).fails().stderr_move_str();
assert_eq!(
out,
"env: '\\c' must not appear in double-quoted -S string\n"
"env: '\\c' must not appear in double-quoted -S string at position 2\n"
);
}
@ -608,91 +608,91 @@ fn test_env_parsing_errors() {
.arg("-S\\|echo hallo") // no quotes, invalid escape sequence |
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\|' in -S\n");
.stderr_is("env: invalid sequence '\\|' in -S at position 1\n");
ts.ucmd()
.arg("-S\\a") // no quotes, invalid escape sequence a
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\a' in -S\n");
.stderr_is("env: invalid sequence '\\a' in -S at position 1\n");
ts.ucmd()
.arg("-S\"\\a\"") // double quotes, invalid escape sequence a
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\a' in -S\n");
.stderr_is("env: invalid sequence '\\a' in -S at position 2\n");
ts.ucmd()
.arg(r#"-S"\a""#) // same as before, just using r#""#
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\a' in -S\n");
.stderr_is("env: invalid sequence '\\a' in -S at position 2\n");
ts.ucmd()
.arg("-S'\\a'") // single quotes, invalid escape sequence a
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\a' in -S\n");
.stderr_is("env: invalid sequence '\\a' in -S at position 2\n");
ts.ucmd()
.arg(r"-S\|\&\;") // no quotes, invalid escape sequence |
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\|' in -S\n");
.stderr_is("env: invalid sequence '\\|' in -S at position 1\n");
ts.ucmd()
.arg(r"-S\<\&\;") // no quotes, invalid escape sequence <
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\<' in -S\n");
.stderr_is("env: invalid sequence '\\<' in -S at position 1\n");
ts.ucmd()
.arg(r"-S\>\&\;") // no quotes, invalid escape sequence >
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\>' in -S\n");
.stderr_is("env: invalid sequence '\\>' in -S at position 1\n");
ts.ucmd()
.arg(r"-S\`\&\;") // no quotes, invalid escape sequence `
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\`' in -S\n");
.stderr_is("env: invalid sequence '\\`' in -S at position 1\n");
ts.ucmd()
.arg(r#"-S"\`\&\;""#) // double quotes, invalid escape sequence `
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\`' in -S\n");
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
ts.ucmd()
.arg(r"-S'\`\&\;'") // single quotes, invalid escape sequence `
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\`' in -S\n");
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
ts.ucmd()
.arg(r"-S\`") // ` escaped without quotes
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\`' in -S\n");
.stderr_is("env: invalid sequence '\\`' in -S at position 1\n");
ts.ucmd()
.arg(r#"-S"\`""#) // ` escaped in double quotes
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\`' in -S\n");
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
ts.ucmd()
.arg(r"-S'\`'") // ` escaped in single quotes
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\`' in -S\n");
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
ts.ucmd()
.args(&[r"-S\🦉"]) // ` escaped in single quotes
.fails_with_code(125)
.no_stdout()
.stderr_is("env: invalid sequence '\\\u{FFFD}' in -S\n"); // gnu doesn't show the owl. Instead a invalid unicode ?
.stderr_is("env: invalid sequence '\\\u{FFFD}' in -S at position 1\n"); // gnu doesn't show the owl. Instead a invalid unicode ?
}
#[test]

View file

@ -2,26 +2,40 @@ Index: gnu/tests/env/env-S.pl
===================================================================
--- gnu.orig/tests/env/env-S.pl
+++ gnu/tests/env/env-S.pl
@@ -212,27 +212,28 @@ my @Tests =
{ERR=>"$prog: no terminating quote in -S string\n"}],
@@ -200,36 +200,37 @@ my @Tests =
# Test Error Conditions
['err1', q[-S'"\\c"'], {EXIT=>125},
- {ERR=>"$prog: '\\c' must not appear in double-quoted -S string\n"}],
+ {ERR=>"$prog: '\\c' must not appear in double-quoted -S string at position 2\n"}],
['err2', q[-S'A=B\\'], {EXIT=>125},
- {ERR=>"$prog: invalid backslash at end of string in -S\n"}],
+ {ERR=>"$prog: invalid backslash at end of string in -S at position 4 in context Unquoted\n"}],
['err3', q[-S'"A=B\\"'], {EXIT=>125},
- {ERR=>"$prog: no terminating quote in -S string\n"}],
+ {ERR=>"$prog: no terminating quote in -S string at position 6 for quote '\"'\n"}],
['err4', q[-S"'A=B\\\\'"], {EXIT=>125},
- {ERR=>"$prog: no terminating quote in -S string\n"}],
+ {ERR=>"$prog: no terminating quote in -S string at position 6 for quote '''\n"}],
['err5', q[-S'A=B\\q'], {EXIT=>125},
{ERR=>"$prog: invalid sequence '\\q' in -S\n"}],
- {ERR=>"$prog: invalid sequence '\\q' in -S\n"}],
- ['err6', q[-S'A=$B'], {EXIT=>125},
- {ERR=>"$prog: only \${VARNAME} expansion is supported, error at: \$B\n"}],
+ {ERR=>"$prog: invalid sequence '\\q' in -S at position 4\n"}],
+ ['err6', q[-S'A=$B echo hello'], {EXIT=>0},
+ {OUT=>"hello"}],
['err7', q[-S'A=${B'], {EXIT=>125},
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
- "error at: \${B\n"}],
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Missing closing brace\n]}],
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Missing closing brace at position 5\n]}],
['err8', q[-S'A=${B%B}'], {EXIT=>125},
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
- "error at: \${B%B}\n"}],
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Unexpected character: '%', expected a closing brace ('}') or colon (':')\n]}],
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Unexpected character: '%', expected a closing brace ('}') or colon (':') at position 5\n]}],
['err9', q[-S'A=${9B}'], {EXIT=>125},
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
- "error at: \${9B}\n"}],
+ {ERR=>"$prog" . qq[: variable name issue (at 4): Unexpected character: '9', expected variable name must not start with 0..9\n]}],
+ {ERR=>"$prog" . qq[: variable name issue (at 4): Unexpected character: '9', expected variable name must not start with 0..9 at position 4\n]}],
# Test incorrect shebang usage (extraneous whitespace).
['err_sp2', q['-v -S cat -n'], {EXIT=>125},