oktest 1.3.1 → 1.5.0

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