pthread-once tests: Fix crash on mingw.
[gnulib.git] / tests / test-parse-duration.sh
blobcf45913261b4f898e6f9819f7d187449cb865830
1 #!/bin/sh
3 # Show all commands when run with environment variable VERBOSE=yes.
4 test -z "$VERBOSE" || set -x
5 prog=test-parse-duration
7 exe=`pwd`/${prog}${EXEEXT}
9 # func_tmpdir
10 # creates a temporary directory.
11 # Sets variable
12 # - tmp pathname of freshly created temporary directory
13 func_tmpdir ()
15 # Use the environment variable TMPDIR, falling back to /tmp. This allows
16 # users to specify a different temporary directory, for example, if their
17 # /tmp is filled up or too small.
18 : "${TMPDIR=/tmp}"
20 # Use the mktemp program if available. If not available, hide the error
21 # message.
22 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
23 test -n "$tmp" && test -d "$tmp"
24 } ||
26 # Use a simple mkdir command. It is guaranteed to fail if the directory
27 # already exists. $RANDOM is bash specific and expands to empty in shells
28 # other than bash, ksh and zsh. Its use does not increase security;
29 # rather, it minimizes the probability of failure in a very cluttered /tmp
30 # directory.
31 tmp=$TMPDIR/gl$$-$RANDOM
32 (umask 077 && mkdir "$tmp")
33 } ||
35 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
36 exit 1
40 die ()
42 echo "${prog} fatal error: $*" >&2
43 exit 1
46 func_tmpdir
47 trap 'rm -rf "${tmp}"' EXIT
48 tmpf="${tmp}/tests.txt"
50 cat > "${tmpf}" <<- _EOF_
51 1 Y 2 M 3 W 4 d 5 h 6 m 7 s
52 P 00010225 T 05:06:07
53 P 1Y2M3W4D T 5H6M7S
54 1 Y 2 M 25 D 5:6:7
55 1 Y 2 M 25 d 5h 6:7
56 1 Y 2 M 25 d 5h 6m 7
57 P 1-2-25 T 5:6:7
58 _EOF_
60 exec 3< "${tmpf}"
61 while read line <&3
63 v=`${CHECKER} ${exe} "${line}" | LC_ALL=C tr -d '\r'` \
64 || { ls -l "${tmpf}"; die "Failed: ${exe} '${line}'"; }
65 test $v -eq 38898367 || die $v is not 38898367
66 done
67 exec 3>&-