am-ft: make the environment available earlier
[platform/upstream/automake.git] / t / py-compile-usage.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
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/>.
16
17 # Test 'py-compile --help', 'py-compile --version', and that 'py-compile'
18 # correctly complains on wrong usage.
19
20 . test-init.sh
21
22 cp "$am_scriptdir/py-compile" . \
23   || fatal_ "failed to fetch auxiliary script py-compile"
24
25 # --help
26
27 ./py-compile --help >stdout 2>stderr \
28   || { cat stdout; cat stderr >&2; exit 1; }
29 cat stdout
30 test -s stderr && { cat stderr >&2; exit 1; }
31 grep '^Usage: py-compile .' stdout
32 $FGREP ' [--basedir DIR]' stdout
33 $FGREP ' [--destdir DIR]' stdout
34
35 # --version
36
37 ./py-compile --version >stdout 2>stderr \
38   || { cat stdout; cat stderr >&2; exit 1; }
39 cat stdout
40 test -s stderr && { cat stderr >&2; exit 1; }
41 year='20[0-9][0-9]' # Hopefully automake will be obsolete in 80 years ;-)
42 month='(0[0-9]|1[012])'
43 day='([012][0-9]|3[01])'
44 hour='([01][0-9]|2[0123])'
45 LC_ALL=C $EGREP "^py-compile $year-$month-$day\.$hour" stdout
46 test $(wc -l <stdout) -eq 1
47
48 # Unknown option.
49
50 for opt in -b -d --foo; do
51   ./py-compile $opt 2>stderr && { cat stderr >&2; exit 1; }
52   cat stderr >&2
53   grep "^py-compile: unrecognized option '$opt'" stderr
54   grep "^Try 'py-compile --help' for more information" stderr
55 done
56
57 # Missing option argument.
58
59 for opt in --basedir --destdir; do
60   ./py-compile $opt 2>stderr && { cat stderr >&2; exit 1; }
61   cat stderr >&2
62   grep "^py-compile: option '$opt' requires an argument" stderr
63   grep "^Try 'py-compile --help' for more information" stderr
64 done
65
66 # Missing files.
67
68 for args in '' '--basedir dir' '--destdir dir'; do
69   ./py-compile $args 2>stderr && { cat stderr >&2; exit 1; }
70   cat stderr >&2
71   grep '^py-compile: no files given' stderr
72   grep "^Try 'py-compile --help' for more information" stderr
73 done
74
75 :