oktest 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/mainapp_test.rb CHANGED
@@ -2,29 +2,31 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 1.4.0 $
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 './initialize'
10
+ require_relative './init'
11
11
 
12
12
 
13
- class MainApp_TC < TC
13
+ class MainApp__Test
14
+ extend NanoTest
15
+ extend Oktest::SpecHelper
14
16
 
15
- def setup
17
+ def self.test_subject(desc, &b)
16
18
  @testfile = "_tmp_test.rb"
17
- File.write(@testfile, INPUT, encoding: 'utf-8')
18
- @_color_enabled = Oktest::Config.color_enabled
19
+ File.write(@testfile, INPUT_5, encoding: 'utf-8')
20
+ color_enabled = Oktest::Config.color_enabled
19
21
  Oktest::Config.color_enabled = true
20
- end
21
-
22
- def teardown
23
- Oktest::Config.color_enabled = @_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
- INPUT = <<'END'
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
- describe '.main()' do
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 = capture do
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
- it "[!tb6sx] returns 0 when no errors raised." do
107
+ test_subject "[!tb6sx] returns 0 when no errors raised." do
106
108
  ret, sout, serr = main(["-h"])
107
- assert_eq ret, 0
108
- assert_eq serr, ""
109
+ test_eq? ret, 0
110
+ test_eq? serr, ""
109
111
  end
110
112
 
111
- it "[!d5mql] returns 1 when a certain error raised." do
113
+ test_subject "[!d5mql] returns 1 when a certain error raised." do
112
114
  ret, sout, serr = main(["-U"])
113
- assert_eq ret, 1
114
- assert_eq serr, "[ERROR] -U: Unknown option.\n"
115
+ test_eq? ret, 1
116
+ test_eq? serr, "[ERROR] -U: Unknown option.\n"
115
117
  end
116
118
 
117
- it "[!jr49p] reports error when unknown option specified." do
119
+ test_subject "[!jr49p] reports error when unknown option specified." do
118
120
  ret, sout, serr = main(["-X"])
119
- assert_eq ret, 1
120
- assert_eq serr, "[ERROR] -X: Unknown option.\n"
121
+ test_eq? ret, 1
122
+ test_eq? serr, "[ERROR] -X: Unknown option.\n"
121
123
  #
122
124
  ret, sout, serr = main(["--foobar"])
123
- assert_eq ret, 1
124
- assert_eq serr, "[ERROR] --foobar: Unknown long option.\n"
125
+ test_eq? ret, 1
126
+ test_eq? serr, "[ERROR] --foobar: Unknown long option.\n"
125
127
  end
126
128
 
127
- it "[!uqomj] reports error when required argument is missing." do
129
+ test_subject "[!uqomj] reports error when required argument is missing." do
128
130
  ret, sout, serr = main(["-s"])
129
- assert_eq ret, 1
130
- assert_eq serr, "[ERROR] -s: Argument required.\n"
131
+ test_eq? ret, 1
132
+ test_eq? serr, "[ERROR] -s: Argument required.\n"
131
133
  end
132
134
 
133
- it "[!8i755] reports error when argument is invalid." do
135
+ test_subject "[!8i755] reports error when argument is invalid." do
134
136
  ret, sout, serr = main(["-s", "foobar"])
135
- assert_eq ret, 1
136
- assert_eq serr, "[ERROR] -s foobar: Expected one of verbose/simple/compact/plain/quiet/v/s/c/p/q.\n"
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
- assert_eq ret, 1
140
- assert_eq serr, "[ERROR] -F aaa=*pat*: Pattern unmatched.\n"
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
- assert_eq ret, 1
144
- assert_eq serr, "[ERROR] --color=abc: Boolean expected.\n"
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
- describe '#run()' do
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 = capture("", tty: tty) do
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
- it "[!18qpe] runs test scripts." do
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
- assert_eq ret, 2
166
- assert edit_actual(sout).end_with?(edit_expected(expected)), "invalid status line"
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
- it "[!k402d] raises error if file not found." do
171
+ test_subject "[!k402d] raises error if file not found." do
170
172
  filename = "not-exist-file"
171
- assert_exc(Benry::CmdOpt::OptionError, "#{filename}: not found.") do
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
- it "[!bim36] changes auto-running to off." do
179
+ test_subject "[!bim36] changes auto-running to off." do
177
180
  Oktest::Config.auto_run = true
178
181
  _ = run(@testfile)
179
- assert_eq Oktest::Config.auto_run, false
182
+ test_eq? Oktest::Config.auto_run, false
180
183
  end
181
184
 
182
- it "[!hiu5b] finds test scripts in directory and runs them." do
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
- assert_eq ret, 2
193
- assert edit_actual(sout).end_with?(edit_expected(expected)), "invalid status line"
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
- it "[!v5xie] parses $OKTEST_RB environment variable." do
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
- assert sout.start_with?(expected), "expected verbose-style, but not."
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
- assert sout.start_with?(expected), "expected simple-style, but not."
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
- it "[!tt2gj] parses command options even after filenames." do
229
+ test_subject "[!tt2gj] parses command options even after filenames." do
227
230
  ret, sout, serr = run(@testfile, "--version")
