-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sub_parser_example.sh
executable file
·109 lines (97 loc) · 3.96 KB
/
test_sub_parser_example.sh
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
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bats
VERSION_REGEX='^libClaPP\ v.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} [a-zA-Z]+\-Build: '
CLAPP_EXCEPTION_REGEX='^Caught\ ClaPP-Exception:.*$'
@test "sub-parser-example: no arguments/options given throws" {
run ./libclapp_example_sub_parser
[ "$status" -eq 0 ]
[ "${lines[0]}" = "verbose: 2" ]
[ "${lines[1]}" = "first parser not active" ]
[ "${lines[2]}" = "second parser not active" ]
}
@test "sub-parser-example: show help with long option --help" {
run ./libclapp_example_sub_parser --help
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Usage:" ]
}
@test "sub-parser-example: show help with short option -h" {
run ./libclapp_example_sub_parser -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Usage:" ]
}
@test "sub-parser-example: show version with long option --version" {
run ./libclapp_example_sub_parser --version
[ "$status" -eq 0 ]
[[ "${lines[0]}" =~ $VERSION_REGEX ]]
}
@test "sub-parser-example: give verbose options multiple times" {
run ./libclapp_example_sub_parser --verbose -v
[ "$status" -eq 0 ]
[ "${lines[0]}" = "verbose: 4" ]
[ "${lines[1]}" = "first parser not active" ]
[ "${lines[2]}" = "second parser not active" ]
}
@test "sub-parser-example: show not implemented with short option -d" {
run ./libclapp_example_sub_parser -d
[ "$status" -eq 1 ]
[ "${lines[0]}" = "Option '-d' currently not implemented: don't use it!" ]
}
@test "sub-parser-example: show not implemented with short option --debug" {
run ./libclapp_example_sub_parser --debug
[ "$status" -eq 1 ]
[ "${lines[0]}" = "Option '--debug' currently not implemented: don't use it!" ]
}
@test "sub-parser-example: first: give only mandatory short option -b" {
run ./libclapp_example_sub_parser first -b
[ "$status" -eq 0 ]
[ "${lines[0]}" = "verbose: 2" ]
[ "${lines[1]}" = "first parser active" ]
[ "${lines[2]}" = "short_bool: 1" ]
[ "${lines[3]}" = "string: not given" ]
[ "${lines[4]}" = "string-arg-x: abaa" ]
[ "${lines[5]}" = "double-opt: 10" ]
[ "${lines[6]}" = "second parser not active" ]
}
@test "sub-parser-example: first: give only mandatory short option -b and optional option -d" {
run ./libclapp_example_sub_parser first -b -d 11
[ "$status" -eq 0 ]
[ "${lines[0]}" = "verbose: 2" ]
[ "${lines[1]}" = "first parser active" ]
[ "${lines[2]}" = "short_bool: 1" ]
[ "${lines[3]}" = "string: not given" ]
[ "${lines[4]}" = "string-arg-x: abaa" ]
[ "${lines[5]}" = "double-opt: 11" ]
[ "${lines[6]}" = "second parser not active" ]
}
@test "sub-parser-example: first: give only mandatory short option -b and optional option -s" {
run ./libclapp_example_sub_parser first -b -s string
[ "$status" -eq 0 ]
[ "${lines[0]}" = "verbose: 2" ]
[ "${lines[1]}" = "first parser active" ]
[ "${lines[2]}" = "short_bool: 1" ]
[ "${lines[3]}" = "string: string" ]
[ "${lines[4]}" = "string-arg-x: abaa" ]
[ "${lines[5]}" = "double-opt: 10" ]
[ "${lines[6]}" = "second parser not active" ]
}
@test "sub-parser-example: second: give only mandatory args" {
run ./libclapp_example_sub_parser second 9 121
[ "$status" -eq 0 ]
[ "${lines[0]}" = "verbose: 2" ]
[ "${lines[1]}" = "first parser not active" ]
[ "${lines[2]}" = "second parser active" ]
[ "${lines[3]}" = "int-arg: 9" ]
[ "${lines[4]}" = "double-arg: 121" ]
[ "${lines[5]}" = "string-arg-x: default-string-arg-x" ]
[ "${lines[6]}" = "variadic-int-arg: not given" ]
}
@test "sub-parser-example: second: give only mandatory args and optional args" {
run ./libclapp_example_sub_parser second 9 121 string-arg 6 7
[ "$status" -eq 0 ]
[ "${lines[0]}" = "verbose: 2" ]
[ "${lines[1]}" = "first parser not active" ]
[ "${lines[2]}" = "second parser active" ]
[ "${lines[3]}" = "int-arg: 9" ]
[ "${lines[4]}" = "double-arg: 121" ]
[ "${lines[5]}" = "string-arg-x: string-arg" ]
[ "${lines[6]}" = "variadic-int-arg (size: 2): 6, 7, " ]
}