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