diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index df3aabf40..d5a7c8659 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -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 diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index c52202ec2..a4319b71f 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -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] diff --git a/util/gnu-patches/tests_env_env-S.pl.patch b/util/gnu-patches/tests_env_env-S.pl.patch index 1ea860fa0..b3c5d34d1 100644 --- a/util/gnu-patches/tests_env_env-S.pl.patch +++ b/util/gnu-patches/tests_env_env-S.pl.patch @@ -2,27 +2,41 @@ 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}, - {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" . + "For more information, try '--help'.\n" . + "$prog: use -[v]S to pass options in shebang lines\n"}], - + # Also diagnose incorrect shebang usage when failing to exec. # This typically happens with: