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/mainapp_test.rb CHANGED
@@ -1,27 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
1
4
  ###
2
- ### $Release: 1.3.1 $
5
+ ### $Release: 1.5.0 $
3
6
  ### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
4
7
  ### $License: MIT License $
5
8
  ###
6
9
 
7
- require_relative './initialize'
10
+ require_relative './init'
8
11
 
9
12
 
10
- class MainApp_TC < TC
13
+ class MainApp__Test
14
+ extend NanoTest
15
+ extend Oktest::SpecHelper
11
16
 
12
- def setup
17
+ def self.test_subject(desc, &b)
13
18
  @testfile = "_tmp_test.rb"
14
- File.write(@testfile, INPUT, encoding: 'utf-8')
15
- @_color_enabled = Oktest::Config.color_enabled
19
+ File.write(@testfile, INPUT_5, encoding: 'utf-8')
20
+ color_enabled = Oktest::Config.color_enabled
16
21
  Oktest::Config.color_enabled = true
17
- end
18
-
19
- def teardown
20
- Oktest::Config.color_enabled = @_color_enabled
22
+ #
23
+ super
24
+ ensure
25
+ Oktest::Config.color_enabled = color_enabled
21
26
  File.unlink(@testfile)
22
27
  end
23
28
 
24
- INPUT = <<'END'
29
+ INPUT_5 = <<'END'
25
30
  require 'oktest'
26
31
 
27
32
  Oktest.scope do
@@ -73,7 +78,7 @@ end
73
78
 
74
79
  END
75
80
 
76
- def edit_actual(output)
81
+ def self.edit_actual(output)
77
82
  bkup = output.dup
78
83
  output = output.gsub(/^.*\r/, '')
79
84
  output = output.gsub(/^ .*(_test\.tmp:\d+)/, ' \1')
@@ -82,94 +87,102 @@ END
82
87
  return output
83
88
  end
84
89
 
