annotate tests/test-parse-duration.sh @ 40221:8c1a17df67e0

tests: Prepare for using valgrind. tests/*.sh: Invoke all test programs through ${CHECKER}. tests/*/*.sh: Likewise.
author Bruno Haible <bruno@clisp.org>
date Sun, 10 Mar 2019 11:32:11 +0100
parents 2119c582d05b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10823
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
1 #!/bin/sh
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
2
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
3 # Show all commands when run with environment variable VERBOSE=yes.
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
4 test -z "$VERBOSE" || set -x
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
5 prog=test-parse-duration
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
6
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
7 exe=`pwd`/${prog}${EXEEXT}
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
8 nl='
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
9 '
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
10
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
11 # func_tmpdir
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
12 # creates a temporary directory.
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
13 # Sets variable
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
14 # - tmp pathname of freshly created temporary directory
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
15 func_tmpdir ()
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
16 {
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
17 # Use the environment variable TMPDIR, falling back to /tmp. This allows
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
18 # users to specify a different temporary directory, for example, if their
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
19 # /tmp is filled up or too small.
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
20 : ${TMPDIR=/tmp}
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
21 {
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
22 # Use the mktemp program if available. If not available, hide the error
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
23 # message.
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
24 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
25 test -n "$tmp" && test -d "$tmp"
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
26 } ||
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
27 {
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
28 # Use a simple mkdir command. It is guaranteed to fail if the directory
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
29 # already exists. $RANDOM is bash specific and expands to empty in shells
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
30 # other than bash, ksh and zsh. Its use does not increase security;
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
31 # rather, it minimizes the probability of failure in a very cluttered /tmp
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
32 # directory.
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
33 tmp=$TMPDIR/gl$$-$RANDOM
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
34 (umask 077 && mkdir "$tmp")
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
35 } ||
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
36 {
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
37 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
38 exit 1
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
39 }
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
40 }
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
41
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
42 die ()
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
43 {
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
44 echo "${prog} fatal error: $*" >&2
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
45 exit 1
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
46 }
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
47
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
48 func_tmpdir
10887
8985a457ead7 Fix security problem in test-parse-duration.sh.
Bruno Haible <bruno@clisp.org>
parents: 10823
diff changeset
49 trap 'rm -rf "${tmp}"' EXIT
8985a457ead7 Fix security problem in test-parse-duration.sh.
Bruno Haible <bruno@clisp.org>
parents: 10823
diff changeset
50 tmpf="${tmp}/tests.txt"
10823
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
51
10887
8985a457ead7 Fix security problem in test-parse-duration.sh.
Bruno Haible <bruno@clisp.org>
parents: 10823
diff changeset
52 cat > "${tmpf}" <<- _EOF_
16929
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
53 1 Y 2 M 3 W 4 d 5 h 6 m 7 s
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
54 P 00010225 T 05:06:07
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
55 P 1Y2M3W4D T 5H6M7S
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
56 1 Y 2 M 25 D 5:6:7
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
57 1 Y 2 M 25 d 5h 6:7
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
58 1 Y 2 M 25 d 5h 6m 7
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
59 P 1-2-25 T 5:6:7
2119c582d05b testing: fix typo in here doc
Bruce Korb <bkorb@gnu.org>
parents: 15338
diff changeset
60 _EOF_
10823
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
61
10887
8985a457ead7 Fix security problem in test-parse-duration.sh.
Bruno Haible <bruno@clisp.org>
parents: 10823
diff changeset
62 exec 3< "${tmpf}"
11596
c1d3603bec42 tests/test-parse-duration.sh: Don't use non-portable 'read -u3'.
Simon Josefsson <simon@josefsson.org>
parents: 10889
diff changeset
63 while read line <&3
10823
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
64 do
40221
8c1a17df67e0 tests: Prepare for using valgrind.
Bruno Haible <bruno@clisp.org>
parents: 16929
diff changeset
65 v=`${CHECKER} ${exe} "${line}"` || { ls -l "${tmpf}"; die "Failed: ${exe} '${line}'"; }
10823
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
66 test $v -eq 38898367 || die $v is not 38898367
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
67 done
72f4e089ac91 Tests for module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
68 exec 3>&-