oktest 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +197 -22
- data/Rakefile.rb +5 -2
- data/benchmark/Rakefile.rb +4 -0
- data/lib/oktest.rb +170 -58
- data/oktest.gemspec +3 -3
- data/test/assertion_test.rb +1 -1
- data/test/filter_test.rb +1 -1
- data/test/fixture_test.rb +14 -1
- data/test/generator_test.rb +1 -1
- data/test/helper_test.rb +3 -3
- data/test/initialize.rb +1 -1
- data/test/mainapp_test.rb +59 -43
- data/test/matcher_test.rb +1 -1
- data/test/misc_test.rb +5 -5
- data/test/node_test.rb +27 -4
- data/test/reporter_test.rb +30 -31
- data/test/runner_test.rb +8 -17
- data/test/tc.rb +12 -0
- data/test/util_test.rb +71 -1
- data/test/utilhelper_test.rb +84 -0
- data/test/visitor_test.rb +1 -1
- metadata +4 -3
data/test/mainapp_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
###
|
2
|
-
### $Release: 1.
|
2
|
+
### $Release: 1.2.0 $
|
3
3
|
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
4
4
|
### $License: MIT License $
|
5
5
|
###
|
@@ -73,15 +73,6 @@ end
|
|
73
73
|
|
74
74
|
END
|
75
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
76
|
def edit_actual(output)
|
86
77
|
bkup = output.dup
|
87
78
|
output = output.gsub(/^.*\r/, '')
|
@@ -165,7 +156,7 @@ END
|
|
165
156
|
|
166
157
|
it "[!18qpe] runs test scripts." do
|
167
158
|
expected = <<'END'
|
168
|
-
## total:8 (<
|
159
|
+
## 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
|
169
160
|
END
|
170
161
|
ret, sout, serr = run(@testfile)
|
171
162
|
assert_eq ret, 2
|
@@ -180,7 +171,7 @@ END
|
|
180
171
|
|
181
172
|
it "[!hiu5b] finds test scripts in directory and runs them." do
|
182
173
|
expected = <<'END'
|
183
|
-
## total:8 (<
|
174
|
+
## 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
|
184
175
|
END
|
185
176
|
dir = "_tmpdir.d"
|
186
177
|
dirs = [dir, "#{dir}/d1", "#{dir}/d1/d2"]
|
@@ -196,6 +187,32 @@ END
|
|
196
187
|
end
|
197
188
|
end
|
198
189
|
|
190
|
+
it "[!v5xie] parses $OKTEST_RB environment variable." do
|
191
|
+
ret, sout, serr = run(@testfile, tty: false)
|
192
|
+
expected = plain2colored(<<'END')
|
193
|
+
## _tmp_test.rb
|
194
|
+
* <b>Parent</b>
|
195
|
+
* <b>Child1</b>
|
196
|
+
- [<C>pass</C>] 1+1 should be 2
|
197
|
+
- [<C>pass</C>] 1-1 should be 0
|
198
|
+
END
|
199
|
+
assert sout.start_with?(expected), "expected verbose-style, but not."
|
200
|
+
#
|
201
|
+
begin
|
202
|
+
ENV['OKTEST_RB'] = "-ss"
|
203
|
+
ret, sout, serr = run(@testfile, tty: false)
|
204
|
+
expected = plain2colored(<<'END')
|
205
|
+
## _tmp_test.rb
|
206
|
+
* <b>Parent</b>: <C>.</C><C>.</C>
|
207
|
+
* <b>Child1</b>: <C>.</C><C>.</C>
|
208
|
+
* <b>Child2</b>: <R>f</R><E>E</E>
|
209
|
+
END
|
210
|
+
assert sout.start_with?(expected), "expected simple-style, but not."
|
211
|
+
ensure
|
212
|
+
ENV.delete('OKTEST_RB')
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
199
216
|
#HELP_MESSAGE = Oktest::MainApp::HELP_MESSAGE % {command: File.basename($0)}
|
200
217
|
HELP_MESSAGE = <<"END"
|
201
218
|
Usage: #{File.basename($0)} [<options>] [<file-or-directory>...]
|
@@ -204,9 +221,8 @@ Usage: #{File.basename($0)} [<options>] [<file-or-directory>...]
|
|
204
221
|
-s <REPORT-STYLE> : verbose/simple/compact/plain/quiet, or v/s/c/p/q
|
205
222
|
-F <PATTERN> : filter topic or spec with pattern (see below)
|
206
223
|
--color[={on|off}] : enable/disable output coloring forcedly
|
207
|
-
-
|
224
|
+
-S, --skeleton : print test code skeleton
|
208
225
|
-G, --generate : generate test code skeleton from ruby file
|
209
|
-
--faster : make 'ok{}' faster (for very large project)
|
210
226
|
|
211
227
|
Filter examples:
|
212
228
|
$ oktest -F topic=Hello # filter by topic
|
@@ -241,7 +257,7 @@ END
|
|
241
257
|
end
|
242
258
|
|
243
259
|
it "[!qqizl] '--version' option prints version number." do
|
244
|
-
expected = '$Release: 1.
|
260
|
+
expected = '$Release: 1.2.0 $'.split()[1] + "\n"
|
245
261
|
#
|
246
262
|
ret, sout, serr = run("--version")
|
247
263
|
assert_eq ret, 0
|
@@ -254,11 +270,11 @@ END
|
|
254
270
|
## _tmp_test.rb
|
255
271
|
* <b>Parent</b>
|
256
272
|
* <b>Child1</b>
|
257
|
-
- [<
|
258
|
-
- [<
|
273
|
+
- [<C>pass</C>] 1+1 should be 2
|
274
|
+
- [<C>pass</C>] 1-1 should be 0
|
259
275
|
* <b>Child2</b>
|
260
276
|
- [<R>Fail</R>] 1*1 should be 1
|
261
|
-
- [<
|
277
|
+
- [<E>ERROR</E>] 1/1 should be 1
|
262
278
|
----------------------------------------------------------------------
|
263
279
|
END
|
264
280
|
#
|
@@ -276,9 +292,9 @@ END
|
|
276
292
|
it "[!zfdr5] '-s simple' or '-ss' option prints test results in simple mode." do
|
277
293
|
expected = <<END
|
278
294
|
## _tmp_test.rb
|
279
|
-
* <b>Parent</b>: <
|
280
|
-
* <b>Child1</b>: <
|
281
|
-
* <b>Child2</b>: <R>f</R><
|
295
|
+
* <b>Parent</b>: <C>.</C><C>.</C>
|
296
|
+
* <b>Child1</b>: <C>.</C><C>.</C>
|
297
|
+
* <b>Child2</b>: <R>f</R><E>E</E>
|
282
298
|
----------------------------------------------------------------------
|
283
299
|
END
|
284
300
|
#
|
@@ -295,7 +311,7 @@ END
|
|
295
311
|
|
296
312
|
it "[!ef5v7] '-s compact' or '-sc' option prints test results in compact mode." do
|
297
313
|
expected = <<END
|
298
|
-
#{@testfile}: <
|
314
|
+
#{@testfile}: <C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C>
|
299
315
|
----------------------------------------------------------------------
|
300
316
|
END
|
301
317
|
#
|
@@ -312,7 +328,7 @@ END
|
|
312
328
|
|
313
329
|
it "[!244te] '-s plain' or '-sp' option prints test results in plain mode." do
|
314
330
|
expected = <<END
|
315
|
-
<
|
331
|
+
<C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C>
|
316
332
|
----------------------------------------------------------------------
|
317
333
|
END
|
318
334
|
#
|
@@ -329,7 +345,7 @@ END
|
|
329
345
|
|
330
346
|
it "[!ai61w] '-s quiet' or '-sq' option prints test results in quiet mode." do
|
331
347
|
expected = <<END
|
332
|
-
<R>f</R><
|
348
|
+
<R>f</R><E>E</E><Y>s</Y><Y>t</Y>
|
333
349
|
----------------------------------------------------------------------
|
334
350
|
END
|
335
351
|
#
|
@@ -349,9 +365,9 @@ END
|
|
349
365
|
## _tmp_test.rb
|
350
366
|
* <b>Parent</b>
|
351
367
|
* <b>Child1</b>
|
352
|
-
- [<
|
353
|
-
- [<
|
354
|
-
## total:2 (<
|
368
|
+
- [<C>pass</C>] 1+1 should be 2
|
369
|
+
- [<C>pass</C>] 1-1 should be 0
|
370
|
+
## total:2 (<C>pass:2</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
355
371
|
END
|
356
372
|
#
|
357
373
|
ret, sout, serr = run("-F", "topic=Child1", @testfile)
|
@@ -365,8 +381,8 @@ END
|
|
365
381
|
## _tmp_test.rb
|
366
382
|
* <b>Parent</b>
|
367
383
|
* <b>Child1</b>
|
368
|
-
- [<
|
369
|
-
## total:1 (<
|
384
|
+
- [<C>pass</C>] 1-1 should be 0
|
385
|
+
## total:1 (<C>pass:1</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
370
386
|
END
|
371
387
|
#
|
372
388
|
ret, sout, serr = run("-F", "spec=*1-1*", @testfile)
|
@@ -380,13 +396,13 @@ END
|
|
380
396
|
## _tmp_test.rb
|
381
397
|
* <b>Parent</b>
|
382
398
|
* <b>Child1</b>
|
383
|
-
- [<
|
399
|
+
- [<C>pass</C>] 1-1 should be 0
|
384
400
|
* <b>Child3</b>
|
385
401
|
- [<Y>Skip</Y>] skip example <Y>(reason: a certain condition)</Y>
|
386
402
|
- [<Y>TODO</Y>] todo example
|
387
403
|
- <b>When x is negative</b>
|
388
|
-
- [<
|
389
|
-
## total:4 (<
|
404
|
+
- [<C>pass</C>] [!6hs1j] x*x is positive.
|
405
|
+
## total:4 (<C>pass:2</C>, fail:0, error:0, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
|
390
406
|
END
|
391
407
|
#
|
392
408
|
ret, sout, serr = run("-F", "tag={new,exp}", @testfile)
|
@@ -400,8 +416,8 @@ END
|
|
400
416
|
## _tmp_test.rb
|
401
417
|
* <b>Parent</b>
|
402
418
|
- <b>When x is negative</b>
|
403
|
-
- [<
|
404
|
-
## total:1 (<
|
419
|
+
- [<C>pass</C>] [!6hs1j] x*x is positive.
|
420
|
+
## total:1 (<C>pass:1</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
405
421
|
END
|
406
422
|
#
|
407
423
|
ret, sout, serr = run("-F", "sid=6hs1j", @testfile)
|
@@ -415,11 +431,11 @@ END
|
|
415
431
|
## _tmp_test.rb
|
416
432
|
* <b>Parent</b>
|
417
433
|
* <b>Child1</b>
|
418
|
-
- [<
|
419
|
-
- [<
|
434
|
+
- [<C>pass</C>] 1+1 should be 2
|
435
|
+
- [<C>pass</C>] 1-1 should be 0
|
420
436
|
- <b>Else</b>
|
421
|
-
- [<
|
422
|
-
## total:3 (<
|
437
|
+
- [<C>pass</C>] [!pwiq7] x*x is also positive.
|
438
|
+
## total:3 (<C>pass:3</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
423
439
|
END
|
424
440
|
#
|
425
441
|
ret, sout, serr = run("-F", "tag!={fail,err,exp}", @testfile)
|
@@ -450,7 +466,7 @@ END
|
|
450
466
|
[true, false].each do |tty|
|
451
467
|
Oktest::Config.color_enabled = bool
|
452
468
|
_, sout, serr = run("--color=on", @testfile, tty: tty)
|
453
|
-
assert sout.include?(edit_expected("[<
|
469
|
+
assert sout.include?(edit_expected("[<C>pass</C>]")), "should contain blue string"
|
454
470
|
assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
|
455
471
|
assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
|
456
472
|
assert_eq serr, ""
|
@@ -463,7 +479,7 @@ END
|
|
463
479
|
[true, false].each do |tty|
|
464
480
|
Oktest::Config.color_enabled = bool
|
465
481
|
_, sout, serr = run("--color", @testfile, tty: tty)
|
466
|
-
assert sout.include?(edit_expected("[<
|
482
|
+
assert sout.include?(edit_expected("[<C>pass</C>]")), "should contain blue string"
|
467
483
|
assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
|
468
484
|
assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
|
469
485
|
assert_eq serr, ""
|
@@ -476,7 +492,7 @@ END
|
|
476
492
|
[true, false].each do |tty|
|
477
493
|
Oktest::Config.color_enabled = bool
|
478
494
|
_, sout, serr = run("--color=off", @testfile, tty: tty)
|
479
|
-
assert !sout.include?(edit_expected("[<
|
495
|
+
assert !sout.include?(edit_expected("[<C>pass</C>]")), "should not contain blue string"
|
480
496
|
assert !sout.include?(edit_expected("[<R>Fail</R>]")), "should not contain red string"
|
481
497
|
assert !sout.include?(edit_expected("[<Y>Skip</Y>]")), "should not contain yellos string"
|
482
498
|
assert_eq serr, ""
|
@@ -490,8 +506,8 @@ END
|
|
490
506
|
end
|
491
507
|
end
|
492
508
|
|
493
|
-
it "[!dk8eg] '-
|
494
|
-
ret, sout, serr = run("-
|
509
|
+
it "[!dk8eg] '-S' or '--skeleton' option prints test code skeleton." do
|
510
|
+
ret, sout, serr = run("-S")
|
495
511
|
assert_eq ret, 0
|
496
512
|
assert_eq sout, Oktest::MainApp::SKELETON
|
497
513
|
assert_eq serr, ""
|
data/test/matcher_test.rb
CHANGED
data/test/misc_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 1.
|
4
|
+
### $Release: 1.2.0 $
|
5
5
|
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -69,11 +69,11 @@ class Color_TC < TC
|
|
69
69
|
|
70
70
|
describe '.status()' do
|
71
71
|
it "[!yev5y] returns string containing color escape sequence." do
|
72
|
-
assert_eq Oktest::Color.status(:PASS , "Pass" ), "\e[
|
73
|
-
assert_eq Oktest::Color.status(:FAIL , "Fail" ), "\e[
|
72
|
+
assert_eq Oktest::Color.status(:PASS , "Pass" ), "\e[0;36mPass\e[0m"
|
73
|
+
assert_eq Oktest::Color.status(:FAIL , "Fail" ), "\e[0;31mFail\e[0m"
|
74
74
|
assert_eq Oktest::Color.status(:ERROR, "Error"), "\e[1;31mError\e[0m"
|
75
|
-
assert_eq Oktest::Color.status(:SKIP , "Skip" ), "\e[
|
76
|
-
assert_eq Oktest::Color.status(:TODO , "Todo" ), "\e[
|
75
|
+
assert_eq Oktest::Color.status(:SKIP , "Skip" ), "\e[0;33mSkip\e[0m"
|
76
|
+
assert_eq Oktest::Color.status(:TODO , "Todo" ), "\e[0;33mTodo\e[0m"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
data/test/node_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 1.
|
4
|
+
### $Release: 1.2.0 $
|
5
5
|
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -315,13 +315,25 @@ class ScopeFunctions_TC < TC
|
|
315
315
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
316
316
|
end
|
317
317
|
|
318
|
+
class DummyLocation # < Thread::Backtrace::Location
|
319
|
+
def initialize(string)
|
320
|
+
string =~ /([^:]+):(\d+)/
|
321
|
+
@path = $1
|
322
|
+
@lineno = $2
|
323
|
+
end
|
324
|
+
attr_reader :path, :lineno
|
325
|
+
end
|
326
|
+
|
318
327
|
def with_dummy_location(location)
|
319
328
|
$_dummy_location = location
|
320
329
|
Oktest.module_eval do
|
321
330
|
class << self
|
322
|
-
def caller(n)
|
331
|
+
def caller(n, len=nil)
|
323
332
|
return [$_dummy_location]
|
324
333
|
end
|
334
|
+
def caller_locations(n, len=nil)
|
335
|
+
return [DummyLocation.new($_dummy_location)]
|
336
|
+
end
|
325
337
|
end
|
326
338
|
end
|
327
339
|
yield
|
@@ -329,6 +341,7 @@ class ScopeFunctions_TC < TC
|
|
329
341
|
Oktest.module_eval do
|
330
342
|
class << self
|
331
343
|
remove_method :caller
|
344
|
+
remove_method :caller_locations
|
332
345
|
end
|
333
346
|
end
|
334
347
|
$_dummy_location = nil
|
@@ -533,6 +546,16 @@ class Context_TC < TC
|
|
533
546
|
assert_eq sp.tag, "exp"
|
534
547
|
assert_eq sp._prefix, "-"
|
535
548
|
end
|
549
|
+
it "[!4vkbl] error when `fixture:` keyword arg is not a Hash object." do
|
550
|
+
new_node_with() do
|
551
|
+
spec "example #2", fixture: {x: 1} do end # not raise anything
|
552
|
+
end
|
553
|
+
assert_exc(ArgumentError, 'spec(fixture: "x: 1"): fixture argument should be a Hash object, but got String object.') do
|
554
|
+
new_node_with() do
|
555
|
+
spec "example #2", fixture: "x: 1" do end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
536
559
|
it "[!ala78] provides raising TodoException block if block not given." do
|
537
560
|
node = new_node_with() do
|
538
561
|
spec "example #3"
|
@@ -552,7 +575,7 @@ class Context_TC < TC
|
|
552
575
|
sp1, sp2 = node.each_child.to_a
|
553
576
|
assert_eq sp1.location, nil
|
554
577
|
assert sp2.location != nil, "not nil"
|
555
|
-
assert sp2.location.start_with?("#{__FILE__}:#{lineno}:in")
|
578
|
+
assert sp2.location.to_s.start_with?("#{__FILE__}:#{lineno}:in")
|
556
579
|
end
|
557
580
|
end
|
558
581
|
|
@@ -568,7 +591,7 @@ class Context_TC < TC
|
|
568
591
|
assert node.fixtures.key?(:alice), "key not registerd"
|
569
592
|
assert node.fixtures[:alice][0].is_a?(Proc), "block expected"
|
570
593
|
assert_eq node.fixtures[:alice][1], nil
|
571
|
-
assert node.fixtures[:alice][2].start_with?("#{__FILE__}:#{lineno}:in ")
|
594
|
+
assert node.fixtures[:alice][2].to_s.start_with?("#{__FILE__}:#{lineno}:in ")
|
572
595
|
end
|
573
596
|
it "[!y3ks3] retrieves block parameter names." do
|
574
597
|
node = new_node_with() do
|
data/test/reporter_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 1.
|
4
|
+
### $Release: 1.2.0 $
|
5
5
|
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -11,15 +11,6 @@ require_relative './initialize'
|
|
11
11
|
|
12
12
|
module ReporterTestHelper
|
13
13
|
|
14
|
-
def plain2colored(str)
|
15
|
-
str = str.gsub(/<R>(.*?)<\/R>/) { Oktest::Color.red($1) }
|
16
|
-
str = str.gsub(/<G>(.*?)<\/G>/) { Oktest::Color.green($1) }
|
17
|
-
str = str.gsub(/<B>(.*?)<\/B>/) { Oktest::Color.blue($1) }
|
18
|
-
str = str.gsub(/<Y>(.*?)<\/Y>/) { Oktest::Color.yellow($1) }
|
19
|
-
str = str.gsub(/<b>(.*?)<\/b>/) { Oktest::Color.bold($1) }
|
20
|
-
return str
|
21
|
-
end
|
22
|
-
|
23
14
|
def edit_actual(output)
|
24
15
|
bkup = output.dup
|
25
16
|
output = output.gsub(/^.*\r/, '')
|
@@ -145,7 +136,11 @@ class BaseReporter_TC < TC
|
|
145
136
|
sout, serr = capture do
|
146
137
|
r.__send__(:print_exc_message, exc, :FAIL)
|
147
138
|
end
|
148
|
-
assert_eq sout,
|
139
|
+
assert_eq sout, plain2colored(<<END)
|
140
|
+
<R>something failed</R>
|
141
|
+
expect: foo
|
142
|
+
actual: bar
|
143
|
+
END
|
149
144
|
assert_eq serr, ""
|
150
145
|
end
|
151
146
|
it "[!pd41p] prints detail of exception." do
|
@@ -155,7 +150,11 @@ class BaseReporter_TC < TC
|
|
155
150
|
sout, serr = capture do
|
156
151
|
r.__send__(:print_exc_message, exc, :ERROR)
|
157
152
|
end
|
158
|
-
assert_eq sout,
|
153
|
+
assert_eq sout, plain2colored(<<END)
|
154
|
+
<R>Oktest::AssertionFailed: something failed</R>
|
155
|
+
expect: foo
|
156
|
+
actual: bar
|
157
|
+
END
|
159
158
|
assert_eq serr, ""
|
160
159
|
end
|
161
160
|
end
|
@@ -246,7 +245,7 @@ END
|
|
246
245
|
end
|
247
246
|
#
|
248
247
|
expected = <<END
|
249
|
-
[<
|
248
|
+
[<E>ERROR</E>] <b>Example > Array > When some condition > 1+1 shoould be 2.</b>
|
250
249
|
#{__FILE__}:#{lineno}:in `/'
|
251
250
|
1/0
|
252
251
|
END
|
@@ -283,7 +282,7 @@ END
|
|
283
282
|
r = new_reporter_with_exceptions(exc)
|
284
283
|
sep = "----------------------------------------------------------------------\n"
|
285
284
|
expected1 = "[<R>Fail</R>] <b>Example > Array > When some condition > 1+1 shoould be 2.</b>\n"
|
286
|
-
expected2 = "[<
|
285
|
+
expected2 = "[<E>ERROR</E>] <b>Example > Array > When some condition > 1+1 shoould be 2.</b>\n"
|
287
286
|
#
|
288
287
|
sout, serr = capture { r.__send__(:print_exceptions) }
|
289
288
|
assert sout.start_with?(sep + plain2colored(expected1)), "not matched"
|
@@ -349,7 +348,7 @@ END
|
|
349
348
|
end
|
350
349
|
|
351
350
|
it "[!gx0n2] builds footer line." do
|
352
|
-
expected = "## total:15 (<
|
351
|
+
expected = "## total:15 (<C>pass:5</C>, <R>fail:4</R>, <E>error:3</E>, <Y>skip:2</Y>, <Y>todo:1</Y>) in 0.500s"
|
353
352
|
assert new_footer(), plain2colored(expected)
|
354
353
|
end
|
355
354
|
end
|
@@ -434,49 +433,49 @@ END
|
|
434
433
|
_test.tmp:18:in `block (4 levels) in <top (required)>'
|
435
434
|
ok {1*1} == 2
|
436
435
|
%%%
|
437
|
-
|
436
|
+
<R>$<actual> == $<expected>: failed.</R>
|
438
437
|
$<actual>: 1
|
439
438
|
$<expected>: 2
|
440
439
|
----------------------------------------------------------------------
|
441
|
-
[<
|
440
|
+
[<E>ERROR</E>] <b>Parent > Child2 > 1/1 should be 1</b>
|
442
441
|
_test.tmp:21:in `/'
|
443
442
|
ok {1/0} == 1
|
444
443
|
%%%
|
445
|
-
ZeroDivisionError: divided by 0
|
444
|
+
<R>ZeroDivisionError: divided by 0</R>
|
446
445
|
----------------------------------------------------------------------
|
447
446
|
END
|
448
447
|
|
449
448
|
FOOTER = <<'END'
|
450
|
-
## total:9 (<
|
449
|
+
## total:9 (<C>pass:5</C>, <R>fail:1</R>, <E>error:1</E>, <Y>skip:1</Y>, <Y>todo:1</Y>) in 0.000s
|
451
450
|
END
|
452
451
|
|
453
452
|
VERBOSE_PART = <<'END'
|
454
453
|
## _test.tmp
|
455
454
|
* <b>Parent</b>
|
456
455
|
* <b>Child1</b>
|
457
|
-
- [<
|
458
|
-
- [<
|
456
|
+
- [<C>pass</C>] 1+1 should be 2
|
457
|
+
- [<C>pass</C>] 1-1 should be 0
|
459
458
|
* <b>Child2</b>
|
460
459
|
- [<R>Fail</R>] 1*1 should be 1
|
461
|
-
- [<
|
460
|
+
- [<E>ERROR</E>] 1/1 should be 1
|
462
461
|
END
|
463
462
|
VERBOSE_PART2 = <<'END'
|
464
463
|
* <b>Child3</b>
|
465
464
|
- [<Y>Skip</Y>] skip example <Y>(reason: a certain condition)</Y>
|
466
465
|
- [<Y>TODO</Y>] todo example
|
467
466
|
- <b>When x is negative</b>
|
468
|
-
- [<
|
467
|
+
- [<C>pass</C>] x*x is positive.
|
469
468
|
- <b>Else</b>
|
470
|
-
- [<
|
471
|
-
- [<
|
469
|
+
- [<C>pass</C>] x*x is also positive.
|
470
|
+
- [<C>pass</C>] last spec
|
472
471
|
END
|
473
472
|
VERBOSE_OUTPUT = VERBOSE_PART + ERROR_PART + VERBOSE_PART2 + FOOTER
|
474
473
|
|
475
474
|
SIMPLE_PART = <<'END'
|
476
475
|
## _test.tmp
|
477
|
-
* <b>Parent</b>: <
|
478
|
-
* <b>Child1</b>: <
|
479
|
-
* <b>Child2</b>: <R>f</R><
|
476
|
+
* <b>Parent</b>: <C>.</C><C>.</C><C>.</C>
|
477
|
+
* <b>Child1</b>: <C>.</C><C>.</C>
|
478
|
+
* <b>Child2</b>: <R>f</R><E>E</E>
|
480
479
|
END
|
481
480
|
SIMPLE_PART2 = <<'END'
|
482
481
|
* <b>Child3</b>: <Y>s</Y><Y>t</Y>
|
@@ -484,17 +483,17 @@ END
|
|
484
483
|
SIMPLE_OUTPUT = SIMPLE_PART + ERROR_PART + SIMPLE_PART2 + FOOTER
|
485
484
|
|
486
485
|
COMPACT_PART = <<'END'
|
487
|
-
_test.tmp: <
|
486
|
+
_test.tmp: <C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C><C>.</C>
|
488
487
|
END
|
489
488
|
COMPACT_OUTPUT = COMPACT_PART + ERROR_PART + FOOTER
|
490
489
|
|
491
490
|
PLAIN_PART = <<'END'
|
492
|
-
<
|
491
|
+
<C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C><C>.</C>
|
493
492
|
END
|
494
493
|
PLAIN_OUTPUT = PLAIN_PART + ERROR_PART + FOOTER
|
495
494
|
|
496
495
|
QUIET_PART = <<'END'
|
497
|
-
<R>f</R><
|
496
|
+
<R>f</R><E>E</E><Y>s</Y><Y>t</Y>
|
498
497
|
END
|
499
498
|
QUIET_OUTPUT = QUIET_PART + ERROR_PART + FOOTER
|
500
499
|
|
data/test/runner_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
###
|
4
|
-
### $Release: 1.
|
4
|
+
### $Release: 1.2.0 $
|
5
5
|
### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
|
6
6
|
### $License: MIT License $
|
7
7
|
###
|
@@ -521,15 +521,6 @@ class RunnerFunctions_TC < TC
|
|
521
521
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
522
522
|
end
|
523
523
|
|
524
|
-
def plain2colored(str)
|
525
|
-
str = str.gsub(/<R>(.*?)<\/R>/) { Oktest::Color.red($1) }
|
526
|
-
str = str.gsub(/<G>(.*?)<\/G>/) { Oktest::Color.green($1) }
|
527
|
-
str = str.gsub(/<B>(.*?)<\/B>/) { Oktest::Color.blue($1) }
|
528
|
-
str = str.gsub(/<Y>(.*?)<\/Y>/) { Oktest::Color.yellow($1) }
|
529
|
-
str = str.gsub(/<b>(.*?)<\/b>/) { Oktest::Color.bold($1) }
|
530
|
-
return str
|
531
|
-
end
|
532
|
-
|
533
524
|
def edit_actual(output)
|
534
525
|
bkup = output.dup
|
535
526
|
output = output.gsub(/^.*\r/, '')
|
@@ -561,17 +552,17 @@ class RunnerFunctions_TC < TC
|
|
561
552
|
VERBOSE_OUTPUT = <<'END'
|
562
553
|
## test/runner_test.rb
|
563
554
|
* <b>Example</b>
|
564
|
-
- [<
|
565
|
-
- [<
|
566
|
-
## total:2 (<
|
555
|
+
- [<C>pass</C>] 1+1 should be 2
|
556
|
+
- [<C>pass</C>] 1-1 should be 0
|
557
|
+
## total:2 (<C>pass:2</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
567
558
|
END
|
568
559
|
COMPACT_OUTPUT = <<'END'
|
569
|
-
test/runner_test.rb: <
|
570
|
-
## total:2 (<
|
560
|
+
test/runner_test.rb: <C>.</C><C>.</C>
|
561
|
+
## total:2 (<C>pass:2</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
571
562
|
END
|
572
563
|
PLAIN_OUTPUT = <<'END'
|
573
|
-
<
|
574
|
-
## total:2 (<
|
564
|
+
<C>.</C><C>.</C>
|
565
|
+
## total:2 (<C>pass:2</C>, fail:0, error:0, skip:0, todo:0) in 0.000s
|
575
566
|
END
|
576
567
|
|
577
568
|
|
data/test/tc.rb
CHANGED
@@ -109,6 +109,18 @@ class TC
|
|
109
109
|
$stdin, $stdout, $stderr = stdin, stdout, stderr
|
110
110
|
end
|
111
111
|
|
112
|
+
def plain2colored(str)
|
113
|
+
str = str.gsub(/<R>(.*?)<\/R>/) { Oktest::Color.red($1) }
|
114
|
+
str = str.gsub(/<G>(.*?)<\/G>/) { Oktest::Color.green($1) }
|
115
|
+
str = str.gsub(/<B>(.*?)<\/B>/) { Oktest::Color.blue($1) }
|
116
|
+
str = str.gsub(/<C>(.*?)<\/C>/) { Oktest::Color.cyan($1) }
|
117
|
+
str = str.gsub(/<M>(.*?)<\/M>/) { Oktest::Color.magenta($1) }
|
118
|
+
str = str.gsub(/<Y>(.*?)<\/Y>/) { Oktest::Color.yellow($1) }
|
119
|
+
str = str.gsub(/<b>(.*?)<\/b>/) { Oktest::Color.bold($1) }
|
120
|
+
str = str.gsub(/<E>(.*?)<\/E>/) { Oktest::Color.red_b($1) }
|
121
|
+
return str
|
122
|
+
end
|
123
|
+
|
112
124
|
end
|
113
125
|
|
114
126
|
|