oktest 1.0.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.
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ###
4
+ ### $Release: 1.0.0 $
5
+ ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
6
+ ### $License: MIT License $
7
+ ###
8
+
9
+ File.class_eval do
10
+ $LOAD_PATH << join(dirname(dirname(expand_path(__FILE__))), 'lib')
11
+ end
12
+
13
+ require_relative './tc'
14
+ require 'oktest'
@@ -0,0 +1,625 @@
1
+ ###
2
+ ### $Release: 1.0.0 $
3
+ ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
4
+ ### $License: MIT License $
5
+ ###
6
+
7
+ require_relative './initialize'
8
+
9
+
10
+ class MainApp_TC < TC
11
+
12
+ def setup
13
+ @testfile = "_tmp_test.rb"
14
+ File.write(@testfile, INPUT, encoding: 'utf-8')
15
+ @_color_enabled = Oktest::Config.color_enabled
16
+ Oktest::Config.color_enabled = true
17
+ end
18
+
19
+ def teardown
20
+ Oktest::Config.color_enabled = @_color_enabled
21
+ File.unlink(@testfile)
22
+ end
23
+
24
+ INPUT = <<'END'
25
+ require 'oktest'
26
+
27
+ Oktest.scope do
28
+
29
+ topic "Parent" do
30
+
31
+ topic "Child1" do
32
+ spec "1+1 should be 2" do
33
+ ok {1+1} == 2
34
+ end
35
+ spec "1-1 should be 0", tag: 'new' do
36
+ ok {1-1} == 0
37
+ end
38
+ end
39
+
40
+ topic "Child2" do
41
+ spec "1*1 should be 1", tag: 'fail' do
42
+ ok {1*1} == 2
43
+ end
44
+ spec "1/1 should be 1", tag: 'err' do
45
+ ok {1/0} == 1
46
+ end
47
+ end
48
+
49
+ topic "Child3", tag: ['exp', 'new'] do
50
+ spec "skip example" do
51
+ skip_when true, "a certain condition"
52
+ end
53
+ spec "todo example"
54
+ end
55
+
56
+ case_when "x is negative", tag: 'exp' do
57
+ spec "[!6hs1j] x*x is positive." do
58
+ x = -2
59
+ ok {x*x} > 0
60
+ end
61
+ end
62
+
63
+ case_else do
64
+ spec "[!pwiq7] x*x is also positive." do
65
+ x = 2
66
+ ok {x*x} > 0
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ END
75
+
76
+ def plain2colored(str)
77
+ str = str.gsub(/<R>(.*?)<\/R>/) { Oktest::Color.red($1) }
78
+ str = str.gsub(/<G>(.*?)<\/G>/) { Oktest::Color.green($1) }
79
+ str = str.gsub(/<B>(.*?)<\/B>/) { Oktest::Color.blue($1) }
80
+ str = str.gsub(/<Y>(.*?)<\/Y>/) { Oktest::Color.yellow($1) }
81
+ str = str.gsub(/<b>(.*?)<\/b>/) { Oktest::Color.bold($1) }
82
+ return str
83
+ end
84
+
85
+ def edit_actual(output)
86
+ bkup = output.dup
87
+ output = output.gsub(/^.*\r/, '')
88
+ output = output.gsub(/^ .*(_test\.tmp:\d+)/, ' \1')
89
+ output = output.gsub(/^ .*test.reporter_test\.rb:.*\n( .*\n)*/, "%%%\n")
90
+ output = output.sub(/ in \d+\.\d\d\ds/, ' in 0.000s')
91
+ return output
92
+ end
93
+
94
+ def edit_expected(expected)
95
+ expected = expected.gsub(/^ (.*:\d+)(:in `block .*)/, ' \1') if RUBY_VERSION < "1.9"
96
+ expected = plain2colored(expected)
97
+ return expected
98
+ end
99
+
100
+
101
+ describe '.main()' do
102
+
103
+ def main(argv)
104
+ ret = nil
105
+ sout, serr = capture do
106
+ ret = Oktest::MainApp.main(argv)
107
+ end
108
+ return ret, sout, serr
109
+ end
110
+
111
+ it "[!tb6sx] returns 0 when no errors raised." do
112
+ ret, sout, serr = main(["-h"])
113
+ assert_eq ret, 0
114
+ assert_eq serr, ""
115
+ end
116
+
117
+ it "[!d5mql] returns 1 when a certain error raised." do
118
+ ret, sout, serr = main(["-U"])
119
+ assert_eq ret, 1
120
+ assert_eq serr, "#{File.basename($0)}: -U: unknown option.\n"
121
+ end
122
+
123
+ it "[!jr49p] reports error when unknown option specified." do
124
+ ret, sout, serr = main(["-X"])
125
+ assert_eq ret, 1
126
+ assert_eq serr, "#{File.basename($0)}: -X: unknown option.\n"
127
+ #
128
+ ret, sout, serr = main(["--foobar"])
129
+ assert_eq ret, 1
130
+ assert_eq serr, "#{File.basename($0)}: --foobar: unknown option.\n"
131
+ end
132
+
133
+ it "[!uqomj] reports error when required argument is missing." do
134
+ ret, sout, serr = main(["-s"])
135
+ assert_eq ret, 1
136
+ assert_eq serr, "#{File.basename($0)}: -s: argument required.\n"
137
+ end
138
+
139
+ it "[!8i755] reports error when argument is invalid." do
140
+ ret, sout, serr = main(["-s", "foobar"])
141
+ assert_eq ret, 1
142
+ assert_eq serr, "#{File.basename($0)}: -s foobar: invalid argument.\n"
143
+ #
144
+ ret, sout, serr = main(["-F", "aaa=*pat*"])
145
+ assert_eq ret, 1
146
+ assert_eq serr, "#{File.basename($0)}: -F aaa=*pat*: invalid argument.\n"
147
+ #
148
+ ret, sout, serr = main(["--color=true"])
149
+ assert_eq ret, 1
150
+ assert_eq serr, "#{File.basename($0)}: --color=true: invalid argument.\n"
151
+ end
152
+
153
+ end
154
+
155
+
156
+ describe '#run()' do
157
+
158
+ def run(*args, tty: true)
159
+ ret = nil
160
+ sout, serr = capture("", tty: tty) do
161
+ ret = Oktest::MainApp.new.run(*args)
162
+ end
163
+ return ret, sout, serr
164
+ end
165
+
166
+ it "[!18qpe] runs test scripts." do
167
+ expected = <<'END'
168
+ ## total:8 (<B>pass:4</B>, <R>fail:1</R>, <R>error:1</R>, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
169
+ END
170
+ ret, sout, serr = run(@testfile)
171
+ assert_eq ret, 2
172
+ assert edit_actual(sout).end_with?(edit_expected(expected)), "invalid status line"
173
+ end
174
+
175
+ it "[!bim36] changes auto-running to off." do
176
+ Oktest::Config.auto_run = true
177
+ _ = run(@testfile)
178
+ assert_eq Oktest::Config.auto_run, false
179
+ end
180
+
181
+ it "[!hiu5b] finds test scripts in directory and runs them." do
182
+ expected = <<'END'
183
+ ## total:8 (<B>pass:4</B>, <R>fail:1</R>, <R>error:1</R>, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
184
+ END
185
+ dir = "_tmpdir.d"
186
+ dirs = [dir, "#{dir}/d1", "#{dir}/d1/d2"]
187
+ dirs.each {|x| Dir.mkdir(x) unless File.directory?(x) }
188
+ File.rename(@testfile, "#{dir}/d1/d2/#{@testfile}")
189
+ begin
190
+ ret, sout, serr = run(dir)
191
+ assert_eq ret, 2
192
+ assert edit_actual(sout).end_with?(edit_expected(expected)), "invalid status line"
193
+ ensure
194
+ File.rename("#{dir}/d1/d2/#{@testfile}", @testfile)
195
+ dirs.reverse.each {|x| Dir.rmdir(x) }
196
+ end
197
+ end
198
+
199
+ #HELP_MESSAGE = Oktest::MainApp::HELP_MESSAGE % {command: File.basename($0)}
200
+ HELP_MESSAGE = <<"END"
201
+ Usage: #{File.basename($0)} [<options>] [<file-or-directory>...]
202
+ -h, --help : show help
203
+ --version : print version
204
+ -s <STYLE> : report style (verbose/simple/plain/quiet, or v/s/p/q)
205
+ -F <PATTERN> : filter topic or spec with pattern (see below)
206
+ --color[={on|off}] : enable/disable output coloring forcedly
207
+ -C, --create : print test code skeleton
208
+ -G, --generate : generate test code skeleton from ruby file
209
+ --faster : make 'ok{}' faster (for very large project)
210
+
211
+ Filter examples:
212
+ $ oktest -F topic=Hello # filter by topic
213
+ $ oktest -F spec='*hello*' # filter by spec
214
+ $ oktest -F tag=name # filter by tag name
215
+ $ oktest -F tag!=name # negative filter by tag name
216
+ $ oktest -F tag='{name1,name2}' # filter by multiple tag names
217
+
218
+ See https://github.com/kwatch/oktest/blob/ruby/ruby/README.md for details.
219
+ END
220
+
221
+ it "[!65vdx] prints help message if no arguments specified." do
222
+ expected = HELP_MESSAGE
223
+ ret, sout, serr = run()
224
+ assert_eq ret, 0
225
+ assert_eq sout, expected
226
+ assert_eq serr, ""
227
+ end
228
+
229
+ it "[!9973n] '-h' or '--help' option prints help message." do
230
+ expected = HELP_MESSAGE
231
+ #
232
+ ret, sout, serr = run("-h")
233
+ assert_eq ret, 0
234
+ assert_eq sout, expected
235
+ assert_eq serr, ""
236
+ #
237
+ ret, sout, serr = run("--help")
238
+ assert_eq ret, 0
239
+ assert_eq sout, expected
240
+ assert_eq serr, ""
241
+ end
242
+
243
+ it "[!qqizl] '--version' option prints version number." do
244
+ expected = '$Release: 1.0.0 $'.split()[1] + "\n"
245
+ #
246
+ ret, sout, serr = run("--version")
247
+ assert_eq ret, 0
248
+ assert_eq sout, expected
249
+ assert_eq serr, ""
250
+ end
251
+
252
+ it "[!0qd92] '-s verbose' or '-sv' option prints test results in verbose mode." do
253
+ expected = <<END
254
+ * <b>Parent</b>
255
+ * <b>Child1</b>
256
+ - [<B>pass</B>] 1+1 should be 2
257
+ - [<B>pass</B>] 1-1 should be 0
258
+ * <b>Child2</b>
259
+ - [<R>Fail</R>] 1*1 should be 1
260
+ - [<R>ERROR</R>] 1/1 should be 1
261
+ ----------------------------------------------------------------------
262
+ END
263
+ #
264
+ ret, sout, serr = run("-sv", @testfile)
265
+ assert_eq ret, 2
266
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
267
+ assert_eq serr, ""
268
+ #
269
+ ret, sout, serr = run("-s", "verbose", @testfile)
270
+ assert_eq ret, 2
271
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
272
+ assert_eq serr, ""
273
+ end
274
+
275
+ it "[!ef5v7] '-s simple' or '-ss' option prints test results in simple mode." do
276
+ expected = <<END
277
+ #{@testfile}: <B>.</B><B>.</B><R>f</R><R>E</R><Y>s</Y><Y>t</Y><B>.</B><B>.</B>
278
+ ----------------------------------------------------------------------
279
+ END
280
+ #
281
+ ret, sout, serr = run("-ss", @testfile)
282
+ assert_eq ret, 2
283
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
284
+ assert_eq serr, ""
285
+ #
286
+ ret, sout, serr = run("-s", "simple", @testfile)
287
+ assert_eq ret, 2
288
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
289
+ assert_eq serr, ""
290
+ end
291
+
292
+ it "[!244te] '-s plain' or '-sp' option prints test results in plain mode." do
293
+ expected = <<END
294
+ <B>.</B><B>.</B><R>f</R><R>E</R><Y>s</Y><Y>t</Y><B>.</B><B>.</B>
295
+ ----------------------------------------------------------------------
296
+ END
297
+ #
298
+ ret, sout, serr = run("-sp", @testfile)
299
+ assert_eq ret, 2
300
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
301
+ assert_eq serr, ""
302
+ #
303
+ ret, sout, serr = run("-s", "plain", @testfile)
304
+ assert_eq ret, 2
305
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
306
+ assert_eq serr, ""
307
+ end
308
+
309
+ it "[!ai61w] '-s quiet' or '-sq' option prints test results in quiet mode." do
310
+ expected = <<END
311
+ <R>f</R><R>E</R><Y>s</Y><Y>t</Y>
312
+ ----------------------------------------------------------------------
313
+ END
314
+ #
315
+ ret, sout, serr = run("-sq", @testfile)
316
+ assert_eq ret, 2
317
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
318
+ assert_eq serr, ""
319
+ #
320
+ ret, sout, serr = run("-s", "quiet", @testfile)
321
+ assert_eq ret, 2
322
+ assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
323
+ assert_eq serr, ""
324
+ end
325
+
326
+ it "[!yz7g5] '-F topic=...' option filters topics." do
327
+ expected = <<END
328
+ * <b>Parent</b>
329
+ * <b>Child1</b>
330
+ - [<B>pass</B>] 1+1 should be 2
331
+ - [<B>pass</B>] 1-1 should be 0
332
+ ## total:2 (<B>pass:2</B>, fail:0, error:0, skip:0, todo:0) in 0.000s
333
+ END
334
+ #
335
+ ret, sout, serr = run("-F", "topic=Child1", @testfile)
336
+ assert_eq ret, 0
337
+ assert_eq edit_actual(sout), edit_expected(expected)
338
+ assert_eq serr, ""
339
+ end
340
+
341
+ it "[!ww2mp] '-F spec=...' option filters specs." do
342
+ expected = <<END
343
+ * <b>Parent</b>
344
+ * <b>Child1</b>
345
+ - [<B>pass</B>] 1-1 should be 0
346
+ ## total:1 (<B>pass:1</B>, fail:0, error:0, skip:0, todo:0) in 0.000s
347
+ END
348
+ #
349
+ ret, sout, serr = run("-F", "spec=*1-1*", @testfile)
350
+ assert_eq ret, 0
351
+ assert_eq edit_actual(sout), edit_expected(expected)
352
+ assert_eq serr, ""
353
+ end
354
+
355
+ it "[!8uvib] '-F tag=...' option filters by tag name." do
356
+ expected = <<'END'
357
+ * <b>Parent</b>
358
+ * <b>Child1</b>
359
+ - [<B>pass</B>] 1-1 should be 0
360
+ * <b>Child3</b>
361
+ - [<Y>Skip</Y>] skip example <Y>(reason: a certain condition)</Y>
362
+ - [<Y>TODO</Y>] todo example
363
+ - <b>When x is negative</b>
364
+ - [<B>pass</B>] [!6hs1j] x*x is positive.
365
+ ## total:4 (<B>pass:2</B>, fail:0, error:0, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
366
+ END
367
+ #
368
+ ret, sout, serr = run("-F", "tag={new,exp}", @testfile)
369
+ assert_eq ret, 0
370
+ assert_eq edit_actual(sout), edit_expected(expected)
371
+ assert_eq serr, ""
372
+ end
373
+
374
+ it "[!m0iwm] '-F sid=...' option filters by spec id." do
375
+ expected = <<'END'
376
+ * <b>Parent</b>
377
+ - <b>When x is negative</b>
378
+ - [<B>pass</B>] [!6hs1j] x*x is positive.
379
+ ## total:1 (<B>pass:1</B>, fail:0, error:0, skip:0, todo:0) in 0.000s
380
+ END
381
+ #
382
+ ret, sout, serr = run("-F", "sid=6hs1j", @testfile)
383
+ assert_eq ret, 0
384
+ assert_eq edit_actual(sout), edit_expected(expected)
385
+ assert_eq serr, ""
386
+ end
387
+
388
+ it "[!noi8i] '-F' option supports negative filter." do
389
+ expected = <<'END'
390
+ * <b>Parent</b>
391
+ * <b>Child1</b>
392
+ - [<B>pass</B>] 1+1 should be 2
393
+ - [<B>pass</B>] 1-1 should be 0
394
+ - <b>Else</b>
395
+ - [<B>pass</B>] [!pwiq7] x*x is also positive.
396
+ ## total:3 (<B>pass:3</B>, fail:0, error:0, skip:0, todo:0) in 0.000s
397
+ END
398
+ #
399
+ ret, sout, serr = run("-F", "tag!={fail,err,exp}", @testfile)
400
+ assert_eq ret, 0
401
+ assert_eq edit_actual(sout), edit_expected(expected)
402
+ assert_eq serr, ""
403
+ end
404
+
405
+ it "[!71h2x] '-F ...' option will be error." do
406
+ assert_exc(OptionParser::InvalidArgument, "invalid argument: -F *pat*") do
407
+ run("-F", "*pat*", @testfile)
408
+ end
409
+ end
410
+
411
+ it "[!6ro7j] '--color=on' option enables output coloring forcedly." do
412
+ [true, false].each do |bool|
413
+ [true, false].each do |tty|
414
+ Oktest::Config.color_enabled = bool
415
+ _, sout, serr = run("--color=on", @testfile, tty: tty)
416
+ assert sout.include?(edit_expected("[<B>pass</B>]")), "should contain blue string"
417
+ assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
418
+ assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
419
+ assert_eq serr, ""
420
+ end
421
+ end
422
+ end
423
+
424
+ it "[!dptgn] '--color' is same as '--color=on'." do
425
+ [true, false].each do |bool|
426
+ [true, false].each do |tty|
427
+ Oktest::Config.color_enabled = bool
428
+ _, sout, serr = run("--color", @testfile, tty: tty)
429
+ assert sout.include?(edit_expected("[<B>pass</B>]")), "should contain blue string"
430
+ assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
431
+ assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
432
+ assert_eq serr, ""
433
+ end
434
+ end
435
+ end
436
+
437
+ it "[!vmw0q] '--color=off' option disables output coloring forcedly." do
438
+ [true, false].each do |bool|
439
+ [true, false].each do |tty|
440
+ Oktest::Config.color_enabled = bool
441
+ _, sout, serr = run("--color=off", @testfile, tty: tty)
442
+ assert !sout.include?(edit_expected("[<B>pass</B>]")), "should not contain blue string"
443
+ assert !sout.include?(edit_expected("[<R>Fail</R>]")), "should not contain red string"
444
+ assert !sout.include?(edit_expected("[<Y>Skip</Y>]")), "should not contain yellos string"
445
+ assert_eq serr, ""
446
+ end
447
+ end
448
+ end
449
+
450
+ it "[!9nr94] '--color=true' option raises error." do
451
+ assert_exc(OptionParser::InvalidArgument, "invalid argument: --color=true") do
452
+ run("--color=true", @testfile)
453
+ end
454
+ end
455
+
456
+ it "[!dk8eg] '-C' or '--create' option prints test code skeleton." do
457
+ ret, sout, serr = run("-C")
458
+ assert_eq ret, 0
459
+ assert_eq sout, Oktest::MainApp::SKELETON
460
+ assert_eq serr, ""
461
+ end
462
+
463
+ HELLO_CLASS_DEF = <<'END'
464
+ class Hello
465
+ def hello(name=nil)
466
+ #; default name is 'world'.
467
+ if name.nil?
468
+ name = "world"
469
+ end
470
+ #; returns greeting message.
471
+ return "Hello, #{name}!"
472
+ end
473
+ end
474
+ END
475
+
476
+ it "[!uxh5e] '-G' or '--generate' option prints test code." do
477
+ input = HELLO_CLASS_DEF
478
+ filename = "_tmpcode_4674.rb"
479
+ File.write(filename, input)
480
+ expected = <<END
481
+ # coding: utf-8
482
+
483
+ require 'oktest'
484
+
485
+ Oktest.scope do
486
+
487
+
488
+ topic Hello do
489
+
490
+
491
+ topic '#hello()' do
492
+
493
+ spec "default name is 'world'."
494
+
495
+ spec "returns greeting message."
496
+
497
+ end # #hello()
498
+
499
+
500
+ end # Hello
501
+
502
+
503
+ end
504
+ END
505
+ #
506
+ begin
507
+ ret, sout, serr = run("-G", filename)
508
+ assert_eq ret, 0
509
+ assert_eq sout, expected
510
+ assert_eq serr, ""
511
+ #
512
+ ret, sout, serr = run("--generate", filename)
513
+ assert_eq ret, 0
514
+ assert_eq sout, expected
515
+ assert_eq serr, ""
516
+ ensure
517
+ File.unlink(filename)
518
+ end
519
+ end
520
+
521
+ it "[!wmxu5] '--generate=unaryop' option prints test code with unary op." do
522
+ input = HELLO_CLASS_DEF
523
+ filename = "_tmpcode_6431.rb"
524
+ File.write(filename, input)
525
+ expected = <<END
526
+ # coding: utf-8
527
+
528
+ require 'oktest'
529
+
530
+ Oktest.scope do
531
+
532
+
533
+ + topic(Hello) do
534
+
535
+
536
+ + topic('#hello()') do
537
+
538
+ - spec("default name is 'world'.")
539
+
540
+ - spec("returns greeting message.")
541
+
542
+ end # #hello()
543
+
544
+
545
+ end # Hello
546
+
547
+
548
+ end
549
+ END
550
+ #
551
+ begin
552
+ ret, sout, serr = run("-gunaryop", filename)
553
+ assert_eq ret, 0
554
+ assert_eq sout, expected
555
+ assert_eq serr, ""
556
+ #
557
+ ret, sout, serr = run("--generate=unaryop", filename)
558
+ assert_eq ret, 0
559
+ assert_eq sout, expected
560
+ assert_eq serr, ""
561
+ ensure
562
+ File.unlink(filename)
563
+ end
564
+ end
565
+
566
+ it "[!qs8ab] '--faster' chanages 'Config.ok_location' to false." do
567
+ assert_eq Oktest::Config.ok_location, true
568
+ begin
569
+ run("--faster", @testfile)
570
+ assert_eq Oktest::Config.ok_location, false
571
+ ensure
572
+ Oktest::Config.ok_location = true
573
+ end
574
+ end
575
+
576
+ it "[!dsrae] reports if 'ok()' called but assertion not performed." do
577
+ input = <<'END'
578
+ require 'oktest'
579
+ Oktest.scope do
580
+ topic 'Example' do
581
+ spec 'sample #1' do
582
+ ok {1+1} == 2 # assertion performed
583
+ end
584
+ spec 'sample #2' do
585
+ ok {1+1} # ok() called but assertion not performed
586
+ end
587
+ spec 'sample #3' do
588
+ ok {'abc'}.start_with?(str) # assetion not performed unexpectedly
589
+ end
590
+ end
591
+ end
592
+ END
593
+ File.write(@testfile, input)
594
+ expected = <<END
595
+ ** warning: ok() is called but not tested yet (at #{@testfile}:8:in `block (3 levels) in <top (required)>').
596
+ ** warning: ok() is called but not tested yet (at #{@testfile}:11:in `block (3 levels) in <top (required)>').
597
+ END
598
+ ret, sout, serr = run(@testfile)
599
+ assert_eq ret, 1
600
+ assert_eq serr, expected
601
+ end
602
+
603
+ it "[!bzgiw] returns total number of failures and errors." do
604
+ ret, sout, serr = run(@testfile)
605
+ assert_eq ret, 2 # 1 failure, 1 error
606
+ end
607
+
608
+ it "[!937kw] recovers 'Config.color_enabled' value." do
609
+ bkup = Oktest::Config.color_enabled
610
+ begin
611
+ [true, false].each do |bool|
612
+ ["on", "off"].each do |flag|
613
+ Oktest::Config.color_enabled = bool
614
+ run(@testfile, "--color=#{flag}")
615
+ assert_eq Oktest::Config.color_enabled, bool
616
+ end
617
+ end
618
+ ensure
619
+ Oktest::Config.color_enabled = bkup
620
+ end
621
+ end
622
+
623
+ end
624
+
625
+ end