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