tests: cksum: add incorrect data to verify --check & --strict
[coreutils.git] / tests / help / help-version-getopt.sh
blob474bf1eb99d789ffb0caeaa40c246ea8bedce20d
1 #!/bin/sh
2 # Ensure --version and --help options are processed before
3 # any other options by some programs.
5 # Copyright (C) 2019-2024 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21 print_ver_ yes
23 programs="cksum dd hostid hostname link logname nohup
24 sleep tsort unlink uptime users whoami yes"
26 # All these variations should show the help/version screen
27 # regardless of their position on the command line arguments.
28 for prog in $programs; do
29 # skip if the program is not built (e.g., hostname)
30 case " $built_programs " in
31 *" $prog "*) ;;
32 *) continue;;
33 esac
35 for opt in --help --version; do
36 rm -f exp out1 out2 out3 || framework_failure_
38 # Get the reference output
39 env $prog $opt >exp || fail=1
41 # Test: some other argument AFTER --help/--version.
42 env $prog $opt AFTER > out1 || fail=1
43 compare exp out1 || fail=1
45 # nohup is an exception: stops processing after first non-option parameter.
46 # E.g., "nohup df --help" should run "df --help", not "df --help".
47 if [ "$prog" = nohup ]; then
48 rm -f exp || framework_failure_
49 df $opt > exp || framework_failure_
50 BEFORE=df
51 else
52 BEFORE=BEFORE
55 # Test: some other argument BEFORE --help/--version.
56 env $prog $BEFORE $opt > out2 || fail=1
57 compare exp out2 || fail=1
59 # Test: some other arguments BEFORE and AFTER --help/--version.
60 env $prog $BEFORE $opt AFTER > out3 || fail=1
61 compare exp out3 || fail=1
62 done
63 done
65 # After end-of-options marker (--), the options should not be parsed.
66 # Test with 'yes', and assume the common code will work the
67 # same for the other programs.
68 cat >exp <<\EOF || framework_failure_
69 --help
70 EOF
71 env yes -- --help | head -n1 > out
72 compare exp out || fail=1
74 Exit $fail