]>
Commit | Line | Data |
---|---|---|
e1033436 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git rev-parse --parseopt' | |
4 | . ./test-lib.sh | |
5 | ||
47e9cd28 TR |
6 | cat > expect <<\END_EXPECT |
7 | cat <<\EOF | |
e1033436 | 8 | usage: some-command [options] <args>... |
44d86e91 | 9 | |
e1033436 JS |
10 | some-command does foo and bar! |
11 | ||
12 | -h, --help show the help | |
13 | --foo some nifty option --foo | |
14 | --bar ... some cool option --bar with an argument | |
15 | ||
16 | An option group Header | |
6422f633 | 17 | -C[...] option C with an optional argument |
e1033436 JS |
18 | |
19 | Extras | |
20 | --extra1 line above used to cause a segfault but no longer does | |
21 | ||
22 | EOF | |
47e9cd28 | 23 | END_EXPECT |
e1033436 | 24 | |
824af25a | 25 | cat > optionspec << EOF |
e1033436 JS |
26 | some-command [options] <args>... |
27 | ||
28 | some-command does foo and bar! | |
29 | -- | |
30 | h,help show the help | |
31 | ||
32 | foo some nifty option --foo | |
33 | bar= some cool option --bar with an argument | |
34 | ||
35 | An option group Header | |
36 | C? option C with an optional argument | |
37 | ||
38 | Extras | |
39 | extra1 line above used to cause a segfault but no longer does | |
40 | EOF | |
824af25a UKK |
41 | |
42 | test_expect_success 'test --parseopt help output' ' | |
2b5ec018 | 43 | test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec && |
9a001381 | 44 | test_i18ncmp expect output |
e1033436 JS |
45 | ' |
46 | ||
824af25a UKK |
47 | cat > expect <<EOF |
48 | set -- --foo --bar 'ham' -- 'arg' | |
49 | EOF | |
50 | ||
51 | test_expect_success 'test --parseopt' ' | |
52 | git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output && | |
53 | test_cmp expect output | |
54 | ' | |
55 | ||
56 | test_expect_success 'test --parseopt with mixed options and arguments' ' | |
57 | git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output && | |
58 | test_cmp expect output | |
59 | ' | |
60 | ||
61 | cat > expect <<EOF | |
62 | set -- --foo -- 'arg' '--bar=ham' | |
63 | EOF | |
64 | ||
65 | test_expect_success 'test --parseopt with --' ' | |
66 | git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output && | |
67 | test_cmp expect output | |
68 | ' | |
69 | ||
6e0800ef UKK |
70 | test_expect_success 'test --parseopt --stop-at-non-option' ' |
71 | git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output && | |
72 | test_cmp expect output | |
73 | ' | |
74 | ||
824af25a UKK |
75 | cat > expect <<EOF |
76 | set -- --foo -- '--' 'arg' '--bar=ham' | |
77 | EOF | |
78 | ||
79 | test_expect_success 'test --parseopt --keep-dashdash' ' | |
80 | git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output && | |
81 | test_cmp expect output | |
82 | ' | |
83 | ||
29981380 UKK |
84 | cat >expect <<EOF |
85 | set -- --foo -- '--' 'arg' '--spam=ham' | |
86 | EOF | |
87 | ||
88 | test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option with --' ' | |
89 | git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output && | |
90 | test_cmp expect output | |
91 | ' | |
92 | ||
93 | cat > expect <<EOF | |
94 | set -- --foo -- 'arg' '--spam=ham' | |
95 | EOF | |
96 | ||
97 | test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option without --' ' | |
98 | git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output && | |
99 | test_cmp expect output | |
100 | ' | |
101 | ||
e1033436 | 102 | test_done |