85
- def edit_expected(expected)
90
+ def self.edit_expected(expected)
86
91
  expected = expected.gsub(/^ (.*:\d+)(:in `block .*)/, ' \1') if RUBY_VERSION < "1.9"
87
92
  expected = plain2colored(expected)
88
93
  return expected
89
94
  end
90
95
 
91
96
 
92
- describe '.main()' do
97
+ test_target 'Oktest::MainApp.main()' do
93
98
 
94
- def main(argv)
99
+ def self.main(argv)
95
100
  ret = nil
96
- sout, serr = capture do
101
+ sout, serr = capture_output! do
97
102
  ret = Oktest::MainApp.main(argv)
98
103
  end
99
104
  return ret, sout, serr
100
105
  end
101
106
 
102
- it "[!tb6sx] returns 0 when no errors raised." do
107
+ test_subject "[!tb6sx] returns 0 when no errors raised." do
103
108
  ret, sout, serr = main(["-h"])
104
- assert_eq ret, 0
105
- assert_eq serr, ""
109
+ test_eq? ret, 0
110
+ test_eq? serr, ""
106
111
  end
107
112
 
108
- it "[!d5mql] returns 1 when a certain error raised." do
113
+ test_subject "[!d5mql] returns 1 when a certain error raised." do
109
114
  ret, sout, serr = main(["-U"])
110
- assert_eq ret, 1
111
- assert_eq serr, "#{File.basename($0)}: -U: unknown option.\n"
115
+ test_eq? ret, 1
116
+ test_eq? serr, "[ERROR] -U: Unknown option.\n"
112
117
  end
113
118
 
114
- it "[!jr49p] reports error when unknown option specified." do
119
+ test_subject "[!jr49p] reports error when unknown option specified." do
115
120
  ret, sout, serr = main(["-X"])
116
- assert_eq ret, 1
117
- assert_eq serr, "#{File.basename($0)}: -X: unknown option.\n"
121
+ test_eq? ret, 1
122
+ test_eq? serr, "[ERROR] -X: Unknown option.\n"
118
123
  #
119
124
  ret, sout, serr = main(["--foobar"])
120
- assert_eq ret, 1
121
- assert_eq serr, "#{File.basename($0)}: --foobar: unknown option.\n"
125
+ test_eq? ret, 1
126
+ test_eq? serr, "[ERROR] --foobar: Unknown long option.\n"
122
127
  end
123
128
 
124
- it "[!uqomj] reports error when required argument is missing." do
129
+ test_subject "[!uqomj] reports error when required argument is missing." do
125
130
  ret, sout, serr = main(["-s"])
126
- assert_eq ret, 1
127
- assert_eq serr, "#{File.basename($0)}: -s: argument required.\n"
131
+ test_eq? ret, 1
132
+ test_eq? serr, "[ERROR] -s: Argument required.\n"
128
133
  end
129
134
 
130
- it "[!8i755] reports error when argument is invalid." do
135
+ test_subject "[!8i755] reports error when argument is invalid." do
131
136
  ret, sout, serr = main(["-s", "foobar"])
132
- assert_eq ret, 1
133
- assert_eq serr, "#{File.basename($0)}: -s foobar: invalid argument.\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"
134
139
  #
135
140
  ret, sout, serr = main(["-F", "aaa=*pat*"])
136
- assert_eq ret, 1
137
- assert_eq serr, "#{File.basename($0)}: -F aaa=*pat*: invalid argument.\n"
141
+ test_eq? ret, 1
142
+ test_eq? serr, "[ERROR] -F aaa=*pat*: Pattern unmatched.\n"
138
143
  #
139
- ret, sout, serr = main(["--color=true"])
140
- assert_eq ret, 1
141
- assert_eq serr, "#{File.basename($0)}: --color=true: invalid argument.\n"
144
+ ret, sout, serr = main(["--color=abc"])
145
+ test_eq? ret, 1
146
+ test_eq? serr, "[ERROR] --color=abc: Boolean expected.\n"
142
147
  end
143
148
 
144
149
  end
145
150
 
146
151
 
147
- describe '#run()' do
152
+ test_target 'Oktest::MainApp#run()' do
148
153
 
149
- def run(*args, tty: true)
154
+ def self.run(*args, tty: true)
150
155
  ret = nil
151
- sout, serr = capture("", tty: tty) do
156
+ sout, serr = capture_output! "", tty: tty do
152
157
  ret = Oktest::MainApp.new.run(*args)
153
158
  end
154
159
  return ret, sout, serr
155
160
  end
156
161
 
157
- it "[!18qpe] runs test scripts." do
162
+ test_subject "[!18qpe] runs test scripts." do
158
163
  expected = <<'END'
159
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
160
165
  END
161
166
  ret, sout, serr = run(@testfile)
162
- assert_eq ret, 2
163
- 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"
169
+ end
170
+
171
+ test_subject "[!k402d] raises error if file not found." do
172
+ filename = "not-exist-file"
173
+ exc = test_exception? Benry::CmdOpt::OptionError do
174
+ run(filename)
175
+ end
176
+ test_eq? exc.message, "#{filename}: not found."
164
177
  end
165
178
 
166
- it "[!bim36] changes auto-running to off." do
179
+ test_subject "[!bim36] changes auto-running to off." do
167
180
  Oktest::Config.auto_run = true
168
181
  _ = run(@testfile)
169
- assert_eq Oktest::Config.auto_run, false
182
+ test_eq? Oktest::Config.auto_run, false
170
183
  end
171
184
 
172
- it "[!hiu5b] finds test scripts in directory and runs them." do
185
+ test_subject "[!hiu5b] finds test scripts in directory and runs them." do
173
186
  expected = <<'END'
174
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
175
188
  END
@@ -179,15 +192,15 @@ END
179
192
  File.rename(@testfile, "#{dir}/d1/d2/#{@testfile}")
180
193
  begin
181
194
  ret, sout, serr = run(dir)
182
- assert_eq ret, 2
183
- 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"
184
197
  ensure
185
198
  File.rename("#{dir}/d1/d2/#{@testfile}", @testfile)
186
199
  dirs.reverse.each {|x| Dir.rmdir(x) }
187
200
  end
188
201
  end
189
202
 
190
- it "[!v5xie] parses $OKTEST_RB environment variable." do
203
+ test_subject "[!v5xie] parses $OKTEST_RB environment variable." do
191
204
  ret, sout, serr = run(@testfile, tty: false)
192
205
  expected = plain2colored(<<'END')
193
206
  ## _tmp_test.rb
@@ -196,7 +209,7 @@ END
196
209
  - [<C>pass</C>] 1+1 should be 2
197
210
  - [<C>pass</C>] 1-1 should be 0
198
211
  END
199
- assert sout.start_with?(expected), "expected verbose-style, but not."
212
+ test_ok? sout.start_with?(expected), msg: "expected verbose-style, but not."
200
213
  #
201
214
  begin
202
215
  ENV['OKTEST_RB'] = "-ss"
@@ -207,65 +220,88 @@ END
207
220
  * <b>Child1</b>: <C>.</C><C>.</C>
208
221
  * <b>Child2</b>: <R>f</R><E>E</E>
209
222
  END
210
- assert sout.start_with?(expected), "expected simple-style, but not."
223
+ test_ok? sout.start_with?(expected), msg: "expected simple-style, but not."
211
224
  ensure
212
225
  ENV.delete('OKTEST_RB')
213
226
  end
214
227
  end
215
228
 
229
+ test_subject "[!tt2gj] parses command options even after filenames." do
230
+ ret, sout, serr = run(@testfile, "--version")
231
+ test_eq? ret, 0
232
+ test_eq? sout, Oktest::VERSION+"\n"
233
+ test_eq? serr, ""
234
+ end
235
+
216
236
  #HELP_MESSAGE = Oktest::MainApp::HELP_MESSAGE % {command: File.basename($0)}
217
- HELP_MESSAGE = <<"END"
218
- Usage: #{File.basename($0)} [<options>] [<file-or-directory>...]
219
- -h, --help : show help
220
- --version : print version
221
- -s <REPORT-STYLE> : verbose/simple/compact/plain/quiet, or v/s/c/p/q
222
- -F <PATTERN> : filter topic or spec with pattern (see below)
223
- --color[={on|off}] : enable/disable output coloring forcedly
224
- -S, --skeleton : print test code skeleton
225
- -G, --generate : generate test code skeleton from ruby file
226
-
227
- Filter examples:
228
- $ oktest -F topic=Hello # filter by topic
229
- $ oktest -F spec='*hello*' # filter by spec
230
- $ oktest -F tag=name # filter by tag name
231
- $ oktest -F tag!=name # negative filter by tag name
232
- $ oktest -F tag='{name1,name2}' # filter by multiple tag names
233
-
234
- See https://github.com/kwatch/oktest/blob/ruby/ruby/README.md for details.
237
+ HELP_MESSAGE = (<<"END") % {command: File.basename($0)}
238
+ \e[1mOktest\e[0m (#{Oktest::VERSION}) -- New style testing library
239
+
240
+ \e[36mUsage:\e[0m
241
+ $ \e[1m%{command}\e[0m [<options>] [<file|directory>...]
242
+
243
+ \e[36mOptions:\e[0m
244
+ -h, --help : show help
245
+ --version : print version
246
+ -s <reporting-style> : verbose/simple/compact/plain/quiet, or v/s/c/p/q
247
+ -F <key>=<pattern> : filter topic or spec with pattern (see below)
248
+ --color[=<on|off>] : enable/disable output coloring forcedly
249
+ -S, --skeleton : print test code skeleton
250
+ -G, --generate[=<style>] : generate test code skeleton from ruby file
251
+
252
+ \e[36mFilter Examples:\e[0m
253
+ $ %{command} -F topic=Hello # filter by topic
254
+ $ %{command} -F spec='*hello*' # filter by spec
255
+ $ %{command} -F tag=name # filter by tag name
256
+ $ %{command} -F tag!=name # negative filter by tag name
257
+ $ %{command} -F tag='{name1,name2}' # filter by multiple tag names
258
+
259
+ \e[36mDocument:\e[0m
260
+ https://github.com/kwatch/oktest/blob/ruby/ruby/README.md
235
261
  END
236
262
 
237
- it "[!65vdx] prints help message if no arguments specified." do
263
+ test_subject "[!65vdx] prints help message if no arguments specified." do
238
264
  expected = HELP_MESSAGE
239
265
  ret, sout, serr = run()
240
- assert_eq ret, 0
241
- assert_eq sout, expected
242
- assert_eq serr, ""
266
+ test_eq? ret, 0
267
+ test_eq? sout, expected
268
+ test_eq? serr, ""
243
269
  end
244
270
 
245
- it "[!9973n] '-h' or '--help' option prints help message." do
271
+ test_subject "[!9973n] '-h' or '--help' option prints help message." do
246
272
  expected = HELP_MESSAGE
247
273
  #
248
274
  ret, sout, serr = run("-h")
249
- assert_eq ret, 0
250
- assert_eq sout, expected
251
- assert_eq serr, ""
275
+ test_eq? ret, 0
276
+ test_eq? sout, expected
277
+ test_eq? serr, ""
252
278
  #
253
279
  ret, sout, serr = run("--help")
254
- assert_eq ret, 0
255
- assert_eq sout, expected
256
- assert_eq serr, ""
280
+ test_eq? ret, 0
281
+ test_eq? sout, expected
282
+ test_eq? serr, ""
283
+ end
284
+
285
+ test_subject "[!v938d] help message will be colored only when stdout is a tty." do
286
+ ret, sout, serr = run("-h", tty: true)
287
+ test_ok? sout =~ /\e\[1mOktest\e\[0m/
288
+ test_ok? sout =~ /\e\[36mOptions:\e\[0m/
289
+ #
290
+ ret, sout, serr = run("-h", tty: false)
291
+ test_ok? sout !~ /\e\[1mOktest\e\[0m/
292
+ test_ok? sout !~ /\e\[36mOptions:\e\[0m/
257
293
  end
258
294
 
259
- it "[!qqizl] '--version' option prints version number." do
260
- expected = '$Release: 1.3.1 $'.split()[1] + "\n"
295
+ test_subject "[!qqizl] '--version' option prints version number." do
296
+ expected = '$Release: 1.5.0 $'.split()[1] + "\n"
261
297
  #
262
298
  ret, sout, serr = run("--version")
263
- assert_eq ret, 0
264
- assert_eq sout, expected
265
- assert_eq serr, ""
299
+ test_eq? ret, 0
300
+ test_eq? sout, expected
301
+ test_eq? serr, ""
266
302
  end
267
303
 
268
- 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
269
305
  expected = <<END
270
306
  ## _tmp_test.rb
271
307
  * <b>Parent</b>
@@ -279,17 +315,17 @@ END
279
315
  END
280
316
  #
281
317
  ret, sout, serr = run("-sv", @testfile)
282
- assert_eq ret, 2
283
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
284
- 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, ""
285
321
  #
286
322
  ret, sout, serr = run("-s", "verbose", @testfile)
287
- assert_eq ret, 2
288
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
289
- 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, ""
290
326
  end
291
327
 
292
- 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
293
329
  expected = <<END
294
330
  ## _tmp_test.rb
295
331
  * <b>Parent</b>: <C>.</C><C>.</C>
@@ -299,68 +335,68 @@ END
299
335
  END
300
336
  #
301
337
  ret, sout, serr = run("-ss", @testfile)
302
- assert_eq ret, 2
303
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
304
- 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, ""
305
341
  #
306
342
  ret, sout, serr = run("-s", "simple", @testfile)
307
- assert_eq ret, 2
308
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
309
- 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, ""
310
346
  end
311
347
 
312
- 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
313
349
  expected = <<END
314
350
  #{@testfile}: <C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C>
315
351
  ----------------------------------------------------------------------
316
352
  END
317
353
  #
318
354
  ret, sout, serr = run("-sc", @testfile)
319
- assert_eq ret, 2
320
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
321
- 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, ""
322
358
  #
323
359
  ret, sout, serr = run("-s", "compact", @testfile)
324
- assert_eq ret, 2
325
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
326
- 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, ""
327
363
  end
328
364
 
329
- 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
330
366
  expected = <<END
331
367
  <C>.</C><C>.</C><R>f</R><E>E</E><Y>s</Y><Y>t</Y><C>.</C><C>.</C>
332
368
  ----------------------------------------------------------------------
333
369
  END
334
370
  #
335
371
  ret, sout, serr = run("-sp", @testfile)
336
- assert_eq ret, 2
337
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
338
- 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, ""
339
375
  #
340
376
  ret, sout, serr = run("-s", "plain", @testfile)
341
- assert_eq ret, 2
342
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
343
- 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, ""
344
380
  end
345
381
 
346
- 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
347
383
  expected = <<END
348
384
  <R>f</R><E>E</E><Y>s</Y><Y>t</Y>
349
385
  ----------------------------------------------------------------------
350
386
  END
351
387
  #
352
388
  ret, sout, serr = run("-sq", @testfile)
353
- assert_eq ret, 2
354
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
355
- 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, ""
356
392
  #
357
393
  ret, sout, serr = run("-s", "quiet", @testfile)
358
- assert_eq ret, 2
359
- assert edit_actual(sout).start_with?(edit_expected(expected)), "invalid testcase output"
360
- 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, ""
361
397
  end
362
398
 
363
- it "[!yz7g5] '-F topic=...' option filters topics." do
399
+ test_subject "[!yz7g5] '-F topic=...' option filters topics." do
364
400
  expected = <<END
365
401
  ## _tmp_test.rb
366
402
  * <b>Parent</b>
@@ -371,12 +407,12 @@ END
371
407
  END
372
408
  #
373
409
  ret, sout, serr = run("-F", "topic=Child1", @testfile)
374
- assert_eq ret, 0
375
- assert_eq edit_actual(sout), edit_expected(expected)
376
- assert_eq serr, ""
410
+ test_eq? ret, 0
411
+ test_eq? edit_actual(sout), edit_expected(expected)
412
+ test_eq? serr, ""
377
413
  end
378
414
 
379
- it "[!ww2mp] '-F spec=...' option filters specs." do
415
+ test_subject "[!ww2mp] '-F spec=...' option filters specs." do
380
416
  expected = <<END
381
417
  ## _tmp_test.rb
382
418
  * <b>Parent</b>
@@ -386,12 +422,12 @@ END
386
422
  END
387
423
  #
388
424
  ret, sout, serr = run("-F", "spec=*1-1*", @testfile)
389
- assert_eq ret, 0
390
- assert_eq edit_actual(sout), edit_expected(expected)
391
- assert_eq serr, ""
425
+ test_eq? ret, 0
426
+ test_eq? edit_actual(sout), edit_expected(expected)
427
+ test_eq? serr, ""
392
428
  end
393
429
 
394
- it "[!8uvib] '-F tag=...' option filters by tag name." do
430
+ test_subject "[!8uvib] '-F tag=...' option filters by tag name." do
395
431
  expected = <<'END'
396
432
  ## _tmp_test.rb
397
433
  * <b>Parent</b>
@@ -406,12 +442,12 @@ END
406
442
  END
407
443
  #
408
444
  ret, sout, serr = run("-F", "tag={new,exp}", @testfile)
409
- assert_eq ret, 0
410
- assert_eq edit_actual(sout), edit_expected(expected)
411
- assert_eq serr, ""
445
+ test_eq? ret, 0
446
+ test_eq? edit_actual(sout), edit_expected(expected)
447
+ test_eq? serr, ""
412
448
  end
413
449
 
414
- it "[!m0iwm] '-F sid=...' option filters by spec id." do
450
+ test_subject "[!m0iwm] '-F sid=...' option filters by spec id." do
415
451
  expected = <<'END'
416
452
  ## _tmp_test.rb
417
453
  * <b>Parent</b>
@@ -421,12 +457,12 @@ END
421
457
  END
422
458
  #
423
459
  ret, sout, serr = run("-F", "sid=6hs1j", @testfile)
424
- assert_eq ret, 0
425
- assert_eq edit_actual(sout), edit_expected(expected)
426
- assert_eq serr, ""
460
+ test_eq? ret, 0
461
+ test_eq? edit_actual(sout), edit_expected(expected)
462
+ test_eq? serr, ""
427
463
  end
428
464
 
429
- it "[!noi8i] '-F' option supports negative filter." do
465
+ test_subject "[!noi8i] '-F' option supports negative filter." do
430
466
  expected = <<'END'
431
467
  ## _tmp_test.rb
432
468
  * <b>Parent</b>
@@ -439,78 +475,73 @@ END
439
475
  END
440
476
  #
441
477
  ret, sout, serr = run("-F", "tag!={fail,err,exp}", @testfile)
442
- assert_eq ret, 0
443
- assert_eq edit_actual(sout), edit_expected(expected)
444
- assert_eq serr, ""
478
+ test_eq? ret, 0
479
+ test_eq? edit_actual(sout), edit_expected(expected)
480
+ test_eq? serr, ""
445
481
  end
446
482
 
447
- it "[!71h2x] '-F ...' option will be error." do
448
- assert_exc(OptionParser::InvalidArgument, "invalid argument: -F *pat*") do
483
+ test_subject "[!71h2x] '-F ...' option will be error." do
484
+ exc = test_exception? Benry::CmdOpt::OptionError do
449
485
  run("-F", "*pat*", @testfile)
450
486
  end
487
+ test_eq? exc.message, "-F *pat*: Pattern unmatched."
451
488
  end
452
489
 
453
- 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
454
491
  expected = <<'END'
455
492
  ## total:0 (pass:0, fail:0, error:0, skip:0, todo:0) in 0.000s
456
493
  END
457
494
  #
458
495
  ret, sout, serr = run("-F", "tag=blablabla", @testfile)
459
- assert_eq ret, 0
460
- assert_eq edit_actual(sout), edit_expected(expected)
461
- assert_eq serr, ""
496
+ test_eq? ret, 0
497
+ test_eq? edit_actual(sout), edit_expected(expected)
498
+ test_eq? serr, ""
462
499
  end
463
500
 
464
- it "[!6ro7j] '--color=on' option enables output coloring forcedly." do
501
+ test_subject "[!6ro7j] '--color=on' option enables output coloring forcedly." do
465
502
  [true, false].each do |bool|
466
503
  [true, false].each do |tty|
467
504
  Oktest::Config.color_enabled = bool
468
505
  _, sout, serr = run("--color=on", @testfile, tty: tty)
469
- assert sout.include?(edit_expected("[<C>pass</C>]")), "should contain blue string"
470
- assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
471
- assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
472
- 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, ""
473
510
  end
474
511
  end
475
512
  end
476
513
 
477
- it "[!dptgn] '--color' is same as '--color=on'." do
514
+ test_subject "[!dptgn] '--color' is same as '--color=on'." do
478
515
  [true, false].each do |bool|
479
516
  [true, false].each do |tty|
480
517
  Oktest::Config.color_enabled = bool
481
518
  _, sout, serr = run("--color", @testfile, tty: tty)
482
- assert sout.include?(edit_expected("[<C>pass</C>]")), "should contain blue string"
483
- assert sout.include?(edit_expected("[<R>Fail</R>]")), "should contain red string"
484
- assert sout.include?(edit_expected("[<Y>Skip</Y>]")), "should contain yellos string"
485
- 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, ""
486
523
  end
487
524
  end
488
525
  end
489
526
 
490
- it "[!vmw0q] '--color=off' option disables output coloring forcedly." do
527
+ test_subject "[!vmw0q] '--color=off' option disables output coloring forcedly." do
491
528
  [true, false].each do |bool|
492
529
  [true, false].each do |tty|
493
530
  Oktest::Config.color_enabled = bool
494
531
  _, sout, serr = run("--color=off", @testfile, tty: tty)
495
- assert !sout.include?(edit_expected("[<C>pass</C>]")), "should not contain blue string"
496
- assert !sout.include?(edit_expected("[<R>Fail</R>]")), "should not contain red string"
497
- assert !sout.include?(edit_expected("[<Y>Skip</Y>]")), "should not contain yellos string"
498
- 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, ""
499
536
  end
500
537
  end
501
538
  end
502
539
 
503
- it "[!9nr94] '--color=true' option raises error." do
504
- assert_exc(OptionParser::InvalidArgument, "invalid argument: --color=true") do
505
- run("--color=true", @testfile)
506
- end
507
- end
508
-
509
- it "[!dk8eg] '-S' or '--skeleton' option prints test code skeleton." do
540
+ test_subject "[!dk8eg] '-S' or '--skeleton' option prints test code skeleton." do
510
541
  ret, sout, serr = run("-S")
511
- assert_eq ret, 0
512
- assert_eq sout, Oktest::MainApp::SKELETON
513
- assert_eq serr, ""
542
+ test_eq? ret, 0
543
+ test_eq? sout, Oktest::MainApp.new.__send__(:skeleton)
544
+ test_eq? serr, ""
514
545
  end
515
546
 
516
547
  HELLO_CLASS_DEF = <<'END'
@@ -526,7 +557,7 @@ class Hello
526
557
  end
527
558
  END
528
559
 
529
- it "[!uxh5e] '-G' or '--generate' option prints test code." do
560
+ test_subject "[!uxh5e] '-G' or '--generate' option prints test code." do
530
561
  input = HELLO_CLASS_DEF
531
562
  filename = "_tmpcode_4674.rb"
532
563
  File.write(filename, input)
@@ -547,7 +578,7 @@ Oktest.scope do
547
578
 
548
579
  spec "returns greeting message."
549
580
 
550
- end # #hello()
581
+ end
551
582
 
552
583
 
553
584
  end # Hello
@@ -558,20 +589,20 @@ END
558
589
  #
559
590
  begin
560
591
  ret, sout, serr = run("-G", filename)
561
- assert_eq ret, 0
562
- assert_eq sout, expected
563
- assert_eq serr, ""
592
+ test_eq? ret, 0
593
+ test_eq? sout, expected
594
+ test_eq? serr, ""
564
595
  #
565
596
  ret, sout, serr = run("--generate", filename)
566
- assert_eq ret, 0
567
- assert_eq sout, expected
568
- assert_eq serr, ""
597
+ test_eq? ret, 0
598
+ test_eq? sout, expected
599
+ test_eq? serr, ""
569
600
  ensure
570
601
  File.unlink(filename)
571
602
  end
572
603
  end
573
604
 
574
- 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
575
606
  input = HELLO_CLASS_DEF
576
607
  filename = "_tmpcode_6431.rb"
577
608
  File.write(filename, input)
@@ -592,7 +623,7 @@ Oktest.scope do
592
623
 
593
624
  - spec("returns greeting message.")
594
625
 
595
- end # #hello()
626
+ end
596
627
 
597
628
 
598
629
  end # Hello
@@ -602,31 +633,31 @@ end
602
633
  END
603
634
  #
604
635
  begin
605
- ret, sout, serr = run("-gunaryop", filename)
606
- assert_eq ret, 0
607
- assert_eq sout, expected
608
- assert_eq serr, ""
636
+ ret, sout, serr = run("-Gunaryop", filename)
637
+ test_eq? ret, 0
638
+ test_eq? sout, expected
639
+ test_eq? serr, ""
609
640
  #
610
641
  ret, sout, serr = run("--generate=unaryop", filename)
611
- assert_eq ret, 0
612
- assert_eq sout, expected
613
- assert_eq serr, ""
642
+ test_eq? ret, 0
643
+ test_eq? sout, expected
644
+ test_eq? serr, ""
614
645
  ensure
615
646
  File.unlink(filename)
616
647
  end
617
648
  end
618
649
 
619
- it "[!qs8ab] '--faster' chanages 'Config.ok_location' to false." do
620
- 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
621
652
  begin
622
653
  run("--faster", @testfile)
623
- assert_eq Oktest::Config.ok_location, false
654
+ test_eq? Oktest::Config.ok_location, false
624
655
  ensure
625
656
  Oktest::Config.ok_location = true
626
657
  end
627
658
  end
628
659
 
629
- it "[!dsrae] reports if 'ok()' called but assertion not performed." do
660
+ test_subject "[!dsrae] reports if 'ok()' called but assertion not performed." do
630
661
  input = <<'END'
631
662
  require 'oktest'
632
663
  Oktest.scope do
@@ -649,23 +680,23 @@ END
649
680
  ** warning: ok() is called but not tested yet (at #{@testfile}:11:in `block (3 levels) in <top (required)>').
650
681
  END
651
682
  ret, sout, serr = run(@testfile)
652
- assert_eq ret, 1
653
- assert_eq serr, expected
683
+ test_eq? ret, 1
684
+ test_eq? serr, expected
654
685
  end
655
686
 
656
- it "[!bzgiw] returns total number of failures and errors." do
687
+ test_subject "[!bzgiw] returns total number of failures and errors." do
657
688
  ret, sout, serr = run(@testfile)
658
- assert_eq ret, 2 # 1 failure, 1 error
689
+ test_eq? ret, 2 # 1 failure, 1 error
659
690
  end
660
691
 
661
- it "[!937kw] recovers 'Config.color_enabled' value." do
692
+ test_subject "[!937kw] recovers 'Config.color_enabled' value." do
662
693
  bkup = Oktest::Config.color_enabled
663
694
  begin
664
695
  [true, false].each do |bool|
665
696
  ["on", "off"].each do |flag|
666
697
  Oktest::Config.color_enabled = bool
667
698
  run(@testfile, "--color=#{flag}")
668
- assert_eq Oktest::Config.color_enabled, bool
699
+ test_eq? Oktest::Config.color_enabled, bool
669
700
  end
670
701
  end
671
702
  ensure
@@ -675,4 +706,23 @@ END
675
706
 
676
707
  end
677
708
 
709
+ test_target 'Oktest::MainApp#skeleton()' do
710
+ test_subject "[!s2i1p] returns skeleton string of test script." do
711
+ str = Oktest::MainApp.new.__send__(:skeleton)
712
+ test_match? str, /^require 'oktest'$/
713
+ test_match? str, /^Oktest\.scope do$/
714
+ end
715
+ test_subject "[!opvik] skeleton string is valid ruby code." do
716
+ str = Oktest::MainApp.new.__send__(:skeleton)
717
+ filename = "tmp.skeleton.rb"
718
+ File.write(filename, str, encoding: 'utf-8')
719
+ begin
720
+ result = `ruby -wc #{filename}` # may reports warning
721
+ test_eq? result, "Syntax OK\n"
722
+ ensure
723
+ File.unlink filename
724
+ end
725
+ end
726
+ end
727
+
678
728
  end