~dricottone/my-utils

ref: a45a21860817f3e7822235476351c31aa5929150 my-utils/core/test/ctdir.bats -rw-r--r-- 5.7 KiB
a45a2186Dominic Ricottone Rewrote tests with bats 2 years ago
                                                                                
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bats
bats_require_minimum_version 1.5.0

setup() {
  mkdir -p test/static/
  touch test/static/{a,b,c,d,e,.f,.g,.h,.i,.j}.txt
}

teardown() {
  rm -rf test/static/
}

@test "ctdir usage" {
  run --separate-stderr ctdir
  [ "$status" -eq 1 ]
  [ "$output" = "" ]
  [ "$stderr" = "Usage: ctdir TARGET [OPTIONS]" ]
}

@test "ctdir version" {
  run --separate-stderr ctdir --version
  [ "$status" -eq 0 ]
  [ "$output" = "ctdir 1.0" ]
  [ "$stderr" = "" ]
}

@test "ctdir version - quiet" {
  run --separate-stderr ctdir --version --quiet
  [ "$status" -eq 0 ]
  [ "$output" = "ctdir 1.0" ]
  [ "$stderr" = "" ]
}

@test "ctdir version - quiet short" {
  run --separate-stderr ctdir --version -q
  [ "$status" -eq 0 ]
  [ "$output" = "ctdir 1.0" ]
  [ "$stderr" = "" ]
}

@test "ctdir version short" {
  run --separate-stderr ctdir -v
  [ "$status" -eq 0 ]
  [ "$output" = "ctdir 1.0" ]
  [ "$stderr" = "" ]
}

@test "ctdir version short - quiet" {
  run --separate-stderr ctdir -v --quiet
  [ "$status" -eq 0 ]
  [ "$output" = "ctdir 1.0" ]
  [ "$stderr" = "" ]
}

@test "ctdir version short - quiet short" {
  run --separate-stderr ctdir -v -q
  [ "$status" -eq 0 ]
  [ "$output" = "ctdir 1.0" ]
  [ "$stderr" = "" ]
}

@test "ctdir help" {
  run --separate-stderr ctdir --help
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "Count entries in target directory(ies)" ]
  [ "${lines[1]}" = "Usage: ctdir TARGETS [..] [OPTIONS]" ]
  [ "${lines[2]}" = "Options:" ]
  [ "${lines[3]}" = " -h, --help     print this message and exit" ]
  [ "${lines[4]}" = " -q, --quiet    suppress error messages" ]
  [ "${lines[5]}" = " -v, --version  print version number and exit" ]
  [ "$stderr" = "" ]
}

@test "ctdir help - quiet" {
  run --separate-stderr ctdir --help --quiet
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "Count entries in target directory(ies)" ]
  [ "${lines[1]}" = "Usage: ctdir TARGETS [..] [OPTIONS]" ]
  [ "${lines[2]}" = "Options:" ]
  [ "${lines[3]}" = " -h, --help     print this message and exit" ]
  [ "${lines[4]}" = " -q, --quiet    suppress error messages" ]
  [ "${lines[5]}" = " -v, --version  print version number and exit" ]
  [ "$stderr" = "" ]
}

@test "ctdir help - quiet short" {
  run --separate-stderr ctdir --help -q
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "Count entries in target directory(ies)" ]
  [ "${lines[1]}" = "Usage: ctdir TARGETS [..] [OPTIONS]" ]
  [ "${lines[2]}" = "Options:" ]
  [ "${lines[3]}" = " -h, --help     print this message and exit" ]
  [ "${lines[4]}" = " -q, --quiet    suppress error messages" ]
  [ "${lines[5]}" = " -v, --version  print version number and exit" ]
  [ "$stderr" = "" ]
}

@test "ctdir help short" {
  run --separate-stderr ctdir -h
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "Count entries in target directory(ies)" ]
  [ "${lines[1]}" = "Usage: ctdir TARGETS [..] [OPTIONS]" ]
  [ "${lines[2]}" = "Options:" ]
  [ "${lines[3]}" = " -h, --help     print this message and exit" ]
  [ "${lines[4]}" = " -q, --quiet    suppress error messages" ]
  [ "${lines[5]}" = " -v, --version  print version number and exit" ]
  [ "$stderr" = "" ]
}

@test "ctdir help short - quiet" {
  run --separate-stderr ctdir -h --quiet
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "Count entries in target directory(ies)" ]
  [ "${lines[1]}" = "Usage: ctdir TARGETS [..] [OPTIONS]" ]
  [ "${lines[2]}" = "Options:" ]
  [ "${lines[3]}" = " -h, --help     print this message and exit" ]
  [ "${lines[4]}" = " -q, --quiet    suppress error messages" ]
  [ "${lines[5]}" = " -v, --version  print version number and exit" ]
  [ "$stderr" = "" ]
}

@test "ctdir help short - quiet short" {
  run --separate-stderr ctdir -h -q
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "Count entries in target directory(ies)" ]
  [ "${lines[1]}" = "Usage: ctdir TARGETS [..] [OPTIONS]" ]
  [ "${lines[2]}" = "Options:" ]
  [ "${lines[3]}" = " -h, --help     print this message and exit" ]
  [ "${lines[4]}" = " -q, --quiet    suppress error messages" ]
  [ "${lines[5]}" = " -v, --version  print version number and exit" ]
  [ "$stderr" = "" ]
}

@test "ctdir quiet" {
  run --separate-stderr ctdir --quiet
  [ "$status" -eq 1 ]
  [ "$output" = "" ]
  [ "$stderr" = "" ]
}

@test "ctdir quiet short" {
  run --separate-stderr ctdir -q
  [ "$status" -eq 1 ]
  [ "$output" = "" ]
  [ "$stderr" = "" ]
}

@test "ctdir no such directory" {
  run --separate-stderr ctdir foobarbaz
  [ "$status" -eq 1 ]
  [ "$output" = "" ]
  [ "$stderr" = "ctdir: No such directory 'foobarbaz'" ]
}

@test "ctdir no such directory - quiet" {
  run --separate-stderr ctdir foobarbaz --quiet
  [ "$status" -eq 1 ]
  [ "$output" = "" ]
  [ "$stderr" = "" ]
}

@test "ctdir no such directory - quiet short" {
  run --separate-stderr ctdir foobarbaz -q
  [ "$status" -eq 1 ]
  [ "$output" = "" ]
  [ "$stderr" = "" ]
}

@test "ctdir single" {
  run --separate-stderr ctdir test/static/
  [ "$status" -eq 0 ]
  [ "$output" = "10" ]
  [ "$stderr" = "" ]
}

@test "ctdir single - quiet" {
  run --separate-stderr ctdir test/static/
  [ "$status" -eq 0 ]
  [ "$output" = "10" ]
  [ "$stderr" = "" ]
}

@test "ctdir single - quiet short" {
  run --separate-stderr ctdir test/static/ --quiet
  [ "$status" -eq 0 ]
  [ "$output" = "10" ]
  [ "$stderr" = "" ]
}

@test "ctdir multiple" {
  run --separate-stderr ctdir test/static/ test/static/
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "10" ]
  [ "${lines[1]}" = "10" ]
  [ "$stderr" = "" ]
}

@test "ctdir multiple - quiet" {
  run --separate-stderr ctdir test/static/ test/static/ --quiet
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "10" ]
  [ "${lines[1]}" = "10" ]
  [ "$stderr" = "" ]
}

@test "ctdir multiple - quiet short" {
  run --separate-stderr ctdir test/static/ test/static/ -q
  [ "$status" -eq 0 ]
  [ "${lines[0]}" = "10" ]
  [ "${lines[1]}" = "10" ]
  [ "$stderr" = "" ]
}