annotate tests/builtin_getopts/builtin_getopts.t @ 707:cc06815e5504

Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts(). It also has the "silent" option -- but it is undocumented.
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 02 Oct 2024 19:50:37 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
707
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 Tests for the behaviour of the Shell's `getopts`
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 Shell is /bin/sh.
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 Setup
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 =====
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
7
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 $ set -u
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9 $ . "${TESTDIR}/testsetup.sh"
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
11
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
12 Standard
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
13 ========
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15 $ test_standard_1 -a -b bbb1
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17 OPTION: b with arg: `bbb1'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 OPTIND: 4
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
19
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 The variable will be set to ``?`` after the last option when getopts returns 1:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
21
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23 $ test_standard_1 -a -b bbb1
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 OPTION: b with arg: `bbb1'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
26 OPTIND: 4
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29 No option:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
31 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
32 $ test_standard_1 arg1 arg2 args
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
33 OPTIND: 1
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
34 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
35
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36 OPTARG is **unset** at every invocation of `getopts` first:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
37
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
38 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
39 $ test_standard_1 -a -b bbb1 -a
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
40 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41 OPTION: b with arg: `bbb1'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
43 OPTIND: 5
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
44
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
45 Option arguments are not checked for another option syntax:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
46
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
47 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
48 $ test_standard_1 -a -b -a
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
49 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
50 OPTION: b with arg: `-a'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 OPTIND: 4
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
52
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
53
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
54 Missing arguments:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
55
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
56 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
57 $ test_standard_1 -b
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
58 No arg for -b option
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
59 ERROR: unknown option
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
60 OPTIND: 2
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
61 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
62
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
63 No abort on errors:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
64
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
65 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
66 $ test_standard_1 -u -a
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
67 Illegal option -u
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
68 ERROR: unknown option
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
69 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
70 OPTIND: 3
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
71 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
72
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
73 Abort processing with '--'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
74
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
75 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
76 $ test_standard_1 -a -b xxx -- -a -b yyy
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
77 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
78 OPTION: b with arg: `xxx'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
79 OPTIND: 5
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
80 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
81
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
82 '--' does not stop option processing when a required arg just before is missing
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
83
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
84 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
85 $ test_standard_1 -a -b -- -a -b yyy
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
86 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
87 OPTION: b with arg: `--'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
88 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
89 OPTION: b with arg: `yyy'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
90 OPTIND: 7
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
91
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
92
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
93 No Error Reports
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
94 ================
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
95
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
96 This behaviour with a colon as the very first character in optstring is not
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
97 documented. But it works similar to ksh93.
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
98
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
99 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
100 $ test_noreport_1 -a -b bbb1
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
101 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
102 OPTION: b with arg: `bbb1'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
103 OPTIND: 4
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
104
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
105 The variable will be set to ``?`` after the last option when getopts returns 1:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
106
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
107 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
108 $ test_standard_1 -a -b bbb1
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
109 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
110 OPTION: b with arg: `bbb1'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
111 OPTIND: 4
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
112 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
113
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
114 No option:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
115
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
116 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
117 $ test_noreport_1 arg1 arg2 args
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
118 OPTIND: 1
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
119 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
120
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
121 OPTARG is **unset** at every invocation of `getopts` first:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
122
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
123 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
124 $ test_noreport_1 -a -b bbb1 -a
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
125 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
126 OPTION: b with arg: `bbb1'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
127 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
128 OPTIND: 5
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
129
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
130 Option arguments are not checked for another option syntax:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
131
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
132 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
133 $ test_noreport_1 -a -b -a
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
134 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
135 OPTION: b with arg: `-a'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
136 OPTIND: 4
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
137
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
138 Here FreeBSD's `/bin/sh` behaves like `ksh93`
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
139
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
140 Missing arguments are reported via ':' here:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
141
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
142 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
143 $ test_noreport_1 -b
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
144 ERROR: unknown option (colon): b
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
145 OPTIND: 2
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
146 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
147
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
148 No abort on errors -- unknown options are reported via '?' here:
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
149
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
150 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
151 $ test_noreport_1 -u -a
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
152 ERROR: unknown option: u
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
153 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
154 OPTIND: 3
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
155 $ test "$opt" = '?'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
156
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
157 Abort processing with '--'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
158
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
159 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
160 $ test_noreport_1 -a -b xxx -- -a -b yyy
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
161 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
162 OPTION: b with arg: `xxx'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
163 OPTIND: 5
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
164
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
165 '--' does not stop option processing when a required arg just before is missing
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
166
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
167 $ reset_getopts
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
168 $ test_noreport_1 -a -b -- -a -b yyy
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
169 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
170 OPTION: b with arg: `--'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
171 OPTION: a with arg: `'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
172 OPTION: b with arg: `yyy'
cc06815e5504 Add some tests about the behaviour of FreeBSD's /bin/sh builtin getopts().
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
173 OPTIND: 7