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