tests: work around strangeness in MSYS
[automake.git] / tests / missing-tar.test
blob72c7f078719029894663ed8ef4976b80c6419ae5
1 #! /bin/sh
2 # Copyright (C) 2011 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Test how the `missing' script wraps the`tar' program.
19 . ./defs || Exit 1
21 get_shell_script "missing"
23 old_PATH=$PATH; export old_PATH
24 new_PATH=`pwd`/bin$PATH_SEPARATOR$PATH
25 mkdir bin
27 cat > data.txt <<'END'
28 To be, or not to be: that is the question:
29 Whether 'tis nobler in the mind to suffer
30 ...
31 END
33 cat > nonesuch <<'END'
34 #!/bin/sh
35 exit 127
36 END
37 chmod a+x nonesuch
39 # Simple runs.
40 for nullify_gnu in yes no; do
41 case $nullify_gnu in
42 yes)
43 cp nonesuch bin/gtar
44 cp nonesuch bin/gnutar
45 PATH=$new_PATH; export PATH;
46 mkdir simple-nognu
47 cd simple-nognu
49 no)
50 mkdir simple-dflt
51 cd simple-dflt
54 Exit 99 # Can't happen.
56 esac
57 cp ../data.txt foobar.txt
58 ../missing --run tar cvf mu.tar foobar.txt
59 rm -f foobar.txt
60 test -f mu.tar
61 ../missing --run tar tf mu.tar >output 2>&1 || { cat output; Exit 1; }
62 cat output
63 $FGREP 'foobar.txt' output
64 test ! -f foobar.txt
65 ../missing --run tar xvf mu.tar
66 diff ../data.txt foobar.txt
67 PATH=$old_PATH; export PATH;
68 cd ..
69 done
71 rm -f bin/*
73 # Helper scripts and functions for next tests.
75 cat > fake-gnu-tar <<'END'
76 #!/bin/sh
77 case " $* " in *\ --version\ *) echo fake GNU tar; exit $?;; esac
78 PATH=$old_PATH; export PATH
79 exec tar "$@"
80 END
81 chmod a+x fake-gnu-tar
83 cat > failing-tar <<'END'
84 #!/bin/sh
85 echo "Error message from tar passed through" >&2
86 exit 1
87 END
88 chmod a+x failing-tar
90 grep_tar_failed ()
92 grep "WARNING:.* can't.* run \`tar' with .*given arguments" $*
95 # The `tar' program does not work with the given options, but we have
96 # gtar or gnutar.
97 cp failing-tar bin/tar
98 for pfx in g gnu; do
99 case $pfx in g) othpfx=gnu;; gnu) othpfx=g;; *) Exit 99;; esac
100 cp nonesuch bin/${othpfx}tar
101 if ${pfx}tar --version | grep GNU; then :; else
102 cp fake-gnu-tar bin/${pfx}tar
104 tarball=foo-$pfx.tar
105 PATH=$new_PATH; export PATH
106 ./missing --run tar cvf $tarball ./data.txt 2>stderr \
107 || { cat stderr >&2; Exit 1; }
108 cat stderr >&2
109 PATH=$old_PATH; export PATH
110 test -f $tarball
111 grep_tar_failed stderr
112 grep "Error message from tar passed through" stderr
113 grep "[Tt]rying to use GNU tar.*${pfx}tar" stderr
114 grep "${othpfx}tar" stderr && Exit 1
115 : # For shells with broken 'set -e'
116 done
118 rm -f bin/*
120 # The `tar' program does not work with the given options, and we don't
121 # have neither gtar nor gnutar.
122 cp failing-tar bin/tar
123 cp nonesuch bin/gtar
124 cp nonesuch bin/gnutar
125 PATH=$new_PATH; export PATH
126 ./missing --run tar cvf foo.tar ./data.txt 2>stderr \
127 && { cat stderr >&2; Exit 1; }
128 cat stderr >&2
129 PATH=$old_PATH; export PATH
130 test ! -f foo.tar
131 grep_tar_failed stderr
132 grep "Error message from tar passed through" stderr
133 grep "[iI]nstall GNU tar or Free [pP]axutils" stderr
134 $EGREP "(g|gnu)tar" stderr && Exit 1
136 rm -f bin/*
138 # We try to use an option that causes any `tar' program (GNU or non-GNU) to.
139 ./missing --run tar --bad-unknonw-option cvf foo.tar ./data.txt 2>stderr \
140 && { cat stderr >&2; Exit 1; }
141 cat stderr >&2
142 test ! -f foo.tar
143 grep_tar_failed stderr
144 grep "bad-unknonw-option" stderr
145 for p in gtar gnutar; do
146 if $p --version; then
147 cnt=1
148 else
149 cnt=0
151 test `$EGREP -c "[Tt]rying to use GNU tar.*$p" stderr` -eq $cnt
152 done