Skip to content

Commit 576bd6f

Browse files
committed
env: adjust to test after the improvement on the error message
1 parent 625dec0 commit 576bd6f

3 files changed

Lines changed: 44 additions & 27 deletions

File tree

src/uu/env/src/env.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
917917
#[cfg(test)]
918918
mod tests {
919919
use super::*;
920+
use uucore::locale;
920921

921922
#[test]
922923
fn test_split_string_environment_vars_test() {
@@ -951,20 +952,22 @@ mod tests {
951952

952953
#[test]
953954
fn test_error_cases() {
955+
let _ = locale::setup_localization("env");
956+
954957
// Test EnvBackslashCNotAllowedInDoubleQuotes
955958
let result = parse_args_from_str(&NCvt::convert(r#"sh -c "echo \c""#));
956959
assert!(result.is_err());
957960
assert_eq!(
958961
result.unwrap_err().to_string(),
959-
"'\\c' must not appear in double-quoted -S string"
962+
"'\\c' must not appear in double-quoted -S string at position 13"
960963
);
961964

962965
// Test EnvInvalidBackslashAtEndOfStringInMinusS
963966
let result = parse_args_from_str(&NCvt::convert(r#"sh -c "echo \"#));
964967
assert!(result.is_err());
965968
assert_eq!(
966969
result.unwrap_err().to_string(),
967-
"no terminating quote in -S string"
970+
"no terminating quote in -S string at position 13 for quote '\"'"
968971
);
969972

970973
// Test EnvInvalidSequenceBackslashXInMinusS
@@ -982,7 +985,7 @@ mod tests {
982985
assert!(result.is_err());
983986
assert_eq!(
984987
result.unwrap_err().to_string(),
985-
"no terminating quote in -S string"
988+
"no terminating quote in -S string at position 12 for quote '\"'"
986989
);
987990

988991
// Test variable-related errors

tests/by-util/test_env.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ fn test_split_string_into_args_s_escaped_c_not_allowed() {
522522
let out = scene.ucmd().args(&[r#"-S"\c""#]).fails().stderr_move_str();
523523
assert_eq!(
524524
out,
525-
"env: '\\c' must not appear in double-quoted -S string\n"
525+
"env: '\\c' must not appear in double-quoted -S string at position 2\n"
526526
);
527527
}
528528

@@ -608,91 +608,91 @@ fn test_env_parsing_errors() {
608608
.arg("-S\\|echo hallo") // no quotes, invalid escape sequence |
609609
.fails_with_code(125)
610610
.no_stdout()
611-
.stderr_is("env: invalid sequence '\\|' in -S\n");
611+
.stderr_is("env: invalid sequence '\\|' in -S at position 1\n");
612612

613613
ts.ucmd()
614614
.arg("-S\\a") // no quotes, invalid escape sequence a
615615
.fails_with_code(125)
616616
.no_stdout()
617-
.stderr_is("env: invalid sequence '\\a' in -S\n");
617+
.stderr_is("env: invalid sequence '\\a' in -S at position 1\n");
618618

619619
ts.ucmd()
620620
.arg("-S\"\\a\"") // double quotes, invalid escape sequence a
621621
.fails_with_code(125)
622622
.no_stdout()
623-
.stderr_is("env: invalid sequence '\\a' in -S\n");
623+
.stderr_is("env: invalid sequence '\\a' in -S at position 2\n");
624624

625625
ts.ucmd()
626626
.arg(r#"-S"\a""#) // same as before, just using r#""#
627627
.fails_with_code(125)
628628
.no_stdout()
629-
.stderr_is("env: invalid sequence '\\a' in -S\n");
629+
.stderr_is("env: invalid sequence '\\a' in -S at position 2\n");
630630

631631
ts.ucmd()
632632
.arg("-S'\\a'") // single quotes, invalid escape sequence a
633633
.fails_with_code(125)
634634
.no_stdout()
635-
.stderr_is("env: invalid sequence '\\a' in -S\n");
635+
.stderr_is("env: invalid sequence '\\a' in -S at position 2\n");
636636

637637
ts.ucmd()
638638
.arg(r"-S\|\&\;") // no quotes, invalid escape sequence |
639639
.fails_with_code(125)
640640
.no_stdout()
641-
.stderr_is("env: invalid sequence '\\|' in -S\n");
641+
.stderr_is("env: invalid sequence '\\|' in -S at position 1\n");
642642

643643
ts.ucmd()
644644
.arg(r"-S\<\&\;") // no quotes, invalid escape sequence <
645645
.fails_with_code(125)
646646
.no_stdout()
647-
.stderr_is("env: invalid sequence '\\<' in -S\n");
647+
.stderr_is("env: invalid sequence '\\<' in -S at position 1\n");
648648

649649
ts.ucmd()
650650
.arg(r"-S\>\&\;") // no quotes, invalid escape sequence >
651651
.fails_with_code(125)
652652
.no_stdout()
653-
.stderr_is("env: invalid sequence '\\>' in -S\n");
653+
.stderr_is("env: invalid sequence '\\>' in -S at position 1\n");
654654

655655
ts.ucmd()
656656
.arg(r"-S\`\&\;") // no quotes, invalid escape sequence `
657657
.fails_with_code(125)
658658
.no_stdout()
659-
.stderr_is("env: invalid sequence '\\`' in -S\n");
659+
.stderr_is("env: invalid sequence '\\`' in -S at position 1\n");
660660

661661
ts.ucmd()
662662
.arg(r#"-S"\`\&\;""#) // double quotes, invalid escape sequence `
663663
.fails_with_code(125)
664664
.no_stdout()
665-
.stderr_is("env: invalid sequence '\\`' in -S\n");
665+
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
666666

667667
ts.ucmd()
668668
.arg(r"-S'\`\&\;'") // single quotes, invalid escape sequence `
669669
.fails_with_code(125)
670670
.no_stdout()
671-
.stderr_is("env: invalid sequence '\\`' in -S\n");
671+
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
672672

673673
ts.ucmd()
674674
.arg(r"-S\`") // ` escaped without quotes
675675
.fails_with_code(125)
676676
.no_stdout()
677-
.stderr_is("env: invalid sequence '\\`' in -S\n");
677+
.stderr_is("env: invalid sequence '\\`' in -S at position 1\n");
678678

679679
ts.ucmd()
680680
.arg(r#"-S"\`""#) // ` escaped in double quotes
681681
.fails_with_code(125)
682682
.no_stdout()
683-
.stderr_is("env: invalid sequence '\\`' in -S\n");
683+
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
684684

685685
ts.ucmd()
686686
.arg(r"-S'\`'") // ` escaped in single quotes
687687
.fails_with_code(125)
688688
.no_stdout()
689-
.stderr_is("env: invalid sequence '\\`' in -S\n");
689+
.stderr_is("env: invalid sequence '\\`' in -S at position 2\n");
690690

691691
ts.ucmd()
692692
.args(&[r"-S\🦉"]) // ` escaped in single quotes
693693
.fails_with_code(125)
694694
.no_stdout()
695-
.stderr_is("env: invalid sequence '\\\u{FFFD}' in -S\n"); // gnu doesn't show the owl. Instead a invalid unicode ?
695+
.stderr_is("env: invalid sequence '\\\u{FFFD}' in -S at position 1\n"); // gnu doesn't show the owl. Instead a invalid unicode ?
696696
}
697697

698698
#[test]

util/gnu-patches/tests_env_env-S.pl.patch

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,41 @@ Index: gnu/tests/env/env-S.pl
22
===================================================================
33
--- gnu.orig/tests/env/env-S.pl
44
+++ gnu/tests/env/env-S.pl
5-
@@ -212,27 +212,28 @@ my @Tests =
6-
{ERR=>"$prog: no terminating quote in -S string\n"}],
5+
@@ -200,36 +200,37 @@ my @Tests =
6+
7+
# Test Error Conditions
8+
['err1', q[-S'"\\c"'], {EXIT=>125},
9+
- {ERR=>"$prog: '\\c' must not appear in double-quoted -S string\n"}],
10+
+ {ERR=>"$prog: '\\c' must not appear in double-quoted -S string at position 2\n"}],
11+
['err2', q[-S'A=B\\'], {EXIT=>125},
12+
- {ERR=>"$prog: invalid backslash at end of string in -S\n"}],
13+
+ {ERR=>"$prog: invalid backslash at end of string in -S at position 4 in context Unquoted\n"}],
14+
['err3', q[-S'"A=B\\"'], {EXIT=>125},
15+
- {ERR=>"$prog: no terminating quote in -S string\n"}],
16+
+ {ERR=>"$prog: no terminating quote in -S string at position 6 for quote '\"'\n"}],
17+
['err4', q[-S"'A=B\\\\'"], {EXIT=>125},
18+
- {ERR=>"$prog: no terminating quote in -S string\n"}],
19+
+ {ERR=>"$prog: no terminating quote in -S string at position 6 for quote '''\n"}],
720
['err5', q[-S'A=B\\q'], {EXIT=>125},
8-
{ERR=>"$prog: invalid sequence '\\q' in -S\n"}],
21+
- {ERR=>"$prog: invalid sequence '\\q' in -S\n"}],
922
- ['err6', q[-S'A=$B'], {EXIT=>125},
1023
- {ERR=>"$prog: only \${VARNAME} expansion is supported, error at: \$B\n"}],
24+
+ {ERR=>"$prog: invalid sequence '\\q' in -S at position 4\n"}],
1125
+ ['err6', q[-S'A=$B echo hello'], {EXIT=>0},
1226
+ {OUT=>"hello"}],
1327
['err7', q[-S'A=${B'], {EXIT=>125},
1428
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
1529
- "error at: \${B\n"}],
16-
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Missing closing brace\n]}],
30+
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Missing closing brace at position 5\n]}],
1731
['err8', q[-S'A=${B%B}'], {EXIT=>125},
1832
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
1933
- "error at: \${B%B}\n"}],
20-
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Unexpected character: '%', expected a closing brace ('}') or colon (':')\n]}],
34+
+ {ERR=>"$prog" . qq[: variable name issue (at 5): Unexpected character: '%', expected a closing brace ('}') or colon (':') at position 5\n]}],
2135
['err9', q[-S'A=${9B}'], {EXIT=>125},
2236
- {ERR=>"$prog: only \${VARNAME} expansion is supported, " .
2337
- "error at: \${9B}\n"}],
24-
+ {ERR=>"$prog" . qq[: variable name issue (at 4): Unexpected character: '9', expected variable name must not start with 0..9\n]}],
25-
38+
+ {ERR=>"$prog" . qq[: variable name issue (at 4): Unexpected character: '9', expected variable name must not start with 0..9 at position 4\n]}],
39+
2640
# Test incorrect shebang usage (extraneous whitespace).
2741
['err_sp2', q['-v -S cat -n'], {EXIT=>125},
2842
- {ERR=>"env: invalid option -- ' '\n" .
@@ -42,6 +56,6 @@ Index: gnu/tests/env/env-S.pl
4256
+ "Usage: $prog [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]\n\n" .
4357
+ "For more information, try '--help'.\n" .
4458
+ "$prog: use -[v]S to pass options in shebang lines\n"}],
45-
59+
4660
# Also diagnose incorrect shebang usage when failing to exec.
4761
# This typically happens with:

0 commit comments

Comments
 (0)