228
- assert_eq ret, 0
229
- assert_eq sout, Oktest::VERSION+"\n"
230
- assert_eq serr, ""
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
- it "[!65vdx] prints help message if no arguments specified." do
263
+ test_subject "[!65vdx] prints help message if no arguments specified." do
261
264
  expected = HELP_MESSAGE
262
265
  ret, sout, serr = run()
263
- assert_eq ret, 0
264
- assert_eq sout, expected
265
- assert_eq serr, ""
266
+ test_eq? ret, 0
267
+ test_eq? sout, expected
268
+ test_eq? serr, ""
266
269
  end
267
270
 
268
- it "[!9973n] '-h' or '--help' option prints help message." do
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
- assert_eq ret, 0
273
- assert_eq sout, expected
274
- assert_eq serr, ""
275
+ test_eq? ret, 0
276
+ test_eq? sout, expected
277
+ test_eq? serr, ""
275
278
  #
276
279
  ret, sout, serr = run("--help")
277
- assert_eq ret, 0
278
- assert_eq sout, expected
279
- assert_eq serr, ""
280
+ test_eq? ret, 0
281
+ test_eq? sout, expected
282
+ test_eq? serr, ""
280
283
  end
281
284
 
282
- it "[!v938d] help message will be colored only when stdout is a tty." do
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
- assert sout =~ /\e\[1mOktest\e\[0m/
285
- assert sout =~ /\e\[36mOptions:\e\[0m/
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
- assert sout !~ /\e\[1mOktest\e\[0m/
289
- assert sout !~ /\e\[36mOptions:\e\[0m/
291
+ test_ok? sout !~ /\e\[1mOktest\e\[0m/
292
+ test_ok? sout !~ /\e\[36mOptions:\e\[0m/
290
293
  end
291
294
 
292
- it "[!qqizl] '--version' option prints version number." do
293
- expected = '$Release: 1.4.0 $'.split()[1] + "\n"
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
- assert_eq ret, 0
297
- assert_eq sout, expected
298
- assert_eq serr, ""
299
+ test_eq? ret, 0
300
+ test_eq? sout, expected
301
+ test_eq? serr, ""
299
302
  end
300
303
 
301
- it "[!0qd92] '-s verbose' or '-sv' option prints test results in verbose mode." do
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
- assert_eq ret, 2
316
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
317
- assert_eq serr, ""
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
- assert_eq ret, 2
321
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
322
- assert_eq serr, ""
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
- it "[!zfdr5] '-s simple' or '-ss' option prints test results in simple mode." do
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
- assert_eq ret, 2
336
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
337
- assert_eq serr, ""
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
- assert_eq ret, 2
341
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
342
- assert_eq serr, ""
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
- it "[!ef5v7] '-s compact' or '-sc' option prints test results in compact mode." do
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
- assert_eq ret, 2
353
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
354
- assert_eq serr, ""
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
- assert_eq ret, 2
358
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
359
- assert_eq serr, ""
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
- it "[!244te] '-s plain' or '-sp' option prints test results in plain mode." do
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
- assert_eq ret, 2
370
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
371
- assert_eq serr, ""
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
- assert_eq ret, 2
375
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
376
- assert_eq serr, ""
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
- it "[!ai61w] '-s quiet' or '-sq' option prints test results in quiet mode." do
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
- assert_eq ret, 2
387
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
388
- assert_eq serr, ""
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
- assert_eq ret, 2
392
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
393
- assert_eq serr, ""
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
- it "[!yz7g5] '-F topic=...' option filters topics." do
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
- assert_eq ret, 0
408
- assert_eq edit_actual(sout), edit_expected(expected)
409
- assert_eq serr, ""
410
+ test_eq? ret, 0
411
+ test_eq? edit_actual(sout), edit_expected(expected)
412
+ test_eq? serr, ""
410
413
  end
411
414
 
412
- it "[!ww2mp] '-F spec=...' option filters specs." do
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
- assert_eq ret, 0
423
- assert_eq edit_actual(sout), edit_expected(expected)
424
- assert_eq serr, ""
425
+ test_eq? ret, 0
426
+ test_eq? edit_actual(sout), edit_expected(expected)
427
+ test_eq? serr, ""
425
428
  end
426
429
 
427
- it "[!8uvib] '-F tag=...' option filters by tag name." do
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
- assert_eq ret, 0
443
- assert_eq edit_actual(sout), edit_expected(expected)
444
- assert_eq serr, ""
445
+ test_eq? ret, 0
446
+ test_eq? edit_actual(sout), edit_expected(expected)
447
+ test_eq? serr, ""
445
448
  end
446
449
 
447
- it "[!m0iwm] '-F sid=...' option filters by spec id." do
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
- assert_eq ret, 0
458
- assert_eq edit_actual(sout), edit_expected(expected)
459
- assert_eq serr, ""
460
+ test_eq? ret, 0
461
+ test_eq? edit_actual(sout), edit_expected(expected)
462
+ test_eq? serr, ""
460
463
  end
461
464
 
462
- it "[!noi8i] '-F' option supports negative filter." do
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
- assert_eq ret, 0
476
- assert_eq edit_actual(sout), edit_expected(expected)
477
- assert_eq serr, ""
478
+ test_eq? ret, 0
479
+ test_eq? edit_actual(sout), edit_expected(expected)
480
+ test_eq? serr, ""
478
481
  end
479
482
 
480
- it "[!71h2x] '-F ...' option will be error." do
481
- assert_exc(Benry::CmdOpt::OptionError, "-F *pat*: Pattern unmatched.") do
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
- it "[!j01y7] if filerting by '-F' matched nothing, then prints zero result." do
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
- assert_eq ret, 0
493
- assert_eq edit_actual(sout), edit_expected(expected)
494
- assert_eq serr, ""
496
+ test_eq? ret, 0
497
+ test_eq? edit_actual(sout), edit_expected(expected)
498
+ test_eq? serr, ""
495
499
  end
496
500
 
497
- it "[!6ro7j] '--color=on' option enables output coloring forcedly." do
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
- assert sout.include?(edit_expected("[<C>pass</C>]")), "should contain blue string"
503
- assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
504
- assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
505
- assert_eq serr, ""
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
- it "[!dptgn] '--color' is same as '--color=on'." do
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
- assert sout.include?(edit_expected("[<C>pass</C>]")), "should contain blue string"
516
- assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
517
- assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
518
- assert_eq serr, ""
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
- it "[!vmw0q] '--color=off' option disables output coloring forcedly." do
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
- assert !sout.include?(edit_expected("[<C>pass</C>]")), "should not contain blue string"
529
- assert !sout.include?(edit_expected("[<R>Fail</R>]")), "should not contain red string"
530
- assert !sout.include?(edit_expected("[<Y>Skip</Y>]")), "should not contain yellos string"
531
- assert_eq serr, ""
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
- it "[!dk8eg] '-S' or '--skeleton' option prints test code skeleton." do
540
+ test_subject "[!dk8eg] '-S' or '--skeleton' option prints test code skeleton." do
537
541
  ret, sout, serr = run("-S")
538
- assert_eq ret, 0
539
- assert_eq sout, Oktest::MainApp.new.__send__(:skeleton)
540
- assert_eq serr, ""
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
- it "[!uxh5e] '-G' or '--generate' option prints test code." do
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
- assert_eq ret, 0
589
- assert_eq sout, expected
590
- assert_eq serr, ""
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
- assert_eq ret, 0
594
- assert_eq sout, expected
595
- assert_eq serr, ""
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
- it "[!wmxu5] '--generate=unaryop' option prints test code with unary op." do
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
- assert_eq ret, 0
634
- assert_eq sout, expected
635
- assert_eq serr, ""
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
- assert_eq ret, 0
639
- assert_eq sout, expected
640
- assert_eq serr, ""
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
- it "[!qs8ab] '--faster' chanages 'Config.ok_location' to false." do
647
- assert_eq Oktest::Config.ok_location, true
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
- assert_eq Oktest::Config.ok_location, false
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
- it "[!dsrae] reports if 'ok()' called but assertion not performed." do
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
- assert_eq ret, 1
680
- assert_eq serr, expected
683
+ test_eq? ret, 1
684
+ test_eq? serr, expected
681
685
  end
682
686
 
683
- it "[!bzgiw] returns total number of failures and errors." do
687
+ test_subject "[!bzgiw] returns total number of failures and errors." do
684
688
  ret, sout, serr = run(@testfile)
685
- assert_eq ret, 2 # 1 failure, 1 error
689
+ test_eq? ret, 2 # 1 failure, 1 error
686
690
  end
687
691
 
688
- it "[!937kw] recovers 'Config.color_enabled' value." do
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
- assert_eq Oktest::Config.color_enabled, bool
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
- describe '#skeleton()' do
706
- it "[!s2i1p] returns skeleton string of test script." do
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
- assert str =~ /^require 'oktest'$/
709
- assert str =~ /^Oktest\.scope do$/
712
+ test_match? str, /^require 'oktest'$/
713
+ test_match? str, /^Oktest\.scope do$/
710
714
  end
711
- it "[!opvik] skeleton string is valid ruby code." do
715
+ test_subject "[!opvik] skeleton string is valid ruby code." do
712
716
  str = Oktest::MainApp.new.__send__(:skeleton)
713
- filename = "tmp.skeleten.rb"
717
+ filename = "tmp.skeleton.rb"
714
718
  File.write(filename, str, encoding: 'utf-8')
715
719
  begin
716
- result = `ruby -wc #{filename}`
717
- assert_eq result, "Syntax OK\n"
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