oktest 1.4.0 → 1.5.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 +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/visitor_test.rb
CHANGED
@@ -2,15 +2,16 @@
|
|
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 Visitor__Test
|
14
|
+
extend NanoTest
|
14
15
|
|
15
16
|
class DummyVisitor0 < Oktest::Visitor
|
16
17
|
def initialize
|
@@ -37,7 +38,7 @@ class Visitor_TC < TC
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
def prepare()
|
41
|
+
def self.prepare()
|
41
42
|
Oktest.scope do
|
42
43
|
topic 'Example1' do
|
43
44
|
topic 'sample1-1' do
|
@@ -48,15 +49,15 @@ class Visitor_TC < TC
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
def teardown
|
52
|
+
def self.test_subject(desc, &b)
|
53
|
+
super
|
54
|
+
ensure
|
55
55
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
|
59
|
+
test_target 'Oktest::Visitor#visit_spec()' do
|
60
|
+
test_subject "[!9f7i9] do something on spec." do
|
60
61
|
expected = <<'END'
|
61
62
|
spec: sample {
|
62
63
|
}
|
@@ -64,12 +65,12 @@ END
|
|
64
65
|
sp = Oktest::SpecLeaf.new(nil, "sample")
|
65
66
|
visitor = DummyVisitor0.new
|
66
67
|
visitor.visit_spec(sp, 0, nil)
|
67
|
-
|
68
|
+
test_eq? visitor.log.join(), expected
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
|
-
|
72
|
-
|
72
|
+
test_target 'Oktest::Visitor#visit_topic()' do
|
73
|
+
test_subject "[!mu3fn] visits each child of topic." do
|
73
74
|
expected = <<'END'
|
74
75
|
topic: example {
|
75
76
|
spec: sample {
|
@@ -80,12 +81,12 @@ END
|
|
80
81
|
sp = Oktest::SpecLeaf.new(to, "sample")
|
81
82
|
visitor = DummyVisitor0.new
|
82
83
|
visitor.visit_topic(to, 0, nil)
|
83
|
-
|
84
|
+
test_eq? visitor.log.join(), expected
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
test_target 'Oktest::Visitor#visit_scope()' do
|
89
|
+
test_subject "[!hebhz] visits each child scope." do
|
89
90
|
expected = <<'END'
|
90
91
|
scope: file.rb {
|
91
92
|
topic: example {
|
@@ -99,12 +100,12 @@ END
|
|
99
100
|
sp = Oktest::SpecLeaf.new(sc, "sample")
|
100
101
|
visitor = DummyVisitor0.new
|
101
102
|
visitor.visit_scope(sc, 0, nil)
|
102
|
-
|
103
|
+
test_eq? visitor.log.join(), expected
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
|
-
|
107
|
-
|
107
|
+
test_target 'Oktest::Visitor#start()' do
|
108
|
+
test_subject "[!8h8qf] start visiting tree." do
|
108
109
|
expected = <<'END'
|
109
110
|
scope: test/visitor_test.rb {
|
110
111
|
topic: Example1 {
|
@@ -120,14 +121,15 @@ END
|
|
120
121
|
prepare()
|
121
122
|
visitor = DummyVisitor0.new
|
122
123
|
visitor.start()
|
123
|
-
|
124
|
+
test_eq? visitor.log.join(), expected
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
128
|
end
|
128
129
|
|
129
130
|
|
130
|
-
class
|
131
|
+
class Traverser__Test
|
132
|
+
extend NanoTest
|
131
133
|
|
132
134
|
class MyTraverser < Oktest::Traverser
|
133
135
|
def on_scope(filename, tag, depth)
|
@@ -159,7 +161,7 @@ class Traverser_TC < TC
|
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
162
|
-
def prepare()
|
164
|
+
def self.prepare()
|
163
165
|
Oktest.scope do
|
164
166
|
topic 'Example' do
|
165
167
|
topic Integer, tag: 'cls' do
|
@@ -180,13 +182,15 @@ class Traverser_TC < TC
|
|
180
182
|
end
|
181
183
|
end
|
182
184
|
|
183
|
-
def
|
185
|
+
def self.test_subject(desc, &b)
|
186
|
+
super
|
187
|
+
ensure
|
184
188
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
185
189
|
end
|
186
190
|
|
187
191
|
|
188
|
-
|
189
|
-
|
192
|
+
test_target 'Oktest::Traverser#start()' do
|
193
|
+
test_subject "[!5zonp] visits topics and specs and calls callbacks." do
|
190
194
|
expected = <<'END'
|
191
195
|
* scope: test/visitor_test.rb
|
192
196
|
+ topic: Example
|
@@ -202,22 +206,22 @@ class Traverser_TC < TC
|
|
202
206
|
- spec: 1/1 should be 1. (tag: err)
|
203
207
|
END
|
204
208
|
prepare()
|
205
|
-
sout, serr =
|
206
|
-
|
207
|
-
|
209
|
+
sout, serr = capture_output! { MyTraverser.new.start() }
|
210
|
+
test_eq? sout, expected
|
211
|
+
test_eq? serr, ""
|
208
212
|
end
|
209
|
-
|
213
|
+
test_subject "[!gkopz] doesn't change Oktest::THE_GLOBAL_SCOPE." do
|
210
214
|
prepare()
|
211
215
|
n = Oktest::THE_GLOBAL_SCOPE.each_child.to_a.length
|
212
|
-
sout, serr =
|
216
|
+
sout, serr = capture_output! do
|
213
217
|
MyTraverser.new.start()
|
214
218
|
end
|
215
|
-
|
219
|
+
test_eq? Oktest::THE_GLOBAL_SCOPE.each_child.to_a.length, n
|
216
220
|
end
|
217
221
|
end
|
218
222
|
|
219
|
-
|
220
|
-
|
223
|
+
test_target 'Oktest::Traverser#visit_scope()' do
|
224
|
+
test_subject "[!ledj3] calls on_scope() callback on scope." do
|
221
225
|
expected = <<'END'
|
222
226
|
* scope: test/visitor_test.rb
|
223
227
|
* scope: test/visitor_test.rb
|
@@ -226,14 +230,14 @@ END
|
|
226
230
|
end
|
227
231
|
Oktest.scope do
|
228
232
|
end
|
229
|
-
sout, serr =
|
230
|
-
|
231
|
-
|
233
|
+
sout, serr = capture_output! { MyTraverser.new.start() }
|
234
|
+
test_eq? sout, expected
|
235
|
+
test_eq? serr, ""
|
232
236
|
end
|
233
237
|
end
|
234
238
|
|
235
|
-
|
236
|
-
|
239
|
+
test_target 'Oktest::Traverser#visit_topic()' do
|
240
|
+
test_subject "[!x8r9w] calls on_topic() callback on topic." do
|
237
241
|
expected = <<'END'
|
238
242
|
* scope: test/visitor_test.rb
|
239
243
|
+ topic: Parent
|
@@ -245,11 +249,11 @@ END
|
|
245
249
|
end
|
246
250
|
end
|
247
251
|
end
|
248
|
-
sout, serr =
|
249
|
-
|
250
|
-
|
252
|
+
sout, serr = capture_output! { MyTraverser.new.start() }
|
253
|
+
test_eq? sout, expected
|
254
|
+
test_eq? serr, ""
|
251
255
|
end
|
252
|
-
|
256
|
+
test_subject "[!qh0q3] calls on_case() callback on case_when or case_else." do
|
253
257
|
expected = <<'END'
|
254
258
|
* scope: test/visitor_test.rb
|
255
259
|
+ topic: Parent
|
@@ -264,14 +268,14 @@ END
|
|
264
268
|
end
|
265
269
|
end
|
266
270
|
end
|
267
|
-
sout, serr =
|
268
|
-
|
269
|
-
|
271
|
+
sout, serr = capture_output! { MyTraverser.new.start() }
|
272
|
+
test_eq? sout, expected
|
273
|
+
test_eq? serr, ""
|
270
274
|
end
|
271
275
|
end
|
272
276
|
|
273
|
-
|
274
|
-
|
277
|
+
test_target 'Oktest::Traverser#visit_spec()' do
|
278
|
+
test_subject "[!41uyj] calls on_spec() callback." do
|
275
279
|
expected = <<'END'
|
276
280
|
* scope: test/visitor_test.rb
|
277
281
|
+ topic: Example
|
@@ -284,9 +288,9 @@ END
|
|
284
288
|
spec "sample #2" do ok {1-1} == 0 end
|
285
289
|
end
|
286
290
|
end
|
287
|
-
sout, serr =
|
288
|
-
|
289
|
-
|
291
|
+
sout, serr = capture_output! { MyTraverser.new.start() }
|
292
|
+
test_eq? sout, expected
|
293
|
+
test_eq? serr, ""
|
290
294
|
end
|
291
295
|
end
|
292
296
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oktest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kwatch
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diff-lcs
|
@@ -76,20 +76,20 @@ files:
|
|
76
76
|
- bin/oktest
|
77
77
|
- lib/oktest.rb
|
78
78
|
- oktest.gemspec
|
79
|
+
- test/all.rb
|
79
80
|
- test/assertion_test.rb
|
80
81
|
- test/filter_test.rb
|
81
82
|
- test/fixture_test.rb
|
82
83
|
- test/generator_test.rb
|
83
84
|
- test/helper_test.rb
|
84
|
-
- test/
|
85
|
+
- test/init.rb
|
85
86
|
- test/mainapp_test.rb
|
86
87
|
- test/matcher_test.rb
|
87
88
|
- test/misc_test.rb
|
89
|
+
- test/nanot.rb
|
88
90
|
- test/node_test.rb
|
89
91
|
- test/reporter_test.rb
|
90
|
-
- test/run_all.rb
|
91
92
|
- test/runner_test.rb
|
92
|
-
- test/tc.rb
|
93
93
|
- test/util_test.rb
|
94
94
|
- test/utilhelper_test.rb
|
95
95
|
- test/visitor_test.rb
|
@@ -97,7 +97,7 @@ homepage: https://github.com/kwatch/oktest/tree/ruby/ruby
|
|
97
97
|
licenses:
|
98
98
|
- MIT
|
99
99
|
metadata: {}
|
100
|
-
post_install_message:
|
100
|
+
post_install_message:
|
101
101
|
rdoc_options: []
|
102
102
|
require_paths:
|
103
103
|
- lib
|
@@ -112,9 +112,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
115
|
+
rubygems_version: 3.4.19
|
116
|
+
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: a new style testing library
|
119
119
|
test_files:
|
120
|
-
- test/
|
120
|
+
- test/all.rb
|
data/test/initialize.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
###
|
5
|
-
### $Release: 1.4.0 $
|
6
|
-
### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
|
7
|
-
### $License: MIT License $
|
8
|
-
###
|
9
|
-
|
10
|
-
File.class_eval do
|
11
|
-
$LOAD_PATH << join(dirname(dirname(expand_path(__FILE__))), 'lib')
|
12
|
-
end
|
13
|
-
|
14
|
-
require_relative './tc'
|
15
|
-
require 'oktest'
|
16
|
-
|
17
|
-
|
18
|
-
# for Ruby 2.4 or older
|
19
|
-
require 'set'
|
20
|
-
unless Set.instance_methods(false).include?(:===)
|
21
|
-
class Set; alias === include?; end
|
22
|
-
end
|
data/test/tc.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
## micro test case class
|
5
|
-
class TC
|
6
|
-
|
7
|
-
COUNTS = {:ok => 0, :fail => 0, :error => 0}
|
8
|
-
|
9
|
-
def self.report_result()
|
10
|
-
ok, fail, error = COUNTS[:ok], COUNTS[:fail], COUNTS[:error]
|
11
|
-
COUNTS.keys.each {|k| COUNTS[k] = 0 }
|
12
|
-
red = proc {|s| "\033[0;31m#{s}\033[0m" }
|
13
|
-
fail_s = "fail: #{fail}" ; fail_s = red.call(fail_s) if fail > 0
|
14
|
-
error_s = "error: #{error}" ; error_s = red.call(error_s) if error > 0
|
15
|
-
STDOUT.puts "## total: #{ok+fail+error} (ok: #{ok}, #{fail_s}, #{error_s})"
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.describe(target, &b)
|
19
|
-
prev, @curr_target = @curr_target, target
|
20
|
-
yield
|
21
|
-
ensure
|
22
|
-
@curr_target = prev
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.curr_target()
|
26
|
-
@curr_target
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.it(spec, &b)
|
30
|
-
t = @curr_target
|
31
|
-
print "[#{self.name}#{t ? ' > ' : ''}#{t}] #{spec} ... " unless ENV['TC_QUIET']
|
32
|
-
obj = self.new
|
33
|
-
obj.setup()
|
34
|
-
begin
|
35
|
-
obj.instance_eval(&b)
|
36
|
-
rescue => exc
|
37
|
-
if exc.is_a?(AssertionFailed)
|
38
|
-
COUNTS[:fail] += 1; puts "\e[31mFAILED!\e[0m" unless ENV['TC_QUIET']
|
39
|
-
else
|
40
|
-
COUNTS[:error] += 1; puts "\e[31mERROR!\e[0m" unless ENV['TC_QUIET']
|
41
|
-
end
|
42
|
-
puts " #{exc.class.name}: #{exc.message}"
|
43
|
-
exc.backtrace.each do |bt|
|
44
|
-
puts " #{bt}" if bt.index(__FILE__) == nil
|
45
|
-
end
|
46
|
-
else
|
47
|
-
COUNTS[:ok] += 1; puts "ok." unless ENV['TC_QUIET']
|
48
|
-
ensure
|
49
|
-
obj.teardown()
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup
|
54
|
-
end
|
55
|
-
|
56
|
-
def teardown
|
57
|
-
end
|
58
|
-
|
59
|
-
class AssertionFailed < StandardError
|
60
|
-
end
|
61
|
-
|
62
|
-
def assert(cond, msg="assertion failed")
|
63
|
-
raise msg unless cond
|
64
|
-
end
|
65
|
-
|
66
|
-
def assert_eq(actual, expected)
|
67
|
-
return if actual == expected
|
68
|
-
multiline_p = actual.is_a?(String) && actual =~ /\n/ \
|
69
|
-
&& expected.is_a?(String) && expected =~ /\n/
|
70
|
-
errmsg = (multiline_p \
|
71
|
-
? "$<actual> == $<expected> : failed.\n" +
|
72
|
-
" $<actual>: <<END\n#{actual}END\n" +
|
73
|
-
" $<expected>: <<END\n#{expected}END"
|
74
|
-
: "$<actual> == $<expected> : failed.\n" +
|
75
|
-
" $<actual>: #{actual.inspect}\n" +
|
76
|
-
" $<expected>: #{expected.inspect}")
|
77
|
-
raise AssertionFailed, errmsg
|
78
|
-
end
|
79
|
-
|
80
|
-
def assert_exc(errcls, errmsg=nil, &b)
|
81
|
-
begin
|
82
|
-
yield
|
83
|
-
rescue NoMemoryError, SystemExit, SyntaxError, SignalException
|
84
|
-
raise
|
85
|
-
rescue Exception => exc
|
86
|
-
exc.class == errcls or
|
87
|
-
raise AssertionFailed, "#{errcls} should be raised but got #{exc.inspect}"
|
88
|
-
errmsg.nil? || errmsg === exc.message or
|
89
|
-
raise AssertionFailed, ("invalid error message.\n"\
|
90
|
-
" $<actual>: #{exc.message.inspect}\n"\
|
91
|
-
" $<expected>: #{errmsg.inspect}")
|
92
|
-
return exc
|
93
|
-
else
|
94
|
-
raise AssertionFailed, "#{errcls.name} should be raised but not."
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def capture(input="", tty: true, &b)
|
99
|
-
require 'stringio' unless defined?(StringIO)
|
100
|
-
stdin, stdout, stderr = $stdin, $stdout, $stderr
|
101
|
-
$stdin = sin = StringIO.new(input)
|
102
|
-
$stdout = sout = StringIO.new
|
103
|
-
$stderr = serr = StringIO.new
|
104
|
-
def sin.tty? ; true; end if tty
|
105
|
-
def sout.tty?; true; end if tty
|
106
|
-
def sout.tty?; true; end if tty
|
107
|
-
yield
|
108
|
-
return sout.string, serr.string
|
109
|
-
ensure
|
110
|
-
$stdin, $stdout, $stderr = stdin, stdout, stderr
|
111
|
-
end
|
112
|
-
|
113
|
-
def plain2colored(str)
|
114
|
-
str = str.gsub(/<R>(.*?)<\/R>/) { Oktest::Color.red($1) }
|
115
|
-
str = str.gsub(/<G>(.*?)<\/G>/) { Oktest::Color.green($1) }
|
116
|
-
str = str.gsub(/<B>(.*?)<\/B>/) { Oktest::Color.blue($1) }
|
117
|
-
str = str.gsub(/<C>(.*?)<\/C>/) { Oktest::Color.cyan($1) }
|
118
|
-
str = str.gsub(/<M>(.*?)<\/M>/) { Oktest::Color.magenta($1) }
|
119
|
-
str = str.gsub(/<Y>(.*?)<\/Y>/) { Oktest::Color.yellow($1) }
|
120
|
-
str = str.gsub(/<b>(.*?)<\/b>/) { Oktest::Color.bold($1) }
|
121
|
-
str = str.gsub(/<E>(.*?)<\/E>/) { Oktest::Color.red_b($1) }
|
122
|
-
return str
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
at_exit { TC.report_result() }
|
/data/test/{run_all.rb → all.rb}
RENAMED
File without changes
|