zsh-workers
 help / color / mirror / code / Atom feed
f6977accbbb13d5e3ad974a5d1a8290663df1a72 blob 1790 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
# Test the getopts builtin.

%prep

  test_getopts() {
    local OPTARG OPTIND opt
    local -a res
    while getopts abc: opt 2>&1; do
      [[ $opt == [?:] ]] || res+=( $opt )
    done
    (( $#res )) && print -r -- $res
    return $(( $#res ? 0 : 1 ))
  }

%test

  test_getopts
1:no arguments

  test_getopts foo
1:one operand

  test_getopts -a
0:one option
>a

  test_getopts -a foo
0:one option, one operand
>a

  test_getopts -a foo -b
0:one option, two operands, leading hyphen
>a

  test_getopts -ab
0:two options, single argument
>a b

  test_getopts -a -b
0:two options, separate arguments
>a b

  test_getopts -a -b +a
0:three options, + variant
>a b +a

  test_getopts -cx
0:one option with value, single argument
>c

  test_getopts +cx
0:one option with value, single argument, + variant
>+c

  test_getopts -c x
0:one option with value, separate arguments
>c

  test_getopts -acx
0:two options, one with value, single argument
>a c

  test_getopts -ac x
0:two options, one with value, separate arguments
>a c

  test_getopts -c
1:one option missing value
>test_getopts:3: argument expected after -c option

  test_getopts +c
1:one option missing value, + variant
>test_getopts:3: argument expected after +c option

  test_getopts -x
1:one illegal option
>test_getopts:3: bad option: -x

  test_getopts +x
1:one illegal option, + variant
>test_getopts:3: bad option: +x

  t() { local o; repeat $1 { getopts a: o "${@:2}" 2>&1 }; print -r $OPTIND }
  t 4 -a -w -e -r -a
  t 5 -a -w -e -a -w -e
  t 5 -a -w -e -r -ax -a
0:OPTIND calculation after error (workers/42248)
*>*: bad option: -e
*>*: bad option: -r
*>*: argument expected after -a option
>6
*>*: bad option: -e
*>*: bad option: -e
>7
*>*: bad option: -e
*>*: bad option: -r
*>*: argument expected after -a option
>7
debug log:

solving f6977accb ...
found f6977accb in https://inbox.vuxu.org/zsh-workers/0877C4E8-4CA3-453F-A16B-99E576F60E8D@dana.is/
found 7eba5a4b1 in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 7eba5a4b10e99d895a1061cec48312eb143f8e97	Test/B10getopts.ztst

applying [1/1] https://inbox.vuxu.org/zsh-workers/0877C4E8-4CA3-453F-A16B-99E576F60E8D@dana.is/
diff --git a/Test/B10getopts.ztst b/Test/B10getopts.ztst
index 7eba5a4b1..f6977accb 100644

Checking patch Test/B10getopts.ztst...
Applied patch Test/B10getopts.ztst cleanly.

index at:
100644 f6977accbbb13d5e3ad974a5d1a8290663df1a72	Test/B10getopts.ztst

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).