mirror of
https://github.com/uutils/coreutils.git
synced 2025-07-07 21:45:01 +00:00
env: adjust to test after the improvement on the error message
This commit is contained in:
parent
625dec0be1
commit
576bd6f565
3 changed files with 44 additions and 27 deletions
9
src/uu/env/src/env.rs
vendored
9
src/uu/env/src/env.rs
vendored
|
@ -917,6 +917,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use uucore::locale;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_string_environment_vars_test() {
|
fn test_split_string_environment_vars_test() {
|
||||||
|
@ -951,12 +952,14 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_error_cases() {
|
fn test_error_cases() {
|
||||||
|
let _ = locale::setup_localization("env");
|
||||||
|
|
||||||
// Test EnvBackslashCNotAllowedInDoubleQuotes
|
// Test EnvBackslashCNotAllowedInDoubleQuotes
|
||||||
let result = parse_args_from_str(&NCvt::convert(r#"sh -c "echo \c""#));
|
let result = parse_args_from_str(&NCvt::convert(r#"sh -c "echo \c""#));
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.unwrap_err().to_string(),
|
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
|
// Test EnvInvalidBackslashAtEndOfStringInMinusS
|
||||||
|
@ -964,7 +967,7 @@ mod tests {
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.unwrap_err().to_string(),
|
result.unwrap_err().to_string(),
|
||||||
"no terminating quote in -S string"
|
"no terminating quote in -S string at position 13 for quote '\"'"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test EnvInvalidSequenceBackslashXInMinusS
|
// Test EnvInvalidSequenceBackslashXInMinusS
|
||||||
|
@ -982,7 +985,7 @@ mod tests {
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.unwrap_err().to_string(),
|
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
|
// Test variable-related errors
|
||||||
|
|
|
@ -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();
|
let out = scene.ucmd().args(&[r#"-S"\c""#]).fails().stderr_move_str();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
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 |
|
.arg("-S\\|echo hallo") // no quotes, invalid escape sequence |
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\|' in -S\n");
|
.stderr_is("env: invalid sequence '\\|' in -S at position 1\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg("-S\\a") // no quotes, invalid escape sequence a
|
.arg("-S\\a") // no quotes, invalid escape sequence a
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.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()
|
ts.ucmd()
|
||||||
.arg("-S\"\\a\"") // double quotes, invalid escape sequence a
|
.arg("-S\"\\a\"") // double quotes, invalid escape sequence a
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.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()
|
ts.ucmd()
|
||||||
.arg(r#"-S"\a""#) // same as before, just using r#""#
|
.arg(r#"-S"\a""#) // same as before, just using r#""#
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.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()
|
ts.ucmd()
|
||||||
.arg("-S'\\a'") // single quotes, invalid escape sequence a
|
.arg("-S'\\a'") // single quotes, invalid escape sequence a
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.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()
|
ts.ucmd()
|
||||||
.arg(r"-S\|\&\;") // no quotes, invalid escape sequence |
|
.arg(r"-S\|\&\;") // no quotes, invalid escape sequence |
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\|' in -S\n");
|
.stderr_is("env: invalid sequence '\\|' in -S at position 1\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r"-S\<\&\;") // no quotes, invalid escape sequence <
|
.arg(r"-S\<\&\;") // no quotes, invalid escape sequence <
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\<' in -S\n");
|
.stderr_is("env: invalid sequence '\\<' in -S at position 1\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r"-S\>\&\;") // no quotes, invalid escape sequence >
|
.arg(r"-S\>\&\;") // no quotes, invalid escape sequence >
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\>' in -S\n");
|
.stderr_is("env: invalid sequence '\\>' in -S at position 1\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r"-S\`\&\;") // no quotes, invalid escape sequence `
|
.arg(r"-S\`\&\;") // no quotes, invalid escape sequence `
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S at position 1\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S"\`\&\;""#) // double quotes, invalid escape sequence `
|
.arg(r#"-S"\`\&\;""#) // double quotes, invalid escape sequence `
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r"-S'\`\&\;'") // single quotes, invalid escape sequence `
|
.arg(r"-S'\`\&\;'") // single quotes, invalid escape sequence `
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r"-S\`") // ` escaped without quotes
|
.arg(r"-S\`") // ` escaped without quotes
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S at position 1\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S"\`""#) // ` escaped in double quotes
|
.arg(r#"-S"\`""#) // ` escaped in double quotes
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r"-S'\`'") // ` escaped in single quotes
|
.arg(r"-S'\`'") // ` escaped in single quotes
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.args(&[r"-S\🦉"]) // ` escaped in single quotes
|
.args(&[r"-S\🦉"]) // ` escaped in single quotes
|
||||||
.fails_with_code(125)
|
.fails_with_code(125)
|
||||||
.no_stdout()
|
.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]
|
#[test]
|
||||||
|
|
|
@ -2,27 +2,41 @@ Index: gnu/tests/env/env-S.pl
|
||||||
===================================================================
|
===================================================================
|
||||||
--- gnu.orig/tests/env/env-S.pl
|
--- gnu.orig/tests/env/env-S.pl
|
||||||
+++ gnu/tests/env/env-S.pl
|
+++ gnu/tests/env/env-S.pl
|
||||||
@@ -212,27 +212,28 @@ my @Tests =
|
@@ -200,36 +200,37 @@ my @Tests =
|
||||||
{ERR=>"$prog: no terminating quote in -S string\n"}],
|
|
||||||
|
# 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},
|
['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},
|
- ['err6', q[-S'A=$B'], {EXIT=>125},
|
||||||
- {ERR=>"$prog: only \${VARNAME} expansion is supported, error at: \$B\n"}],
|
- {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},
|
+ ['err6', q[-S'A=$B echo hello'], {EXIT=>0},
|
||||||
+ {OUT=>"hello"}],
|
+ {OUT=>"hello"}],
|
||||||
['err7', q[-S'A=${B'], {EXIT=>125},
|
['err7', q[-S'A=${B'], {EXIT=>125},
|
||||||
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
|
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
|
||||||
- "error at: \${B\n"}],
|
- "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},
|
['err8', q[-S'A=${B%B}'], {EXIT=>125},
|
||||||
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
|
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
|
||||||
- "error at: \${B%B}\n"}],
|
- "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},
|
['err9', q[-S'A=${9B}'], {EXIT=>125},
|
||||||
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
|
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
|
||||||
- "error at: \${9B}\n"}],
|
- "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).
|
# Test incorrect shebang usage (extraneous whitespace).
|
||||||
['err_sp2', q['-v -S cat -n'], {EXIT=>125},
|
['err_sp2', q['-v -S cat -n'], {EXIT=>125},
|
||||||
- {ERR=>"env: invalid option -- ' '\n" .
|
- {ERR=>"env: invalid option -- ' '\n" .
|
||||||
|
@ -42,6 +56,6 @@ Index: gnu/tests/env/env-S.pl
|
||||||
+ "Usage: $prog [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]\n\n" .
|
+ "Usage: $prog [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]\n\n" .
|
||||||
+ "For more information, try '--help'.\n" .
|
+ "For more information, try '--help'.\n" .
|
||||||
+ "$prog: use -[v]S to pass options in shebang lines\n"}],
|
+ "$prog: use -[v]S to pass options in shebang lines\n"}],
|
||||||
|
|
||||||
# Also diagnose incorrect shebang usage when failing to exec.
|
# Also diagnose incorrect shebang usage when failing to exec.
|
||||||
# This typically happens with:
|
# This typically happens with:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue