oktest 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +156 -18
- data/Rakefile.rb +1 -1
- data/benchmark/run_all.rb +1 -0
- data/bin/oktest +3 -0
- data/lib/oktest.rb +253 -143
- data/oktest.gemspec +4 -3
- data/test/{run_all.rb → all.rb} +1 -0
- data/test/assertion_test.rb +244 -229
- data/test/filter_test.rb +123 -120
- data/test/fixture_test.rb +34 -32
- data/test/generator_test.rb +26 -22
- data/test/helper_test.rb +382 -204
- data/test/init.rb +44 -0
- data/test/mainapp_test.rb +249 -199
- data/test/matcher_test.rb +157 -126
- data/test/misc_test.rb +32 -30
- data/test/nanot.rb +307 -0
- data/test/node_test.rb +321 -242
- data/test/reporter_test.rb +250 -208
- data/test/runner_test.rb +102 -100
- data/test/util_test.rb +197 -193
- data/test/utilhelper_test.rb +36 -38
- data/test/visitor_test.rb +55 -50
- metadata +21 -7
- data/test/initialize.rb +0 -21
- data/test/tc.rb +0 -127
data/test/mainapp_test.rb
CHANGED
@@ -1,27 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
###
|
2
|
-
### $Release: 1.
|
5
|
+
### $Release: 1.5.0 $
|
3
6
|
### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
|
4
7
|
### $License: MIT License $
|
5
8
|
###
|
6
9
|
|
7
|
-
require_relative './
|
10
|
+
require_relative './init'
|
8
11
|
|
9
12
|
|
10
|
-
class
|
13
|
+
class MainApp__Test
|
14
|
+
extend NanoTest
|
15
|
+
extend Oktest::SpecHelper
|
11
16
|
|
12
|
-
def
|
17
|
+
def self.test_subject(desc, &b)
|
13
18
|
@testfile = "_tmp_test.rb"
|
14
|
-
File.write(@testfile,
|
15
|
-
|
19
|
+
File.write(@testfile, INPUT_5, encoding: 'utf-8')
|
20
|
+
color_enabled = Oktest::Config.color_enabled
|
16
21
|
Oktest::Config.color_enabled = true
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Oktest::Config.color_enabled =
|
22
|
+
#
|
23
|
+
super
|
24
|
+
ensure
|
25
|
+
Oktest::Config.color_enabled = color_enabled
|
21
26
|
File.unlink(@testfile)
|
22
27
|
end
|
23
28
|
|
24
|
-
|
29
|
+
INPUT_5 = <<'END'
|
25
30
|
require 'oktest'
|
26
31
|
|
27
32
|
Oktest.scope do
|
@@ -73,7 +78,7 @@ end
|
|
73
78
|
|
74
79
|
END
|
75
80
|
|
76
|
-
def edit_actual(output)
|
81
|
+
def self.edit_actual(output)
|
77
82
|
bkup = output.dup
|
78
83
|
output = output.gsub(/^.*\r/, '')
|
79
84
|
output = output.gsub(/^ .*(_test\.tmp:\d+)/, ' \1')
|
@@ -82,94 +87,102 @@ END
|
|
82
87
|
return output
|
83
88
|
end
|
84
89
|
|
85
|
-
def edit_expected(expected)
|
90
|
+
def self.edit_expected(expected)
|
86
91
|
expected = expected.gsub(/^ (.*:\d+)(:in `block .*)/, ' \1') if RUBY_VERSION < "1.9"
|
87
92
|
expected = plain2colored(expected)
|
88
93
|
return expected
|
89
94
|
end
|
90
95
|
|
91
96
|
|
92
|
-
|
97
|
+
test_target 'Oktest::MainApp.main()' do
|
93
98
|
|
94
|
-
def main(argv)
|
99
|
+
def self.main(argv)
|
95
100
|
ret = nil
|
96
|
-
sout, serr =
|
101
|
+
sout, serr = capture_output! do
|
97
102
|
ret = Oktest::MainApp.main(argv)
|
98
103
|
end
|
99
104
|
return ret, sout, serr
|
100
105
|
end
|
101
106
|
|
102
|
-
|
107
|
+
test_subject "[!tb6sx] returns 0 when no errors raised." do
|
103
108
|
ret, sout, serr = main(["-h"])
|
104
|
-
|
105
|
-
|
109
|
+
test_eq? ret, 0
|
110
|
+
test_eq? serr, ""
|
106
111
|
end
|
107
112
|
|
108
|
-
|
113
|
+
test_subject "[!d5mql] returns 1 when a certain error raised." do
|
109
114
|
ret, sout, serr = main(["-U"])
|
110
|
-
|
111
|
-
|
115
|
+
test_eq? ret, 1
|
116
|
+
test_eq? serr, "[ERROR] -U: Unknown option.\n"
|
112
117
|
end
|
113
118
|
|
114
|
-
|
119
|
+
test_subject "[!jr49p] reports error when unknown option specified." do
|
115
120
|
ret, sout, serr = main(["-X"])
|
116
|
-
|
117
|
-
|
121
|
+
test_eq? ret, 1
|
122
|
+
test_eq? serr, "[ERROR] -X: Unknown option.\n"
|
118
123
|
#
|
119
124
|
ret, sout, serr = main(["--foobar"])
|
120
|
-
|
121
|
-
|
125
|
+
test_eq? ret, 1
|
126
|
+
test_eq? serr, "[ERROR] --foobar: Unknown long option.\n"
|
122
127
|
end
|
123
128
|
|
124
|
-
|
129
|
+
test_subject "[!uqomj] reports error when required argument is missing." do
|
125
130
|
ret, sout, serr = main(["-s"])
|
126
|
-
|
127
|
-
|
131
|
+
test_eq? ret, 1
|
132
|
+
test_eq? serr, "[ERROR] -s: Argument required.\n"
|
128
133
|
end
|
129
134
|
|
130
|
-
|
135
|
+
test_subject "[!8i755] reports error when argument is invalid." do
|
131
136
|
ret, sout, serr = main(["-s", "foobar"])
|
132
|
-
|
133
|
-
|
137
|
+
test_eq? ret, 1
|
138
|
+
test_eq? serr, "[ERROR] -s foobar: Expected one of verbose/simple/compact/plain/quiet/v/s/c/p/q.\n"
|
134
139
|
#
|
135
140
|
ret, sout, serr = main(["-F", "aaa=*pat*"])
|
136
|
-
|
137
|
-
|
141
|
+
test_eq? ret, 1
|
142
|
+
test_eq? serr, "[ERROR] -F aaa=*pat*: Pattern unmatched.\n"
|
138
143
|
#
|
139
|
-
ret, sout, serr = main(["--color=
|
140
|
-
|
141
|
-
|
144
|
+
ret, sout, serr = main(["--color=abc"])
|
145
|
+
test_eq? ret, 1
|
146
|
+
test_eq? serr, "[ERROR] --color=abc: Boolean expected.\n"
|
142
147
|
end
|
143
148
|
|
144
149
|
end
|
145
150
|
|
146
151
|
|
147
|
-
|
152
|
+
test_target 'Oktest::MainApp#run()' do
|
148
153
|
|
149
|
-
def run(*args, tty: true)
|
154
|
+
def self.run(*args, tty: true)
|
150
155
|
ret = nil
|
151
|
-
sout, serr =
|
156
|
+
sout, serr = capture_output! "", tty: tty do
|
152
157
|
ret = Oktest::MainApp.new.run(*args)
|
153
158
|
end
|
154
159
|
return ret, sout, serr
|
155
160
|
end
|
156
161
|
|
157
|
-
|
162
|
+
test_subject "[!18qpe] runs test scripts." do
|
158
163
|
expected = <<'END'
|
159
164
|
## total:8 (<C>pass:4</C>, <R>fail:1</R>, <E>error:1</E>, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
|
160
165
|
END
|
161
166
|
ret, sout, serr = run(@testfile)
|
162
|
-
|
163
|
-
|
167
|
+
test_eq? ret, 2
|
168
|
+
test_ok? edit_actual(sout).end_with?(edit_expected(expected)), msg: "invalid status line"
|
169
|
+
end
|
170
|
+
|
171
|
+
test_subject "[!k402d] raises error if file not found." do
|
172
|
+
filename = "not-exist-file"
|
173
|
+
exc = test_exception? Benry::CmdOpt::OptionError do
|
174
|
+
run(filename)
|
175
|
+
end
|
176
|
+
test_eq? exc.message, "#{filename}: not found."
|
164
177
|
end
|
165
178
|
|
166
|
-
|
179
|
+
test_subject "[!bim36] changes auto-running to off." do
|
167
180
|
Oktest::Config.auto_run = true
|
168
181
|
_ = run(@testfile)
|
169
|
-
|
182
|
+
test_eq? Oktest::Config.auto_run, false
|
170
183
|
end
|
171
184
|
|
172
|
-
|
185
|
+
test_subject "[!hiu5b] finds test scripts in directory and runs them." do
|
173
186
|
expected = <<'END'
|
174
187
|
## total:8 (<C>pass:4</C>, <R>fail:1</R>, <E>error:1</E>, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
|
175
188
|
END
|
@@ -179,15 +192,15 @@ END
|
|
179
192
|
File.rename(@testfile, "#{dir}/d1/d2/#{@testfile}")
|
180
193
|
begin
|
181
194
|
ret, sout, serr = run(dir)
|
182
|
-
|
183
|
-
|
195
|
+
test_eq? ret, 2
|
196
|
+
test_ok? edit_actual(sout).end_with?(edit_expected(expected)), msg: "invalid status line"
|
184
197
|
ensure
|
185
198
|
File.rename("#{dir}/d1/d2/#{@testfile}", @testfile)
|
186
199
|
dirs.reverse.each {|x| Dir.rmdir(x) }
|
187
200
|
end
|
188
201
|
end
|
189
202
|
|
190
|
-
|
203
|
+
test_subject "[!v5xie] parses $OKTEST_RB environment variable." do
|
191
204
|
ret, sout, serr = run(@testfile, tty: false)
|
192
205
|
expected = plain2colored(<<'END')
|
193
206
|
## _tmp_test.rb
|
@@ -196,7 +209,7 @@ END
|
|
196
209
|
- [<C>pass</C>] 1+1 should be 2
|
197
210
|
- [<C>pass</C>] 1-1 should be 0
|
198
211
|
END
|
199
|
-
|
212
|
+
test_ok? sout.start_with?(expected), msg: "expected verbose-style, but not."
|
200
213
|
#
|
201
214
|
begin
|
202
215
|
ENV['OKTEST_RB'] = "-ss"
|
@@ -207,65 +220,88 @@ END
|
|
207
220
|
* <b>Child1</b>: <C>.</C><C>.</C>
|
208
221
|
* <b>Child2</b>: <R>f</R><E>E</E>
|
209
222
|
END
|
210
|
-
|
223
|
+
test_ok? sout.start_with?(expected), msg: "expected simple-style, but not."
|
211
224
|
ensure
|
212
225
|
ENV.delete('OKTEST_RB')
|
213
226
|
end
|
214
227
|
end
|
215
228
|
|
229
|
+
test_subject "[!tt2gj] parses command options even after filenames." do
|
230
|
+
ret, sout, serr = run(@testfile, "--version")
|
231
|
+
test_eq? ret, 0
|
232
|
+
test_eq? sout, Oktest::VERSION+"\n"
|
233
|
+
test_eq? serr, ""
|
234
|
+
end
|
235
|
+
|
216
236
|
#HELP_MESSAGE = Oktest::MainApp::HELP_MESSAGE % {command: File.basename($0)}
|
217
|
-
HELP_MESSAGE = <<"END"
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
237
|
+
HELP_MESSAGE = (<<"END") % {command: File.basename($0)}
|
238
|
+
\e[1mOktest\e[0m (#{Oktest::VERSION}) -- New style testing library
|
239
|
+
|
240
|
+
\e[36mUsage:\e[0m
|
241
|
+
$ \e[1m%{command}\e[0m [<options>] [<file|directory>...]
|
242
|
+
|
243
|
+
\e[36mOptions:\e[0m
|
244
|
+
-h, --help : show help
|
245
|
+
--version : print version
|
246
|
+
-s <reporting-style> : verbose/simple/compact/plain/quiet, or v/s/c/p/q
|
247
|
+
-F <key>=<pattern> : filter topic or spec with pattern (see below)
|
248
|
+
--color[=<on|off>] : enable/disable output coloring forcedly
|
249
|
+
-S, --skeleton : print test code skeleton
|
250
|
+
-G, --generate[=<style>] : generate test code skeleton from ruby file
|
251
|
+
|
252
|
+
\e[36mFilter Examples:\e[0m
|
253
|
+
$ %{command} -F topic=Hello # filter by topic
|
254
|
+
$ %{command} -F spec='*hello*' # filter by spec
|
255
|
+
$ %{command} -F tag=name # filter by tag name
|
256
|
+
$ %{command} -F tag!=name # negative filter by tag name
|
257
|
+
$ %{command} -F tag='{name1,name2}' # filter by multiple tag names
|
258
|
+
|
259
|
+
\e[36mDocument:\e[0m
|
260
|
+
https://github.com/kwatch/oktest/blob/ruby/ruby/README.md
|
235
261
|
END
|
236
262
|
|
237
|
-
|
263
|
+
test_subject "[!65vdx] prints help message if no arguments specified." do
|
238
264
|
expected = HELP_MESSAGE
|
239
265
|
ret, sout, serr = run()
|
240
|
-
|
241
|
-
|
242
|
-
|
266
|
+
test_eq? ret, 0
|
267
|
+
test_eq? sout, expected
|
268
|
+
test_eq? serr, ""
|
243
269
|
end
|
244
270
|
|
245
|
-
|
271
|
+
test_subject "[!9973n] '-h' or '--help' option prints help message." do
|
246
272
|
expected = HELP_MESSAGE
|
247
273
|
#
|
248
274
|
ret, sout, serr = run("-h")
|
249
|
-
|
250
|
-
|
251
|
-
|
275
|
+
test_eq? ret, 0
|
276
|
+
test_eq? sout, expected
|
277
|
+
test_eq? serr, ""
|
252
278
|
#
|
253
279
|
ret, sout, serr = run("--help")
|
254
|
-
|
255
|
-
|
256
|
-
|
280
|
+
test_eq? ret, 0
|
281
|
+
test_eq? sout, expected
|
282
|
+
test_eq? serr, ""
|
283
|
+
end
|
284
|
+
|
285
|
+
test_subject "[!v938d] help message will be colored only when stdout is a tty." do
|
286
|
+
ret, sout, serr = run("-h", tty: true)
|
287
|
+
test_ok? sout =~ /\e\[1mOktest\e\[0m/
|
288
|
+
test_ok? sout =~ /\e\[36mOptions:\e\[0m/
|
289
|
+
#
|
290
|
+
ret, sout, serr = run("-h", tty: false)
|
291
|
+
test_ok? sout !~ /\e\[1mOktest\e\[0m/
|
292
|
+
test_ok? sout !~ /\e\[36mOptions:\e\[0m/
|
257
293
|
end
|
258
294
|
|
259
|
-
|
260
|
-
expected = '$Release: 1.
|
295
|
+
test_subject "[!qqizl] '--version' option prints version number." do
|
296
|
+
expected = '$Release: 1.5.0 $'.split()[1] + "\n"
|
261
297
|
#
|
262
298
|
ret, sout, serr = run("--version")
|
263
|
-
|
264
|
-
|
265
|
-
|
299
|
+
test_eq? ret, 0
|
300
|
+
test_eq? sout, expected
|
301
|
+
test_eq? serr, ""
|
266
302
|
end
|
267
303
|
|
268
|
-
|
304
|
+
test_subject "[!0qd92] '-s verbose' or '-sv' option prints test results in verbose mode." do
|
269
305
|
expected = <<END
|
270
306
|
## _tmp_test.rb
|
271
307
|
* <b>Parent</b>
|
@@ -279,17 +315,17 @@ END
|
|
279
315
|
END
|
280
316
|
#
|
281
317
|
ret, sout, serr = run("-sv", @testfile)
|
282
|
-
|
283
|
-
|
284
|
-
|
318
|
+
test_eq? ret, 2
|
319
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
320
|
+
test_eq? serr, ""
|
285
321
|
#
|
286
322
|
ret, sout, serr = run("-s", "verbose", @testfile)
|
287
|
-
|
288
|
-
|
289
|
-
|
323
|
+
test_eq? ret, 2
|
324
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
325
|
+
test_eq? serr, ""
|
290
326
|
end
|
291
327
|
|
292
|
-
|
328
|
+
test_subject "[!zfdr5] '-s simple' or '-ss' option prints test results in simple mode." do
|
293
329
|
expected = <<END
|
294
330
|
## _tmp_test.rb
|
295
331
|
* <b>Parent</b>: <C>.</C><C>.</C>
|
@@ -299,68 +335,68 @@ END
|
|
299
335
|
END
|
300
336
|
#
|
301
337
|
ret, sout, serr = run("-ss", @testfile)
|
302
|
-
|
303
|
-
|
304
|
-
|
338
|
+
test_eq? ret, 2
|
339
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
340
|
+
test_eq? serr, ""
|
305
341
|
#
|
306
342
|
ret, sout, serr = run("-s", "simple", @testfile)
|
307
|
-
|
308
|
-
|
309
|
-
|
343
|
+
test_eq? ret, 2
|
344
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
345
|
+
test_eq? serr, ""
|
310
346
|
end
|
311
347
|
|
312
|
-
|
348
|
+
test_subject "[!ef5v7] '-s compact' or '-sc' option prints test results in compact mode." do
|
313
349
|
expected = <<END
|
314
350
|
#{@testfile}: <C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C>
|
315
351
|
----------------------------------------------------------------------
|
316
352
|
END
|
317
353
|
#
|
318
354
|
ret, sout, serr = run("-sc", @testfile)
|
319
|
-
|
320
|
-
|
321
|
-
|
355
|
+
test_eq? ret, 2
|
356
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
357
|
+
test_eq? serr, ""
|
322
358
|
#
|
323
359
|
ret, sout, serr = run("-s", "compact", @testfile)
|
324
|
-
|
325
|
-
|
326
|
-
|
360
|
+
test_eq? ret, 2
|
361
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
362
|
+
test_eq? serr, ""
|
327
363
|
end
|
328
364
|
|
329
|
-
|
365
|
+
test_subject "[!244te] '-s plain' or '-sp' option prints test results in plain mode." do
|
330
366
|
expected = <<END
|
331
367
|
<C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C>
|
332
368
|
----------------------------------------------------------------------
|
333
369
|
END
|
334
370
|
#
|
335
371
|
ret, sout, serr = run("-sp", @testfile)
|
336
|
-
|
337
|
-
|
338
|
-
|
372
|
+
test_eq? ret, 2
|
373
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
374
|
+
test_eq? serr, ""
|
339
375
|
#
|
340
376
|
ret, sout, serr = run("-s", "plain", @testfile)
|
341
|
-
|
342
|
-
|
343
|
-
|
377
|
+
test_eq? ret, 2
|
378
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
379
|
+
test_eq? serr, ""
|
344
380
|
end
|
345
381
|
|
346
|
-
|
382
|
+
test_subject "[!ai61w] '-s quiet' or '-sq' option prints test results in quiet mode." do
|
347
383
|
expected = <<END
|
348
384
|
<R>f</R><E>E</E><Y>s</Y><Y>t</Y>
|
349
385
|
----------------------------------------------------------------------
|
350
386
|
END
|
351
387
|
#
|
352
388
|
ret, sout, serr = run("-sq", @testfile)
|
353
|
-
|
354
|
-
|
355
|
-
|
389
|
+
test_eq? ret, 2
|
390
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
391
|
+
test_eq? serr, ""
|
356
392
|
#
|
357
393
|
ret, sout, serr = run("-s", "quiet", @testfile)
|
358
|
-
|
359
|
-
|
360
|
-
|
394
|
+
test_eq? ret, 2
|
395
|
+
test_ok? edit_actual(sout).start_with?(edit_expected(expected)), msg: "invalid testcase output"
|
396
|
+
test_eq? serr, ""
|
361
397
|
end
|
362
398
|
|
363
|
-
|
399
|
+
test_subject "[!yz7g5] '-F topic=...' option filters topics." do
|
364
400
|
expected = <<END
|
365
401
|
## _tmp_test.rb
|
366
402
|
* <b>Parent</b>
|
@@ -371,12 +407,12 @@ END
|
|
371
407
|
END
|
372
408
|
#
|
373
409
|
ret, sout, serr = run("-F", "topic=Child1", @testfile)
|
374
|
-
|
375
|
-
|
376
|
-
|
410
|
+
test_eq? ret, 0
|
411
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
412
|
+
test_eq? serr, ""
|
377
413
|
end
|
378
414
|
|
379
|
-
|
415
|
+
test_subject "[!ww2mp] '-F spec=...' option filters specs." do
|
380
416
|
expected = <<END
|
381
417
|
## _tmp_test.rb
|
382
418
|
* <b>Parent</b>
|
@@ -386,12 +422,12 @@ END
|
|
386
422
|
END
|
387
423
|
#
|
388
424
|
ret, sout, serr = run("-F", "spec=*1-1*", @testfile)
|
389
|
-
|
390
|
-
|
391
|
-
|
425
|
+
test_eq? ret, 0
|
426
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
427
|
+
test_eq? serr, ""
|
392
428
|
end
|
393
429
|
|
394
|
-
|
430
|
+
test_subject "[!8uvib] '-F tag=...' option filters by tag name." do
|
395
431
|
expected = <<'END'
|
396
432
|
## _tmp_test.rb
|
397
433
|
* <b>Parent</b>
|
@@ -406,12 +442,12 @@ END
|
|
406
442
|
END
|
407
443
|
#
|
408
444
|
ret, sout, serr = run("-F", "tag={new,exp}", @testfile)
|
409
|
-
|
410
|
-
|
411
|
-
|
445
|
+
test_eq? ret, 0
|
446
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
447
|
+
test_eq? serr, ""
|
412
448
|
end
|
413
449
|
|
414
|
-
|
450
|
+
test_subject "[!m0iwm] '-F sid=...' option filters by spec id." do
|
415
451
|
expected = <<'END'
|
416
452
|
## _tmp_test.rb
|
417
453
|
* <b>Parent</b>
|
@@ -421,12 +457,12 @@ END
|
|
421
457
|
END
|
422
458
|
#
|
423
459
|
ret, sout, serr = run("-F", "sid=6hs1j", @testfile)
|
424
|
-
|
425
|
-
|
426
|
-
|
460
|
+
test_eq? ret, 0
|
461
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
462
|
+
test_eq? serr, ""
|
427
463
|
end
|
428
464
|
|
429
|
-
|
465
|
+
test_subject "[!noi8i] '-F' option supports negative filter." do
|
430
466
|
expected = <<'END'
|
431
467
|
## _tmp_test.rb
|
432
468
|
* <b>Parent</b>
|
@@ -439,78 +475,73 @@ END
|
|
439
475
|
END
|
440
476
|
#
|
441
477
|
ret, sout, serr = run("-F", "tag!={fail,err,exp}", @testfile)
|
442
|
-
|
443
|
-
|
444
|
-
|
478
|
+
test_eq? ret, 0
|
479
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
480
|
+
test_eq? serr, ""
|
445
481
|
end
|
446
482
|
|
447
|
-
|
448
|
-
|
483
|
+
test_subject "[!71h2x] '-F ...' option will be error." do
|
484
|
+
exc = test_exception? Benry::CmdOpt::OptionError do
|
449
485
|
run("-F", "*pat*", @testfile)
|
450
486
|
end
|
487
|
+
test_eq? exc.message, "-F *pat*: Pattern unmatched."
|
451
488
|
end
|
452
489
|
|
453
|
-
|
490
|
+
test_subject "[!j01y7] if filerting by '-F' matched nothing, then prints zero result." do
|
454
491
|
expected = <<'END'
|
455
492
|
## total:0 (pass:0, fail:0, error:0, skip:0, todo:0) in 0.000s
|
456
493
|
END
|
457
494
|
#
|
458
495
|
ret, sout, serr = run("-F", "tag=blablabla", @testfile)
|
459
|
-
|
460
|
-
|
461
|
-
|
496
|
+
test_eq? ret, 0
|
497
|
+
test_eq? edit_actual(sout), edit_expected(expected)
|
498
|
+
test_eq? serr, ""
|
462
499
|
end
|
463
500
|
|
464
|
-
|
501
|
+
test_subject "[!6ro7j] '--color=on' option enables output coloring forcedly." do
|
465
502
|
[true, false].each do |bool|
|
466
503
|
[true, false].each do |tty|
|
467
504
|
Oktest::Config.color_enabled = bool
|
468
505
|
_, sout, serr = run("--color=on", @testfile, tty: tty)
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
506
|
+
test_ok? sout.include?(edit_expected("[<C>pass</C>]")), msg: "should contain blue string"
|
507
|
+
test_ok? sout.include?(edit_expected("[<R>Fail</R>]")), msg: "should contain red string"
|
508
|
+
test_ok? sout.include?(edit_expected("[<Y>Skip</Y>]")), msg: "should contain yellos string"
|
509
|
+
test_eq? serr, ""
|
473
510
|
end
|
474
511
|
end
|
475
512
|
end
|
476
513
|
|
477
|
-
|
514
|
+
test_subject "[!dptgn] '--color' is same as '--color=on'." do
|
478
515
|
[true, false].each do |bool|
|
479
516
|
[true, false].each do |tty|
|
480
517
|
Oktest::Config.color_enabled = bool
|
481
518
|
_, sout, serr = run("--color", @testfile, tty: tty)
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
519
|
+
test_ok? sout.include?(edit_expected("[<C>pass</C>]")), msg: "should contain blue string"
|
520
|
+
test_ok? sout.include?(edit_expected("[<R>Fail</R>]")), msg: "should contain red string"
|
521
|
+
test_ok? sout.include?(edit_expected("[<Y>Skip</Y>]")), msg: "should contain yellos string"
|
522
|
+
test_eq? serr, ""
|
486
523
|
end
|
487
524
|
end
|
488
525
|
end
|
489
526
|
|
490
|
-
|
527
|
+
test_subject "[!vmw0q] '--color=off' option disables output coloring forcedly." do
|
491
528
|
[true, false].each do |bool|
|
492
529
|
[true, false].each do |tty|
|
493
530
|
Oktest::Config.color_enabled = bool
|
494
531
|
_, sout, serr = run("--color=off", @testfile, tty: tty)
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
532
|
+
test_ok? !sout.include?(edit_expected("[<C>pass</C>]")), msg: "should not contain blue string"
|
533
|
+
test_ok? !sout.include?(edit_expected("[<R>Fail</R>]")), msg: "should not contain red string"
|
534
|
+
test_ok? !sout.include?(edit_expected("[<Y>Skip</Y>]")), msg: "should not contain yellos string"
|
535
|
+
test_eq? serr, ""
|
499
536
|
end
|
500
537
|
end
|
501
538
|
end
|
502
539
|
|
503
|
-
|
504
|
-
assert_exc(OptionParser::InvalidArgument, "invalid argument: --color=true") do
|
505
|
-
run("--color=true", @testfile)
|
506
|
-
end
|
507
|
-
end
|
508
|
-
|
509
|
-
it "[!dk8eg] '-S' or '--skeleton' option prints test code skeleton." do
|
540
|
+
test_subject "[!dk8eg] '-S' or '--skeleton' option prints test code skeleton." do
|
510
541
|
ret, sout, serr = run("-S")
|
511
|
-
|
512
|
-
|
513
|
-
|
542
|
+
test_eq? ret, 0
|
543
|
+
test_eq? sout, Oktest::MainApp.new.__send__(:skeleton)
|
544
|
+
test_eq? serr, ""
|
514
545
|
end
|
515
546
|
|
516
547
|
HELLO_CLASS_DEF = <<'END'
|
@@ -526,7 +557,7 @@ class Hello
|
|
526
557
|
end
|
527
558
|
END
|
528
559
|
|
529
|
-
|
560
|
+
test_subject "[!uxh5e] '-G' or '--generate' option prints test code." do
|
530
561
|
input = HELLO_CLASS_DEF
|
531
562
|
filename = "_tmpcode_4674.rb"
|
532
563
|
File.write(filename, input)
|
@@ -547,7 +578,7 @@ Oktest.scope do
|
|
547
578
|
|
548
579
|
spec "returns greeting message."
|
549
580
|
|
550
|
-
end
|
581
|
+
end
|
551
582
|
|
552
583
|
|
553
584
|
end # Hello
|
@@ -558,20 +589,20 @@ END
|
|
558
589
|
#
|
559
590
|
begin
|
560
591
|
ret, sout, serr = run("-G", filename)
|
561
|
-
|
562
|
-
|
563
|
-
|
592
|
+
test_eq? ret, 0
|
593
|
+
test_eq? sout, expected
|
594
|
+
test_eq? serr, ""
|
564
595
|
#
|
565
596
|
ret, sout, serr = run("--generate", filename)
|
566
|
-
|
567
|
-
|
568
|
-
|
597
|
+
test_eq? ret, 0
|
598
|
+
test_eq? sout, expected
|
599
|
+
test_eq? serr, ""
|
569
600
|
ensure
|
570
601
|
File.unlink(filename)
|
571
602
|
end
|
572
603
|
end
|
573
604
|
|
574
|
-
|
605
|
+
test_subject "[!wmxu5] '--generate=unaryop' option prints test code with unary op." do
|
575
606
|
input = HELLO_CLASS_DEF
|
576
607
|
filename = "_tmpcode_6431.rb"
|
577
608
|
File.write(filename, input)
|
@@ -592,7 +623,7 @@ Oktest.scope do
|
|
592
623
|
|
593
624
|
- spec("returns greeting message.")
|
594
625
|
|
595
|
-
end
|
626
|
+
end
|
596
627
|
|
597
628
|
|
598
629
|
end # Hello
|
@@ -602,31 +633,31 @@ end
|
|
602
633
|
END
|
603
634
|
#
|
604
635
|
begin
|
605
|
-
ret, sout, serr = run("-
|
606
|
-
|
607
|
-
|
608
|
-
|
636
|
+
ret, sout, serr = run("-Gunaryop", filename)
|
637
|
+
test_eq? ret, 0
|
638
|
+
test_eq? sout, expected
|
639
|
+
test_eq? serr, ""
|
609
640
|
#
|
610
641
|
ret, sout, serr = run("--generate=unaryop", filename)
|
611
|
-
|
612
|
-
|
613
|
-
|
642
|
+
test_eq? ret, 0
|
643
|
+
test_eq? sout, expected
|
644
|
+
test_eq? serr, ""
|
614
645
|
ensure
|
615
646
|
File.unlink(filename)
|
616
647
|
end
|
617
648
|
end
|
618
649
|
|
619
|
-
|
620
|
-
|
650
|
+
test_subject "[!qs8ab] '--faster' chanages 'Config.ok_location' to false." do
|
651
|
+
test_eq? Oktest::Config.ok_location, true
|
621
652
|
begin
|
622
653
|
run("--faster", @testfile)
|
623
|
-
|
654
|
+
test_eq? Oktest::Config.ok_location, false
|
624
655
|
ensure
|
625
656
|
Oktest::Config.ok_location = true
|
626
657
|
end
|
627
658
|
end
|
628
659
|
|
629
|
-
|
660
|
+
test_subject "[!dsrae] reports if 'ok()' called but assertion not performed." do
|
630
661
|
input = <<'END'
|
631
662
|
require 'oktest'
|
632
663
|
Oktest.scope do
|
@@ -649,23 +680,23 @@ END
|
|
649
680
|
** warning: ok() is called but not tested yet (at #{@testfile}:11:in `block (3 levels) in <top (required)>').
|
650
681
|
END
|
651
682
|
ret, sout, serr = run(@testfile)
|
652
|
-
|
653
|
-
|
683
|
+
test_eq? ret, 1
|
684
|
+
test_eq? serr, expected
|
654
685
|
end
|
655
686
|
|
656
|
-
|
687
|
+
test_subject "[!bzgiw] returns total number of failures and errors." do
|
657
688
|
ret, sout, serr = run(@testfile)
|
658
|
-
|
689
|
+
test_eq? ret, 2 # 1 failure, 1 error
|
659
690
|
end
|
660
691
|
|
661
|
-
|
692
|
+
test_subject "[!937kw] recovers 'Config.color_enabled' value." do
|
662
693
|
bkup = Oktest::Config.color_enabled
|
663
694
|
begin
|
664
695
|
[true, false].each do |bool|
|
665
696
|
["on", "off"].each do |flag|
|
666
697
|
Oktest::Config.color_enabled = bool
|
667
698
|
run(@testfile, "--color=#{flag}")
|
668
|
-
|
699
|
+
test_eq? Oktest::Config.color_enabled, bool
|
669
700
|
end
|
670
701
|
end
|
671
702
|
ensure
|
@@ -675,4 +706,23 @@ END
|
|
675
706
|
|
676
707
|
end
|
677
708
|
|
709
|
+
test_target 'Oktest::MainApp#skeleton()' do
|
710
|
+
test_subject "[!s2i1p] returns skeleton string of test script." do
|
711
|
+
str = Oktest::MainApp.new.__send__(:skeleton)
|
712
|
+
test_match? str, /^require 'oktest'$/
|
713
|
+
test_match? str, /^Oktest\.scope do$/
|
714
|
+
end
|
715
|
+
test_subject "[!opvik] skeleton string is valid ruby code." do
|
716
|
+
str = Oktest::MainApp.new.__send__(:skeleton)
|
717
|
+
filename = "tmp.skeleton.rb"
|
718
|
+
File.write(filename, str, encoding: 'utf-8')
|
719
|
+
begin
|
720
|
+
result = `ruby -wc #{filename}` # may reports warning
|
721
|
+
test_eq? result, "Syntax OK\n"
|
722
|
+
ensure
|
723
|
+
File.unlink filename
|
724
|
+
end
|
725
|
+
end
|
726
|
+
end
|
727
|
+
|
678
728
|
end
|