rubytest 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY.md +29 -0
- data/README.md +29 -4
- data/demo/05_builtin_reporters.md +44 -0
- data/demo/06_rake_task.md +87 -0
- data/lib/rubytest/format/abstract_hash.rb +8 -4
- data/lib/rubytest/format/html.rb +144 -0
- data/lib/rubytest/rake.rb +128 -0
- data/lib/rubytest/runner.rb +1 -1
- data/lib/rubytest.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 429759d74415135b8167fe2c08f42100e71db076c1935224295aa8f0a1d4f2de
|
|
4
|
+
data.tar.gz: eae2b813dd229d5c1e6cdeb4dd26fa43bf622e09759d76d12914e48011a48b14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 526daa4c7ea189e1b90aec1ad044ca3d04f687dd93560a4355e45de14c036dc2cad92059fabb9673163cf8d1af38eb9f462cdc91a13c4f1b86e40645a691932b
|
|
7
|
+
data.tar.gz: e6f28deb96beae66e9e5b8d4863f51b5cf4bb661c54e4c33a50dc69e86ac1c405b11b80e9d45a0d0ff20e6f4554dee55a0fcf145222db803f513b77e50123a5c
|
data/HISTORY.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# RELEASE HISTORY
|
|
2
2
|
|
|
3
|
+
## 0.11.1 / 2026-11-20
|
|
4
|
+
|
|
5
|
+
Fixes a crash in the TAP-Y and TAP-J reporters.
|
|
6
|
+
|
|
7
|
+
Changes:
|
|
8
|
+
|
|
9
|
+
* Fix the TAP-Y and TAP-J reporters, which raised NoMethodError
|
|
10
|
+
("undefined method 'file' for nil") for a failed, errored or pending test
|
|
11
|
+
whose exception had no backtrace line outside the test framework. Lemon
|
|
12
|
+
marks a test pending that way when it doesn't call the method it covers.
|
|
13
|
+
The run then ended early with wrong counts. The record now has the
|
|
14
|
+
exception's message without a source location.
|
|
15
|
+
|
|
16
|
+
## 0.11.0 / 2026-11-17
|
|
17
|
+
|
|
18
|
+
The Rake task and the HTML reporter are back in Rubytest, so rubytest-rake
|
|
19
|
+
and rubytest-html are no longer needed. With this, everything that was spun
|
|
20
|
+
off into a separate gem is part of Rubytest again.
|
|
21
|
+
|
|
22
|
+
Changes:
|
|
23
|
+
|
|
24
|
+
* Bring the HTML reporter in from rubytest-html, rewritten for the recorder:
|
|
25
|
+
`rubytest -f html`. It escapes what it writes, reports skipped tests and
|
|
26
|
+
cases, and shows captured output with each test.
|
|
27
|
+
* Bring the Rake task in from rubytest-rake: `require 'rubytest/rake'` for
|
|
28
|
+
`Test::Rake::TestTask`. The task now fails when the run does (it always
|
|
29
|
+
exited 0), runs only the default globs that match a file, and lets `TEST`
|
|
30
|
+
replace the task's files for one invocation.
|
|
31
|
+
|
|
3
32
|
## 0.10.0 / 2026-11-17
|
|
4
33
|
|
|
5
34
|
Results now go through a recorder to the reporters, and the reporters that
|
data/README.md
CHANGED
|
@@ -58,8 +58,10 @@ test), `outline` (nested cases), `progress` (running count and timing), `tap`
|
|
|
58
58
|
(TAP version 13), and `tapy` and `tapj` (TAP-Y and TAP-J, the structured
|
|
59
59
|
streams that [tapout](https://github.com/rubyworks/tapout) reads). Select one
|
|
60
60
|
with `rubytest -f FORMAT`; `-y` and `-j` are short for `-f tapy` and `-f tapj`.
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
`html` writes the whole run as one self-contained HTML document
|
|
62
|
+
(`rubytest -f html > report.html`). Formats load only when selected. The TAP
|
|
63
|
+
and HTML formats capture test output: TAP emits it as diagnostics, and TAP-Y,
|
|
64
|
+
TAP-J and HTML record it with each test.
|
|
63
65
|
|
|
64
66
|
|
|
65
67
|
## Installation
|
|
@@ -122,8 +124,31 @@ named profile, use the `-p/--profile` option:
|
|
|
122
124
|
The configuration file can also be at `config/test.rb`, `Testfile`,
|
|
123
125
|
or `.test` (with optional `.rb` extension).
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
### Via Rake
|
|
128
|
+
|
|
129
|
+
Rubytest has a Rake task. In your Rakefile:
|
|
130
|
+
|
|
131
|
+
require 'rubytest/rake'
|
|
132
|
+
|
|
133
|
+
Test::Rake::TestTask.new do |run|
|
|
134
|
+
run.loadpath 'lib'
|
|
135
|
+
run.test_files << 'test/*_test.rb'
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
The block takes the same settings as `Test.configure`. With no files, the
|
|
139
|
+
task runs whichever of `test/**/test_*.rb`, `*_test.rb`, `case_*.rb` and
|
|
140
|
+
`*_case.rb` it finds, and with no load path it adds `lib`. The task is named
|
|
141
|
+
`test` unless you give it another name (`TestTask.new('spec')`).
|
|
142
|
+
|
|
143
|
+
To run only some tests for one invocation, set `TEST`:
|
|
144
|
+
|
|
145
|
+
$ rake test TEST=test/foo_test.rb
|
|
146
|
+
|
|
147
|
+
Where the platform can fork, the tests run in a child process, so what they
|
|
148
|
+
load stays out of Rake's. `rake test` fails if the run does.
|
|
149
|
+
|
|
150
|
+
A configuration file isn't read by the task. To use one, shell out to
|
|
151
|
+
`rubytest` instead:
|
|
127
152
|
|
|
128
153
|
desc "run tests"
|
|
129
154
|
task :test do
|
|
@@ -104,6 +104,26 @@ YAML documents, TAP-J a line of JSON for each record.
|
|
|
104
104
|
records.count { |record| record['type'] == 'case' && !record['status'] }.assert == 2
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
+
An exception may have no line of backtrace outside the test framework, as
|
|
108
|
+
when a framework marks a test pending itself. Its record then has the message
|
|
109
|
+
without a source location.
|
|
110
|
+
|
|
111
|
+
bare = probe_type.new('bare') do
|
|
112
|
+
error = NotImplementedError.new('not tested')
|
|
113
|
+
error.set_backtrace([])
|
|
114
|
+
raise error
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
readers.each do |format, read|
|
|
118
|
+
success, output, report = render.call(format, [bare, passing])
|
|
119
|
+
records = read.call(output)
|
|
120
|
+
records.last['counts']['total'].assert == 2
|
|
121
|
+
record = records.find { |r| r['label'] == 'bare' }
|
|
122
|
+
record['status'].assert == 'todo'
|
|
123
|
+
record['exception']['message'].assert == 'not tested'
|
|
124
|
+
record['exception'].key?('file').assert == false
|
|
125
|
+
end
|
|
126
|
+
|
|
107
127
|
A TAP-Y stream ends with the YAML end-of-document marker.
|
|
108
128
|
|
|
109
129
|
render.call('tapy')[1].lines.last.chomp.assert == '...'
|
|
@@ -116,3 +136,27 @@ The command line has a shortcut for each.
|
|
|
116
136
|
cli.options.parse!([flag])
|
|
117
137
|
cli.format.assert == format
|
|
118
138
|
end
|
|
139
|
+
|
|
140
|
+
The HTML format writes one self-contained document once the run has
|
|
141
|
+
finished. Names, messages and captured output are escaped.
|
|
142
|
+
|
|
143
|
+
markup = probe_type.new('markup <b>&</b>') { print '<script>'; true }
|
|
144
|
+
html_suite = [Class.new(Array) { def to_s; 'a <case>'; end }.new([markup, failing]),
|
|
145
|
+
pending, skipped, skipped_case, broken_case]
|
|
146
|
+
success, output, report = render.call('html', html_suite)
|
|
147
|
+
success.assert == false
|
|
148
|
+
|
|
149
|
+
output.lines.first.chomp.assert == '<!DOCTYPE html>'
|
|
150
|
+
output.lines.last.chomp.assert == '</html>'
|
|
151
|
+
output.scan('<div class="result ').size.assert == report.total
|
|
152
|
+
output.scan('<section class="case">').size.assert == output.scan('</section>').size
|
|
153
|
+
%w[pass fail error todo skip].each do |status|
|
|
154
|
+
output.include?(%[<div class="result #{status}">]).assert == true
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
output.include?('markup <b>&</b>').assert == true
|
|
158
|
+
output.include?('<h2>a <case></h2>').assert == true
|
|
159
|
+
output.include?('<pre class="stdout"><script></pre>').assert == true
|
|
160
|
+
output.include?('<script>').assert == false
|
|
161
|
+
output.include?('Assertion: ').assert == true
|
|
162
|
+
output.include?('6 tests: 1 passing, 1 failures, 1 errors, 1 pending, 2 skipped.').assert == true
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
## Rake task
|
|
2
|
+
|
|
3
|
+
`rubytest/rake` provides a task for running tests from a Rakefile.
|
|
4
|
+
|
|
5
|
+
require 'rubytest/rake'
|
|
6
|
+
require 'tmpdir'
|
|
7
|
+
|
|
8
|
+
project = Dir.mktmpdir('rubytest-rake')
|
|
9
|
+
Dir.mkdir(File.join(project, 'test'))
|
|
10
|
+
|
|
11
|
+
probe = lambda do |label, body|
|
|
12
|
+
<<-RUBY
|
|
13
|
+
probe = Object.new
|
|
14
|
+
probe.define_singleton_method(:call) { #{body} }
|
|
15
|
+
probe.define_singleton_method(:to_s) { #{label.inspect} }
|
|
16
|
+
$TEST_SUITE << probe
|
|
17
|
+
RUBY
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
File.write(File.join(project, 'test', 'good_test.rb'), probe.call('good', 'true'))
|
|
21
|
+
File.write(File.join(project, 'bad.rb'), probe.call('bad', "raise Assertion, 'wrong value'"))
|
|
22
|
+
|
|
23
|
+
status_of = lambda do |task|
|
|
24
|
+
Dir.chdir(project) do
|
|
25
|
+
begin
|
|
26
|
+
task.run
|
|
27
|
+
0
|
|
28
|
+
rescue SystemExit => exit
|
|
29
|
+
exit.status
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
The block configures the run, as with `Test.configure`. The task is an
|
|
35
|
+
ordinary Rake task.
|
|
36
|
+
|
|
37
|
+
passing = Test::Rake::TestTask.new('demo:pass') do |run|
|
|
38
|
+
run.files << 'test/good_test.rb'
|
|
39
|
+
run.format = 'test'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Rake::Task.task_defined?('demo:pass').assert == true
|
|
43
|
+
status_of.call(passing).assert == 0
|
|
44
|
+
|
|
45
|
+
A run that fails makes the task exit with status 1, so that `rake` fails too.
|
|
46
|
+
|
|
47
|
+
failing = Test::Rake::TestTask.new('demo:fail') do |run|
|
|
48
|
+
run.files << 'bad.rb'
|
|
49
|
+
run.format = 'test'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
status_of.call(failing).assert == 1
|
|
53
|
+
|
|
54
|
+
Given no files, the task looks under `test/` for files named `test_*.rb`,
|
|
55
|
+
`*_test.rb`, `case_*.rb` or `*_case.rb`, and runs whichever of those it
|
|
56
|
+
finds. It also puts `lib` on the load path.
|
|
57
|
+
|
|
58
|
+
defaults = Test::Rake::TestTask.new('demo:defaults') { |run| run.format = 'test' }
|
|
59
|
+
|
|
60
|
+
status_of.call(defaults).assert == 0
|
|
61
|
+
defaults.config.files.assert == ['test/**/*_test.rb']
|
|
62
|
+
defaults.config.loadpath.assert == ['lib']
|
|
63
|
+
|
|
64
|
+
If it finds none, it says so.
|
|
65
|
+
|
|
66
|
+
empty = Dir.mktmpdir('rubytest-rake-empty')
|
|
67
|
+
nothing = Test::Rake::TestTask.new('demo:nothing') { |run| run.format = 'test' }
|
|
68
|
+
missing = begin
|
|
69
|
+
Dir.chdir(empty) { nothing.run }
|
|
70
|
+
nil
|
|
71
|
+
rescue ArgumentError => error
|
|
72
|
+
error
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
missing.message.assert.start_with?('no test files found')
|
|
76
|
+
|
|
77
|
+
The `TEST` environment variable selects the tests for one invocation, in
|
|
78
|
+
place of the task's own.
|
|
79
|
+
|
|
80
|
+
previous = ENV['TEST']
|
|
81
|
+
begin
|
|
82
|
+
ENV['TEST'] = 'bad.rb'
|
|
83
|
+
status_of.call(passing).assert == 1
|
|
84
|
+
passing.config.files.assert == ['bad.rb']
|
|
85
|
+
ensure
|
|
86
|
+
ENV['TEST'] = previous
|
|
87
|
+
end
|
|
@@ -275,10 +275,14 @@ module Test::Reporters
|
|
|
275
275
|
# Add exception subsection of hash.
|
|
276
276
|
def merge_exception(hash, test, exception, bt=false)
|
|
277
277
|
hash['exception'] = {}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
278
|
+
# There is no snippet when every line of the backtrace belongs to
|
|
279
|
+
# the test framework, or the exception has none.
|
|
280
|
+
if snippet = code(exception)
|
|
281
|
+
hash['exception']['file' ] = snippet.file
|
|
282
|
+
hash['exception']['line' ] = snippet.line
|
|
283
|
+
hash['exception']['source' ] = snippet.to_str
|
|
284
|
+
hash['exception']['snippet' ] = snippet.to_omap
|
|
285
|
+
end
|
|
282
286
|
hash['exception']['message' ] = exception.message
|
|
283
287
|
hash['exception']['backtrace'] = clean_backtrace(exception) if bt
|
|
284
288
|
if @current_result && @current_result.exceptions.size > 1
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
module Test::Reporters
|
|
4
|
+
|
|
5
|
+
# HTML Test Reporter
|
|
6
|
+
#
|
|
7
|
+
# Writes the run as one self-contained HTML document, once the run has
|
|
8
|
+
# finished: a tally, then every result under the heading of its case.
|
|
9
|
+
# Test output is captured and shown with the test that wrote it.
|
|
10
|
+
#
|
|
11
|
+
class Html < Abstract
|
|
12
|
+
|
|
13
|
+
LABELS = {
|
|
14
|
+
:pass => 'PASS',
|
|
15
|
+
:fail => 'FAIL',
|
|
16
|
+
:error => 'ERROR',
|
|
17
|
+
:todo => 'TODO',
|
|
18
|
+
:skip => 'SKIP'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ESCAPES = {
|
|
22
|
+
'&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => '''
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
STYLE = <<-CSS
|
|
26
|
+
:root { color-scheme: light dark; --pass: #1a7f37; --fail: #cf222e; --todo: #9a6700; --skip: #57606a; --line: #d0d7de; }
|
|
27
|
+
@media (prefers-color-scheme: dark) { :root { --pass: #3fb950; --fail: #f85149; --todo: #d29922; --skip: #8b949e; --line: #30363d; } }
|
|
28
|
+
body { font-family: system-ui, sans-serif; line-height: 1.5; max-width: 60rem; margin: 2rem auto; padding: 0 1rem; }
|
|
29
|
+
h1 { margin-bottom: 0.25rem; }
|
|
30
|
+
.tally { font-weight: bold; }
|
|
31
|
+
.tally.passed { color: var(--pass); }
|
|
32
|
+
.tally.failed { color: var(--fail); }
|
|
33
|
+
section { border-left: 2px solid var(--line); padding-left: 1rem; margin: 1rem 0; }
|
|
34
|
+
.result { margin: 0.25rem 0; }
|
|
35
|
+
.status { display: inline-block; min-width: 3.5rem; font: bold 0.85em ui-monospace, monospace; }
|
|
36
|
+
.pass .status { color: var(--pass); }
|
|
37
|
+
.fail .status, .error .status { color: var(--fail); }
|
|
38
|
+
.todo .status { color: var(--todo); }
|
|
39
|
+
.skip .status { color: var(--skip); }
|
|
40
|
+
.time, .reason, footer { color: var(--skip); font-size: 0.85em; }
|
|
41
|
+
pre { margin: 0.25rem 0 0.5rem 3.5rem; padding: 0.5rem; border: 1px solid var(--line); overflow-x: auto; font-size: 0.85em; }
|
|
42
|
+
CSS
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
def initialize(runner, output: $stdout)
|
|
46
|
+
super(runner)
|
|
47
|
+
@output = output
|
|
48
|
+
@body = []
|
|
49
|
+
@depth = 0
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Test output would otherwise land in the middle of the document.
|
|
53
|
+
def capture_output?
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
#
|
|
58
|
+
def begin_suite(suite)
|
|
59
|
+
@body = []
|
|
60
|
+
@depth = 0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
#
|
|
64
|
+
def begin_case(test_case)
|
|
65
|
+
title, *rest = test_case.to_s.strip.split("\n")
|
|
66
|
+
level = [@depth + 2, 6].min
|
|
67
|
+
@body << %[<section class="case">]
|
|
68
|
+
@body << %[<h#{level}>#{h title}</h#{level}>]
|
|
69
|
+
@body << %[<p>#{rest.map{ |line| h(line.strip) }.join('<br>')}</p>] unless rest.empty?
|
|
70
|
+
@depth += 1
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#
|
|
74
|
+
def end_case(test_case)
|
|
75
|
+
@depth -= 1
|
|
76
|
+
@body << %[</section>]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Add a completed result to the document.
|
|
80
|
+
def record(result)
|
|
81
|
+
label = result.test.to_s.strip.split("\n").first.to_s
|
|
82
|
+
label = "#{label} (case)" if result.kind == :case
|
|
83
|
+
|
|
84
|
+
line = %[<span class="status">#{LABELS.fetch(result.status)}</span> #{h label}]
|
|
85
|
+
line << %[ <span class="reason">#{h result.reason}</span>] if result.status == :skip && result.reason
|
|
86
|
+
line << %[ <span class="reason">#{h result.exception.message}</span>] if result.status == :todo && result.exception
|
|
87
|
+
line << %[ <span class="time">#{'%.5fs' % result.elapsed}</span>]
|
|
88
|
+
|
|
89
|
+
@body << %[<div class="result #{result.status}">#{line}]
|
|
90
|
+
if [:fail, :error].include?(result.status)
|
|
91
|
+
result.exceptions.each{ |exception| @body << %[<pre>#{h detail(exception, result.status == :error)}</pre>] }
|
|
92
|
+
end
|
|
93
|
+
@body << %[<pre class="stdout">#{h result.stdout}</pre>] unless result.stdout.empty?
|
|
94
|
+
@body << %[<pre class="stderr">#{h result.stderr}</pre>] unless result.stderr.empty?
|
|
95
|
+
@body << %[</div>]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Write the document.
|
|
99
|
+
def finish(summary)
|
|
100
|
+
outcome = summary.success? ? 'passed' : 'failed'
|
|
101
|
+
tally = if summary.total.zero?
|
|
102
|
+
'No tests were run.'
|
|
103
|
+
else
|
|
104
|
+
counts = ::Test::Result::STATUSES.map{ |status| "#{summary.counts[status]} #{TITLES[status]}" }
|
|
105
|
+
"#{summary.total} tests: #{counts.join(', ')}."
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
@output.puts '<!DOCTYPE html>'
|
|
109
|
+
@output.puts '<html lang="en">'
|
|
110
|
+
@output.puts '<head>'
|
|
111
|
+
@output.puts '<meta charset="utf-8">'
|
|
112
|
+
@output.puts '<meta name="viewport" content="width=device-width, initial-scale=1">'
|
|
113
|
+
@output.puts '<title>Test Report</title>'
|
|
114
|
+
@output.puts "<style>\n#{STYLE.gsub(/^ /, '')}</style>"
|
|
115
|
+
@output.puts '</head>'
|
|
116
|
+
@output.puts '<body>'
|
|
117
|
+
@output.puts '<h1>Test Report</h1>'
|
|
118
|
+
@output.puts %[<p class="tally #{outcome}">#{h tally}</p>]
|
|
119
|
+
@output.puts @body.join("\n") unless @body.empty?
|
|
120
|
+
@output.puts %[<footer>Finished in #{'%.5fs' % summary.elapsed}. Generated by Rubytest #{h ::Test::VERSION} on #{h Time.now.strftime('%Y-%m-%d %H:%M:%S')}.</footer>]
|
|
121
|
+
@output.puts '</body>'
|
|
122
|
+
@output.puts '</html>'
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
# Escape text for use in HTML.
|
|
128
|
+
def h(text)
|
|
129
|
+
text.to_s.gsub(/[&<>"']/, ESCAPES)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# An exception's class, message and where it was raised, with the rest
|
|
133
|
+
# of its backtrace if asked.
|
|
134
|
+
def detail(exception, backtrace=false)
|
|
135
|
+
lines = ["#{exception.class}: #{exception.message}"]
|
|
136
|
+
trace = exception.backtrace ? clean_backtrace(exception) : []
|
|
137
|
+
trace = trace.first(1) unless backtrace
|
|
138
|
+
lines.concat(trace.map{ |line| " #{line}" })
|
|
139
|
+
lines.join("\n")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'rubytest'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/tasklib'
|
|
4
|
+
|
|
5
|
+
module Test
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Rake subspace.
|
|
9
|
+
#
|
|
10
|
+
module Rake
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# Define a rake task that runs tests.
|
|
14
|
+
#
|
|
15
|
+
# require 'rubytest/rake'
|
|
16
|
+
#
|
|
17
|
+
# Test::Rake::TestTask.new do |run|
|
|
18
|
+
# run.loadpath 'lib'
|
|
19
|
+
# run.files << 'test/*_test.rb'
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# The block is given the task's Test::Config, the same object that
|
|
23
|
+
# `Test.configure` yields. Without any files, the task runs whichever
|
|
24
|
+
# of DEFAULT_TESTS match, and without a load path it adds `lib`.
|
|
25
|
+
#
|
|
26
|
+
# The `TEST` environment variable selects the tests to run for one
|
|
27
|
+
# invocation, in place of the task's own: `rake test TEST=test/foo_test.rb`.
|
|
28
|
+
# Separate several files or globs with `:` or `;`.
|
|
29
|
+
#
|
|
30
|
+
# Where the platform can fork, tests run in a child process, so that
|
|
31
|
+
# what they load doesn't stay in Rake's. If the run is unsuccessful the
|
|
32
|
+
# task exits with status 1.
|
|
33
|
+
#
|
|
34
|
+
class TestTask < ::Rake::TaskLib
|
|
35
|
+
|
|
36
|
+
# Globs used to find test files when the task is given none.
|
|
37
|
+
DEFAULT_TESTS = [
|
|
38
|
+
'test/**/case_*.rb',
|
|
39
|
+
'test/**/*_case.rb',
|
|
40
|
+
'test/**/test_*.rb',
|
|
41
|
+
'test/**/*_test.rb'
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
# Name of the task.
|
|
45
|
+
#
|
|
46
|
+
# @return [String]
|
|
47
|
+
attr :name
|
|
48
|
+
|
|
49
|
+
# Test run configuration.
|
|
50
|
+
#
|
|
51
|
+
# @return [Config]
|
|
52
|
+
attr :config
|
|
53
|
+
|
|
54
|
+
# Initialize new Rake::TestTask instance.
|
|
55
|
+
#
|
|
56
|
+
def initialize(name='test', desc='run tests', &block)
|
|
57
|
+
@name = (name || 'test').to_s
|
|
58
|
+
@desc = desc
|
|
59
|
+
|
|
60
|
+
@config = Test::Config.new
|
|
61
|
+
|
|
62
|
+
block.call(@config) if block
|
|
63
|
+
|
|
64
|
+
define_task
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Define rake task for testing.
|
|
68
|
+
#
|
|
69
|
+
# @return nothing
|
|
70
|
+
def define_task
|
|
71
|
+
desc @desc
|
|
72
|
+
task @name do
|
|
73
|
+
run
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Run tests, in a child process if possible, otherwise in this one.
|
|
78
|
+
# Exits with status 1 if the run is unsuccessful.
|
|
79
|
+
#
|
|
80
|
+
# @return nothing
|
|
81
|
+
def run
|
|
82
|
+
prepare
|
|
83
|
+
success = Process.respond_to?(:fork) ? run_in_fork : run_here
|
|
84
|
+
exit 1 unless success
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
# Settle the files and load path the run will use.
|
|
90
|
+
def prepare
|
|
91
|
+
if ENV['TEST']
|
|
92
|
+
config.files = ENV['TEST'].split(/[:;]/)
|
|
93
|
+
elsif config.files.empty?
|
|
94
|
+
config.files = default_tests
|
|
95
|
+
end
|
|
96
|
+
config.loadpath << 'lib' if config.loadpath.empty?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# The default globs that match at least one file. The runner fails a
|
|
100
|
+
# glob that matches nothing, so the others are left out.
|
|
101
|
+
#
|
|
102
|
+
# @return [Array<String>]
|
|
103
|
+
def default_tests
|
|
104
|
+
base = config.chdir || Dir.pwd
|
|
105
|
+
globs = DEFAULT_TESTS.reject{ |glob| Dir.glob(glob, base: base).empty? }
|
|
106
|
+
if globs.empty?
|
|
107
|
+
raise ArgumentError, "no test files found; looked for #{DEFAULT_TESTS.join(', ')}"
|
|
108
|
+
end
|
|
109
|
+
globs
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# @return [Boolean] Whether the run was successful.
|
|
113
|
+
def run_here
|
|
114
|
+
Test::Runner.new(config).run
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# @return [Boolean] Whether the run was successful.
|
|
118
|
+
def run_in_fork
|
|
119
|
+
pid = fork { exit(run_here ? 0 : 1) }
|
|
120
|
+
Process.wait(pid)
|
|
121
|
+
$?.success?
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
data/lib/rubytest/runner.rb
CHANGED
|
@@ -433,7 +433,7 @@ module Test
|
|
|
433
433
|
# TODO: Could use finder gem to look these up, but that's yet another dependency.
|
|
434
434
|
#
|
|
435
435
|
KNOWN_FORMATS = %w{
|
|
436
|
-
dotprogress progress outline summary tap tapy tapj test
|
|
436
|
+
dotprogress progress outline summary tap tapy tapj html test
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
# Returns a list of available report types.
|
data/lib/rubytest.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubytest
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Trans
|
|
@@ -83,6 +83,7 @@ files:
|
|
|
83
83
|
- demo/03_runner_reliability.md
|
|
84
84
|
- demo/04_result_pipeline.md
|
|
85
85
|
- demo/05_builtin_reporters.md
|
|
86
|
+
- demo/06_rake_task.md
|
|
86
87
|
- demo/applique/ae.rb
|
|
87
88
|
- demo/applique/rubytest.rb
|
|
88
89
|
- lib/rubytest.rb
|
|
@@ -99,6 +100,7 @@ files:
|
|
|
99
100
|
- lib/rubytest/format/abstract.rb
|
|
100
101
|
- lib/rubytest/format/abstract_hash.rb
|
|
101
102
|
- lib/rubytest/format/dotprogress.rb
|
|
103
|
+
- lib/rubytest/format/html.rb
|
|
102
104
|
- lib/rubytest/format/outline.rb
|
|
103
105
|
- lib/rubytest/format/progress.rb
|
|
104
106
|
- lib/rubytest/format/summary.rb
|
|
@@ -106,6 +108,7 @@ files:
|
|
|
106
108
|
- lib/rubytest/format/tapj.rb
|
|
107
109
|
- lib/rubytest/format/tapy.rb
|
|
108
110
|
- lib/rubytest/format/test.rb
|
|
111
|
+
- lib/rubytest/rake.rb
|
|
109
112
|
- lib/rubytest/recorder.rb
|
|
110
113
|
- lib/rubytest/result.rb
|
|
111
114
|
- lib/rubytest/runner.rb
|