From 6796698c9945d87236ffcc939137d0919ef04931 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Tue, 27 Oct 2015 13:13:59 +0000 Subject: all: quote string arguments in error messages These strings are often file names or other user specified parameters, which can give confusing errors in the presence of unexpected characters for example. * cfg.mk (sc_error_quotes): A new syntax check rule. * src/*.c: Wrap error() string arguments with quote(). * tests/: Adjust accordingly. * NEWS: Mention the improvement. --- tests/du/bigtime.sh | 2 +- tests/misc/dircolors.pl | 2 +- tests/misc/printf-cov.pl | 10 +++---- tests/misc/printf.sh | 4 +-- tests/misc/readlink-fp-loop.sh | 6 ++-- tests/misc/shred-passes.sh | 64 +++++++++++++++++++++--------------------- tests/misc/sort.pl | 4 +-- tests/misc/tsort.pl | 6 ++-- 8 files changed, 49 insertions(+), 49 deletions(-) (limited to 'tests') diff --git a/tests/du/bigtime.sh b/tests/du/bigtime.sh index ad484f818..95fa1932d 100755 --- a/tests/du/bigtime.sh +++ b/tests/du/bigtime.sh @@ -37,7 +37,7 @@ case "$future_time" in esac || skip_ "file system cannot represent big time stamps" printf "0\t$bignum\tfuture\n" > exp || framework_failure_ -printf "du: time $bignum is out of range\n" > err_ok || framework_failure_ +printf "du: time '$bignum' is out of range\n" > err_ok || framework_failure_ du --time future >out 2>err || fail=1 diff --git a/tests/misc/dircolors.pl b/tests/misc/dircolors.pl index 2e6f27d88..2ef6228de 100755 --- a/tests/misc/dircolors.pl +++ b/tests/misc/dircolors.pl @@ -26,7 +26,7 @@ use strict; my @Tests = ( ['a', '-b', {IN => {k => "exec\n"}}, - {ERR => "dircolors: k:1: invalid line; missing second token\n"}, + {ERR => "dircolors: 'k':1: invalid line; missing second token\n"}, {EXIT => 1}], ['quote', '-b', {IN => "exec 'echo Hello;:'\n"}, {OUT => "LS_COLORS='ex='\\''echo Hello;\\:'\\'':';\n" diff --git a/tests/misc/printf-cov.pl b/tests/misc/printf-cov.pl index 4be979718..eb4adf3bd 100755 --- a/tests/misc/printf-cov.pl +++ b/tests/misc/printf-cov.pl @@ -46,9 +46,9 @@ my @Tests = ['d-vwvp', '%*.*d 3 2 15', {OUT=>" 15"}], ['d-neg-prec', '%.*d -3 15', {OUT=>"15"}], ['d-big-prec', "%.*d $pow_2_31 15", # INT_MAX - {EXIT=>1}, {ERR=>"$prog: invalid precision: $pow_2_31\n"}], + {EXIT=>1}, {ERR=>"$prog: invalid precision: '$pow_2_31'\n"}], ['d-big-fwidth', "%*d $pow_2_31 15", # INT_MAX - {EXIT=>1}, {ERR=>"$prog: invalid field width: $pow_2_31\n"}], + {EXIT=>1}, {ERR=>"$prog: invalid field width: '$pow_2_31'\n"}], ['F', '%F 1', {OUT=>"1.000000"}], ['LF', '%LF 1', {OUT=>"1.000000"}], ['E', '%E 2', {OUT=>"2.000000E+00"}], @@ -76,12 +76,12 @@ my @Tests = # no-num: Invalid argument (FreeBSD6) # no-num: expected a numeric value (glibc, Solaris 10) {ERR_SUBST => 's/Invalid argument$/expected a numeric value/'}, - {ERR=>"$prog: no-num: expected a numeric value\n"}], + {ERR=>"$prog: 'no-num': expected a numeric value\n"}], ['d-bad-suffix', '%d 9z', {OUT=>'9'}, {EXIT=>1}, - {ERR=>"$prog: 9z: value not completely converted\n"}], + {ERR=>"$prog: '9z': value not completely converted\n"}], ['d-out-of-range', '%d '.('9'x30), {EXIT=>1}, {OUT=>"inaccurate"}, {OUT_SUBST => 's/\d+/inaccurate/'}, - {ERR=>"$prog: 9...9\n"}, {ERR_SUBST => 's/9+.*/9...9/'}], + {ERR=>"$prog: 9...9\n"}, {ERR_SUBST => "s/'9+.*/9...9/"}], ['excess', 'B 1', {OUT=>'B'}, {ERR=>"$prog: warning: ignoring excess arguments, starting with '1'\n"}], ['percent', '%%', {OUT=>'%'}], diff --git a/tests/misc/printf.sh b/tests/misc/printf.sh index 87ca489f2..10b7a8c5d 100755 --- a/tests/misc/printf.sh +++ b/tests/misc/printf.sh @@ -119,8 +119,8 @@ sed 's/: Invalid.*/: expected a numeric value/' err > k && mv k err cat < exp_err printf: warning: ": character(s) following character constant have been ignored -printf: ": expected a numeric value -printf: a: expected a numeric value +printf: '"': expected a numeric value +printf: 'a': expected a numeric value EOF compare exp out || fail=1 diff --git a/tests/misc/readlink-fp-loop.sh b/tests/misc/readlink-fp-loop.sh index 1c4428b94..d3e1a1eaf 100755 --- a/tests/misc/readlink-fp-loop.sh +++ b/tests/misc/readlink-fp-loop.sh @@ -42,10 +42,10 @@ ln -sf ../s/1 d/2 || framework_failure_ readlink -v -e p/1 2> out && fail=1 readlink_msg=$(cat out) case $readlink_msg in - 'readlink: p/1: '*) ;; + "readlink: 'p/1': "*) ;; *) fail=1;; esac -symlink_loop_msg=${readlink_msg#'readlink: p/1: '} +symlink_loop_msg=${readlink_msg#"readlink: 'p/1': "} # Exercise the hash table code. ln -nsf ../s/3 d/2 || framework_failure_ @@ -62,7 +62,7 @@ compare exp out || fail=1 # A trivial loop ln -s loop loop readlink -v -e loop 2> out && fail=1 -echo "readlink: loop: $symlink_loop_msg" > exp || framework_failure_ +echo "readlink: 'loop': $symlink_loop_msg" > exp || framework_failure_ compare exp out || fail=1 Exit $fail diff --git a/tests/misc/shred-passes.sh b/tests/misc/shred-passes.sh index 64216fd8a..c19cc7655 100755 --- a/tests/misc/shred-passes.sh +++ b/tests/misc/shred-passes.sh @@ -24,12 +24,12 @@ print_ver_ shred # 3 random passes and a single rename. printf 1 > f || framework_failure_ echo "\ -shred: f: pass 1/3 (random)... -shred: f: pass 2/3 (random)... -shred: f: pass 3/3 (random)... -shred: f: removing -shred: f: renamed to 0 -shred: f: removed" > exp || framework_failure_ +shred: 'f': pass 1/3 (random)... +shred: 'f': pass 2/3 (random)... +shred: 'f': pass 3/3 (random)... +shred: 'f': removing +shred: 'f': renamed to '0' +shred: 'f': removed" > exp || framework_failure_ shred -v -u f 2>out || fail=1 compare exp out || fail=1 @@ -39,9 +39,9 @@ compare exp out || fail=1 # to bypass the data passes touch f || framework_failure_ echo "\ -shred: f: removing -shred: f: renamed to 0 -shred: f: removed" > exp || framework_failure_ +shred: 'f': removing +shred: 'f': renamed to '0' +shred: 'f': removed" > exp || framework_failure_ shred -v -u f 2>out || fail=1 compare exp out || fail=1 @@ -52,29 +52,29 @@ compare exp out || fail=1 dd bs=100K count=1 if=/dev/zero | tr '\0' 'U' > Us || framework_failure_ printf 1 > f || framework_failure_ echo "\ -shred: f: pass 1/20 (random)... -shred: f: pass 2/20 (ffffff)... -shred: f: pass 3/20 (924924)... -shred: f: pass 4/20 (888888)... -shred: f: pass 5/20 (db6db6)... -shred: f: pass 6/20 (777777)... -shred: f: pass 7/20 (492492)... -shred: f: pass 8/20 (bbbbbb)... -shred: f: pass 9/20 (555555)... -shred: f: pass 10/20 (aaaaaa)... -shred: f: pass 11/20 (random)... -shred: f: pass 12/20 (6db6db)... -shred: f: pass 13/20 (249249)... -shred: f: pass 14/20 (999999)... -shred: f: pass 15/20 (111111)... -shred: f: pass 16/20 (000000)... -shred: f: pass 17/20 (b6db6d)... -shred: f: pass 18/20 (eeeeee)... -shred: f: pass 19/20 (333333)... -shred: f: pass 20/20 (random)... -shred: f: removing -shred: f: renamed to 0 -shred: f: removed" > exp || framework_failure_ +shred: 'f': pass 1/20 (random)... +shred: 'f': pass 2/20 (ffffff)... +shred: 'f': pass 3/20 (924924)... +shred: 'f': pass 4/20 (888888)... +shred: 'f': pass 5/20 (db6db6)... +shred: 'f': pass 6/20 (777777)... +shred: 'f': pass 7/20 (492492)... +shred: 'f': pass 8/20 (bbbbbb)... +shred: 'f': pass 9/20 (555555)... +shred: 'f': pass 10/20 (aaaaaa)... +shred: 'f': pass 11/20 (random)... +shred: 'f': pass 12/20 (6db6db)... +shred: 'f': pass 13/20 (249249)... +shred: 'f': pass 14/20 (999999)... +shred: 'f': pass 15/20 (111111)... +shred: 'f': pass 16/20 (000000)... +shred: 'f': pass 17/20 (b6db6d)... +shred: 'f': pass 18/20 (eeeeee)... +shred: 'f': pass 19/20 (333333)... +shred: 'f': pass 20/20 (random)... +shred: 'f': removing +shred: 'f': renamed to '0' +shred: 'f': removed" > exp || framework_failure_ shred -v -u -n20 --random-source=Us f 2>out || fail=1 compare exp out || fail=1 diff --git a/tests/misc/sort.pl b/tests/misc/sort.pl index f6a222c2c..012d8b94e 100755 --- a/tests/misc/sort.pl +++ b/tests/misc/sort.pl @@ -33,7 +33,7 @@ my $mb_locale = $ENV{LOCALE_FR_UTF8}; # Normalize each diagnostic to use '-'. my $normalize_filename = {ERR_SUBST => 's/^$prog: .*?:/$prog: -:/'}; -my $no_file = "$prog: cannot read: no-file: No such file or directory\n"; +my $no_file = "$prog: cannot read: 'no-file': No such file or directory\n"; my @Tests = ( @@ -327,7 +327,7 @@ my @Tests = ["o-no-file1", qw(-o no-file no-file), {EXIT=>2}, {ERR=>$no_file}], ["create-empty", qw(-o no/such/file /dev/null), {EXIT=>2}, - {ERR=>"$prog: open failed: no/such/file: No such file or directory\n"}], + {ERR=>"$prog: open failed: 'no/such/file': No such file or directory\n"}], # From Paul Eggert. This was fixed in textutils-1.22k. ["neg-nls", '-n', {IN=>"-1\n-9\n"}, {OUT=>"-9\n-1\n"}], diff --git a/tests/misc/tsort.pl b/tests/misc/tsort.pl index 4d04866ad..60f22c43c 100755 --- a/tests/misc/tsort.pl +++ b/tests/misc/tsort.pl @@ -27,10 +27,10 @@ my @Tests = ( ['cycle-1', {IN => {f => "t b\nt s\ns t\n"}}, {OUT => "s\nt\nb\n"}, {EXIT => 1}, - {ERR => "tsort: f: input contains a loop:\ntsort: s\ntsort: t\n"} ], + {ERR => "tsort: 'f': input contains a loop:\ntsort: s\ntsort: t\n"} ], ['cycle-2', {IN => {f => "t x\nt s\ns t\n"}}, {OUT => "s\nt\nx\n"}, {EXIT => 1}, - {ERR => "tsort: f: input contains a loop:\ntsort: s\ntsort: t\n"} ], + {ERR => "tsort: 'f': input contains a loop:\ntsort: s\ntsort: t\n"} ], ['posix-1', {IN => "a b c c d e\ng g\nf g e f\nh h\n"}, {OUT => "a\nc\nd\nh\nb\ne\nf\ng\n"}], @@ -50,7 +50,7 @@ my @Tests = # copy of the final token were appended. ['odd', {IN => "a\n"}, {EXIT => 1}, - {ERR => "tsort: odd.1: input contains an odd number of tokens\n"}], + {ERR => "tsort: 'odd.1': input contains an odd number of tokens\n"}], ['only-one', {IN => {f => ""}}, {IN => {g => ""}}, {EXIT => 1}, -- cgit v1.2.3-54-g00ecf