1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

[v1.0] posix: don't zero-pad 2nds (re: 5c677a4c, 70fc1da7, b1a41311)

The POSIX mode now disables left-hand zero-padding of seconds in
'time'/'times' output. The standard specifies the output format quite
exactly and zero-padding is not in it.
This commit is contained in:
Martijn Dekker 2022-06-12 16:16:11 +01:00
parent cfc7307be2
commit 9b893992a3
7 changed files with 31 additions and 12 deletions

View file

@ -746,11 +746,11 @@ then
fi
# ======
# 'times' builtin
# 'time' keyword and 'times' builtin
expect=$'0m00.0[0-9][0-9]s 0m00.0[0-9][0-9]s\n0m00.000s 0m00.000s'
actual=$("$SHELL" -c times)
[[ $actual == $expect ]] || err_exit "times output: expected $(printf %q "$expect"), got $(printf %q "$actual")"
exp=$'^user\t0m00.[0-9]{2}s\nsys\t0m00.[0-9]{2}s\n0m00.[0-9]{3}s 0m00.[0-9]{3}s\n0m00.000s 0m00.000s$'
got=$("$SHELL" -c '{ time; } 2>&1; times')
[[ $got =~ $exp ]] || err_exit "times output: expected match of $(printf %q "$exp"), got $(printf %q "$got")"
expect=$'*: times: too many operands'
actual=$(set +x; eval 'times Extra Args' 2>&1)

View file

@ -197,6 +197,11 @@ let "017 == 15" || err_exit "leading octal zero not recognised in 'let' in --pos
(set --noposix --letoctal; let "017 == 15") || err_exit "leading octal zero not recognised in --noposix --letoctal (1)"
(set --noposix; set --letoctal; let "017 == 15") || err_exit "leading octal zero not recognised in --noposix --letoctal (2)"
# disables zero-padding of seconds in the output of the time and times built-ins;
exp=$'^user\t0m0.[0-9]{2}s\nsys\t0m0.[0-9]{2}s\n0m0.[0-9]{3}s 0m0.[0-9]{3}s\n0m0.000s 0m0.000s$'
got=$("$SHELL" --posix -c '{ time; } 2>&1; times')
[[ $got =~ $exp ]] || err_exit "POSIX time/times output: expected match of $(printf %q "$exp"), got $(printf %q "$got")"
# stops the . command (but not source) from looking up functions defined with the function syntax;
echo 'echo SCRIPT' >scrunction
function scrunction { echo FUNCTION; }