minitest-reporters 1.3.0 → 1.3.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +27 -27
- data/.ruby-gemset +1 -1
- data/.travis.yml +10 -10
- data/.yardopts +5 -5
- data/CHANGELOG.md +58 -54
- data/Gemfile +2 -2
- data/LICENSE +19 -19
- data/README.md +134 -134
- data/Rakefile +60 -60
- data/lib/minitest/extensible_backtrace_filter.rb +67 -67
- data/lib/minitest/minitest_reporter_plugin.rb +75 -75
- data/lib/minitest/old_activesupport_fix.rb +24 -24
- data/lib/minitest/relative_position.rb +26 -26
- data/lib/minitest/reporters.rb +91 -91
- data/lib/minitest/reporters/ansi.rb +31 -31
- data/lib/minitest/reporters/base_reporter.rb +119 -117
- data/lib/minitest/reporters/default_reporter.rb +228 -228
- data/lib/minitest/reporters/html_reporter.rb +221 -221
- data/lib/minitest/reporters/junit_reporter.rb +158 -158
- data/lib/minitest/reporters/mean_time_reporter.rb +392 -392
- data/lib/minitest/reporters/progress_reporter.rb +96 -96
- data/lib/minitest/reporters/ruby_mate_reporter.rb +54 -54
- data/lib/minitest/reporters/rubymine_reporter.rb +117 -117
- data/lib/minitest/reporters/spec_reporter.rb +61 -61
- data/lib/minitest/reporters/version.rb +5 -5
- data/lib/minitest/templates/index.html.erb +82 -82
- data/minitest-reporters.gemspec +31 -31
- data/test/fixtures/junit_filename_bug_example_test.rb +21 -21
- data/test/fixtures/mean_time_test.rb +8 -8
- data/test/fixtures/progress_detailed_skip_test.rb +8 -8
- data/test/fixtures/progress_test.rb +8 -8
- data/test/fixtures/sample_test.rb +15 -15
- data/test/fixtures/spec_test.rb +13 -13
- data/test/gallery/bad_test.rb +25 -25
- data/test/gallery/good_test.rb +14 -14
- data/test/integration/reporters/junit_reporter_test.rb +12 -12
- data/test/integration/reporters/mean_time_reporter_test.rb +7 -7
- data/test/integration/reporters/progress_reporter_test.rb +34 -34
- data/test/test_helper.rb +22 -22
- data/test/unit/minitest/extensible_backtrace_filter_test.rb +42 -42
- data/test/unit/minitest/mean_time_reporter_unit_test.rb +152 -152
- data/test/unit/minitest/minitest_reporter_plugin_test.rb +14 -14
- data/test/unit/minitest/reporters_test.rb +65 -65
- data/test/unit/minitest/spec_reporter_test.rb +41 -41
- metadata +4 -4
@@ -1,15 +1,15 @@
|
|
1
|
-
Class.new(Minitest::Test) do
|
2
|
-
def test_success
|
3
|
-
assert true
|
4
|
-
end
|
5
|
-
def test_failure
|
6
|
-
assert false
|
7
|
-
end
|
8
|
-
def test_skip
|
9
|
-
skip('Skipping rope')
|
10
|
-
end
|
11
|
-
def test_error
|
12
|
-
raise 'An unexpected error'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
1
|
+
Class.new(Minitest::Test) do
|
2
|
+
def test_success
|
3
|
+
assert true
|
4
|
+
end
|
5
|
+
def test_failure
|
6
|
+
assert false
|
7
|
+
end
|
8
|
+
def test_skip
|
9
|
+
skip('Skipping rope')
|
10
|
+
end
|
11
|
+
def test_error
|
12
|
+
raise 'An unexpected error'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
data/test/fixtures/spec_test.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require 'minitest'
|
2
|
-
require 'minitest/reporters'
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new
|
6
|
-
|
7
|
-
describe String do
|
8
|
-
describe '#length' do
|
9
|
-
it 'works' do
|
10
|
-
assert_equal 5, 'hello'.length
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
require 'minitest'
|
2
|
+
require 'minitest/reporters'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new
|
6
|
+
|
7
|
+
describe String do
|
8
|
+
describe '#length' do
|
9
|
+
it 'works' do
|
10
|
+
assert_equal 5, 'hello'.length
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/test/gallery/bad_test.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require_relative "../test_helper"
|
2
|
-
|
3
|
-
module MinitestReportersTest
|
4
|
-
class BadTest < TestCase
|
5
|
-
def test_a
|
6
|
-
assert_equal 1, 2
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_b
|
10
|
-
assert false # simple failure
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_b
|
14
|
-
assert_equal "ab\nc", "ab\nd" # some nice diff
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_boom
|
18
|
-
raise "A random exception"
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_long_method_name
|
22
|
-
skip
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
module MinitestReportersTest
|
4
|
+
class BadTest < TestCase
|
5
|
+
def test_a
|
6
|
+
assert_equal 1, 2
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_b
|
10
|
+
assert false # simple failure
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_b
|
14
|
+
assert_equal "ab\nc", "ab\nd" # some nice diff
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_boom
|
18
|
+
raise "A random exception"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_long_method_name
|
22
|
+
skip
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/gallery/good_test.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require_relative "../test_helper"
|
2
|
-
|
3
|
-
module MinitestReportersTest
|
4
|
-
class GoodTest < TestCase
|
5
|
-
def test_a
|
6
|
-
assert_equal 1, 1
|
7
|
-
assert 1
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_b
|
11
|
-
assert_equal 2, 2
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
module MinitestReportersTest
|
4
|
+
class GoodTest < TestCase
|
5
|
+
def test_a
|
6
|
+
assert_equal 1, 1
|
7
|
+
assert 1
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_b
|
11
|
+
assert_equal 2, 2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require_relative "../../test_helper"
|
2
|
-
|
3
|
-
module MinitestReportersTest
|
4
|
-
class JUnitReporterTest < TestCase
|
5
|
-
def test_replaces_special_characters_for_filenames_and_doesnt_crash
|
6
|
-
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
7
|
-
test_filename = File.join(fixtures_directory, 'junit_filename_bug_example_test.rb')
|
8
|
-
output = `ruby #{test_filename} 2>&1`
|
9
|
-
refute_match 'No such file or directory', output
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
|
3
|
+
module MinitestReportersTest
|
4
|
+
class JUnitReporterTest < TestCase
|
5
|
+
def test_replaces_special_characters_for_filenames_and_doesnt_crash
|
6
|
+
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
7
|
+
test_filename = File.join(fixtures_directory, 'junit_filename_bug_example_test.rb')
|
8
|
+
output = `ruby #{test_filename} 2>&1`
|
9
|
+
refute_match 'No such file or directory', output
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require_relative "../../test_helper"
|
2
|
-
|
3
|
-
module MinitestReportersTest
|
4
|
-
class MeanTimeReporterTest < TestCase
|
5
|
-
|
6
|
-
end
|
7
|
-
end
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
|
3
|
+
module MinitestReportersTest
|
4
|
+
class MeanTimeReporterTest < TestCase
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require_relative "../../test_helper"
|
2
|
-
|
3
|
-
module MinitestReportersTest
|
4
|
-
class ProgressReporterTest < TestCase
|
5
|
-
def test_all_failures_are_displayed
|
6
|
-
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
7
|
-
test_filename = File.join(fixtures_directory, 'progress_test.rb')
|
8
|
-
output = `ruby #{test_filename} 2>&1`
|
9
|
-
assert_match 'ERROR["test_error"', output, 'Errors should be displayed'
|
10
|
-
assert_match 'FAIL["test_failure"', output, 'Failures should be displayed'
|
11
|
-
assert_match 'SKIP["test_skip', output, 'Skipped tests should be displayed'
|
12
|
-
end
|
13
|
-
def test_skipped_tests_are_not_displayed
|
14
|
-
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
15
|
-
test_filename = File.join(fixtures_directory, 'progress_detailed_skip_test.rb')
|
16
|
-
output = `ruby #{test_filename} 2>&1`
|
17
|
-
assert_match 'ERROR["test_error"', output, 'Errors should be displayed'
|
18
|
-
assert_match 'FAIL["test_failure"', output, 'Failures should be displayed'
|
19
|
-
refute_match 'SKIP["test_skip', output, 'Skipped tests should not be displayed'
|
20
|
-
end
|
21
|
-
def test_progress_works_with_filter_and_specs
|
22
|
-
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
23
|
-
test_filename = File.join(fixtures_directory, 'spec_test.rb')
|
24
|
-
output = `ruby #{test_filename} -n /length/ 2>&1`
|
25
|
-
refute_match '0 out of 0', output, 'Progress should not puts a warning'
|
26
|
-
end
|
27
|
-
def test_progress_works_with_strict_filter
|
28
|
-
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
29
|
-
test_filename = File.join(fixtures_directory, 'spec_test.rb')
|
30
|
-
output = `ruby #{test_filename} -n /^test_0001_works$/ 2>&1`
|
31
|
-
refute_match '0 out of 0', output, 'Progress should not puts a warning'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
|
3
|
+
module MinitestReportersTest
|
4
|
+
class ProgressReporterTest < TestCase
|
5
|
+
def test_all_failures_are_displayed
|
6
|
+
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
7
|
+
test_filename = File.join(fixtures_directory, 'progress_test.rb')
|
8
|
+
output = `ruby #{test_filename} 2>&1`
|
9
|
+
assert_match 'ERROR["test_error"', output, 'Errors should be displayed'
|
10
|
+
assert_match 'FAIL["test_failure"', output, 'Failures should be displayed'
|
11
|
+
assert_match 'SKIP["test_skip', output, 'Skipped tests should be displayed'
|
12
|
+
end
|
13
|
+
def test_skipped_tests_are_not_displayed
|
14
|
+
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
15
|
+
test_filename = File.join(fixtures_directory, 'progress_detailed_skip_test.rb')
|
16
|
+
output = `ruby #{test_filename} 2>&1`
|
17
|
+
assert_match 'ERROR["test_error"', output, 'Errors should be displayed'
|
18
|
+
assert_match 'FAIL["test_failure"', output, 'Failures should be displayed'
|
19
|
+
refute_match 'SKIP["test_skip', output, 'Skipped tests should not be displayed'
|
20
|
+
end
|
21
|
+
def test_progress_works_with_filter_and_specs
|
22
|
+
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
23
|
+
test_filename = File.join(fixtures_directory, 'spec_test.rb')
|
24
|
+
output = `ruby #{test_filename} -n /length/ 2>&1`
|
25
|
+
refute_match '0 out of 0', output, 'Progress should not puts a warning'
|
26
|
+
end
|
27
|
+
def test_progress_works_with_strict_filter
|
28
|
+
fixtures_directory = File.expand_path('../../../fixtures', __FILE__)
|
29
|
+
test_filename = File.join(fixtures_directory, 'spec_test.rb')
|
30
|
+
output = `ruby #{test_filename} -n /^test_0001_works$/ 2>&1`
|
31
|
+
refute_match '0 out of 0', output, 'Progress should not puts a warning'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
require "minitest/autorun"
|
3
|
-
require "minitest/reporters"
|
4
|
-
|
5
|
-
ENV['MINITEST_REPORTERS_MONO'] = 'yes'
|
6
|
-
module MinitestReportersTest
|
7
|
-
class TestCase < Minitest::Test
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# Testing the built-in reporters using automated unit testing would be extremely
|
12
|
-
# brittle. Consequently, there are no unit tests for them. If you'd like to run
|
13
|
-
# all the reporters sequentially on a fake test suite, run `rake gallery`.
|
14
|
-
|
15
|
-
if ENV["REPORTER"] == "Pride"
|
16
|
-
require "minitest/pride"
|
17
|
-
elsif ENV["REPORTER"]
|
18
|
-
reporter_klass = Minitest::Reporters.const_get(ENV["REPORTER"])
|
19
|
-
Minitest::Reporters.use!(reporter_klass.new)
|
20
|
-
else
|
21
|
-
Minitest::Reporters.use!(Minitest::Reporters::DefaultReporter.new)
|
22
|
-
end
|
1
|
+
require "bundler/setup"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "minitest/reporters"
|
4
|
+
|
5
|
+
ENV['MINITEST_REPORTERS_MONO'] = 'yes'
|
6
|
+
module MinitestReportersTest
|
7
|
+
class TestCase < Minitest::Test
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Testing the built-in reporters using automated unit testing would be extremely
|
12
|
+
# brittle. Consequently, there are no unit tests for them. If you'd like to run
|
13
|
+
# all the reporters sequentially on a fake test suite, run `rake gallery`.
|
14
|
+
|
15
|
+
if ENV["REPORTER"] == "Pride"
|
16
|
+
require "minitest/pride"
|
17
|
+
elsif ENV["REPORTER"]
|
18
|
+
reporter_klass = Minitest::Reporters.const_get(ENV["REPORTER"])
|
19
|
+
Minitest::Reporters.use!(reporter_klass.new)
|
20
|
+
else
|
21
|
+
Minitest::Reporters.use!(Minitest::Reporters::DefaultReporter.new)
|
22
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
require_relative "../../test_helper"
|
2
|
-
|
3
|
-
module MinitestReportersTest
|
4
|
-
class ExtensibleBacktraceFilterTest < TestCase
|
5
|
-
def setup
|
6
|
-
@default_filter = Minitest::ExtensibleBacktraceFilter.default_filter
|
7
|
-
@filter = Minitest::ExtensibleBacktraceFilter.new
|
8
|
-
@backtrace = ["foo", "bar", "baz"]
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_adding_filters
|
12
|
-
@filter.add_filter(/foo/)
|
13
|
-
assert @filter.filters?("foo")
|
14
|
-
refute @filter.filters?("baz")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_filter_backtrace_when_first_line_is_filtered
|
18
|
-
@filter.add_filter(/foo/)
|
19
|
-
assert_equal ["bar", "baz"], @filter.filter(@backtrace)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_filter_backtrace_when_middle_line_is_filtered
|
23
|
-
@filter.add_filter(/bar/)
|
24
|
-
assert_equal ["foo"], @filter.filter(@backtrace)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_filter_backtrace_when_all_lines_are_filtered
|
28
|
-
@filter.add_filter(/./)
|
29
|
-
assert_equal ["foo", "bar", "baz"], @filter.filter(@backtrace)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_default_filter
|
33
|
-
assert @default_filter.filters?("lib/minitest")
|
34
|
-
assert @default_filter.filters?("lib/minitest/reporters")
|
35
|
-
refute @default_filter.filters?("lib/my_gem")
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_nil_backtrace
|
39
|
-
assert_equal [], @filter.filter(nil)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
|
3
|
+
module MinitestReportersTest
|
4
|
+
class ExtensibleBacktraceFilterTest < TestCase
|
5
|
+
def setup
|
6
|
+
@default_filter = Minitest::ExtensibleBacktraceFilter.default_filter
|
7
|
+
@filter = Minitest::ExtensibleBacktraceFilter.new
|
8
|
+
@backtrace = ["foo", "bar", "baz"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_adding_filters
|
12
|
+
@filter.add_filter(/foo/)
|
13
|
+
assert @filter.filters?("foo")
|
14
|
+
refute @filter.filters?("baz")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_filter_backtrace_when_first_line_is_filtered
|
18
|
+
@filter.add_filter(/foo/)
|
19
|
+
assert_equal ["bar", "baz"], @filter.filter(@backtrace)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_filter_backtrace_when_middle_line_is_filtered
|
23
|
+
@filter.add_filter(/bar/)
|
24
|
+
assert_equal ["foo"], @filter.filter(@backtrace)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_filter_backtrace_when_all_lines_are_filtered
|
28
|
+
@filter.add_filter(/./)
|
29
|
+
assert_equal ["foo", "bar", "baz"], @filter.filter(@backtrace)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_default_filter
|
33
|
+
assert @default_filter.filters?("lib/minitest")
|
34
|
+
assert @default_filter.filters?("lib/minitest/reporters")
|
35
|
+
refute @default_filter.filters?("lib/my_gem")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_nil_backtrace
|
39
|
+
assert_equal [], @filter.filter(nil)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,152 +1,152 @@
|
|
1
|
-
require_relative "../../test_helper"
|
2
|
-
|
3
|
-
module MinitestReportersTest
|
4
|
-
class MeanTimeReporterUnitTest < Minitest::Test
|
5
|
-
def setup
|
6
|
-
configure_report_paths
|
7
|
-
previous_test_run
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
File.delete(@previous_run_path) if File.exist?(@previous_run_path)
|
12
|
-
File.delete(@report_file_path) if File.exist?(@report_file_path)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_sorts_avg_numerically
|
16
|
-
report_output = generate_report(:avg)
|
17
|
-
|
18
|
-
expected_order = [
|
19
|
-
'AVG_SLOW',
|
20
|
-
'MAX_SLOW',
|
21
|
-
'MIN_SLOW',
|
22
|
-
'MIDDLE',
|
23
|
-
'MIN_FAST',
|
24
|
-
'MAX_FAST',
|
25
|
-
'AVG_FAST'
|
26
|
-
]
|
27
|
-
verify_result_order(report_output, expected_order)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_sorts_min_numerically
|
31
|
-
report_output = generate_report(:min)
|
32
|
-
|
33
|
-
expected_order = [
|
34
|
-
'MIN_SLOW',
|
35
|
-
'AVG_SLOW',
|
36
|
-
'MAX_SLOW',
|
37
|
-
'MIDDLE',
|
38
|
-
'MAX_FAST',
|
39
|
-
'AVG_FAST',
|
40
|
-
'MIN_FAST'
|
41
|
-
]
|
42
|
-
verify_result_order(report_output, expected_order)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_sorts_max_numerically
|
46
|
-
report_output = generate_report(:max)
|
47
|
-
|
48
|
-
expected_order = [
|
49
|
-
'MAX_SLOW',
|
50
|
-
'AVG_SLOW',
|
51
|
-
'MIN_SLOW',
|
52
|
-
'MIDDLE',
|
53
|
-
'MIN_FAST',
|
54
|
-
'AVG_FAST',
|
55
|
-
'MAX_FAST'
|
56
|
-
]
|
57
|
-
verify_result_order(report_output, expected_order)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_sorts_last_numerically
|
61
|
-
report_output = generate_report(:last)
|
62
|
-
|
63
|
-
expected_order = [
|
64
|
-
'AVG_SLOW',
|
65
|
-
'MIN_SLOW',
|
66
|
-
'MAX_SLOW',
|
67
|
-
'MIDDLE',
|
68
|
-
'MIN_FAST',
|
69
|
-
'MAX_FAST',
|
70
|
-
'AVG_FAST'
|
71
|
-
]
|
72
|
-
verify_result_order(report_output, expected_order)
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def simulate_suite_runtime(suite_name, run_time)
|
78
|
-
test_suite = Minitest::Test.new(suite_name)
|
79
|
-
base_clock_time = Minitest::Reporters.clock_time
|
80
|
-
Minitest::Reporters.stub(:clock_time, base_clock_time - run_time) do
|
81
|
-
@reporter.before_suite(test_suite)
|
82
|
-
end
|
83
|
-
@reporter.after_suite(test_suite)
|
84
|
-
end
|
85
|
-
|
86
|
-
def previous_test_run
|
87
|
-
@reporter = Minitest::Reporters::MeanTimeReporter.new(
|
88
|
-
previous_runs_filename: @previous_run_path,
|
89
|
-
report_filename: @report_file_path
|
90
|
-
)
|
91
|
-
|
92
|
-
simulate_suite_runtime('MIDDLE', 5.0)
|
93
|
-
simulate_suite_runtime('MIN_FAST', 0.5)
|
94
|
-
simulate_suite_runtime('MIN_SLOW', 10.5)
|
95
|
-
simulate_suite_runtime('MAX_FAST', 1.2)
|
96
|
-
simulate_suite_runtime('MAX_SLOW', 16.3)
|
97
|
-
simulate_suite_runtime('AVG_FAST', 1.3)
|
98
|
-
simulate_suite_runtime('AVG_SLOW', 10.2)
|
99
|
-
@reporter.tests << Minitest::Test.new('Final')
|
100
|
-
# Generate a "previous" run
|
101
|
-
@reporter.io = StringIO.new
|
102
|
-
@reporter.start
|
103
|
-
@reporter.report
|
104
|
-
end
|
105
|
-
|
106
|
-
def configure_report_paths
|
107
|
-
previous_runs_file = Tempfile.new('minitest-mean-time-previous-runs')
|
108
|
-
previous_runs_file.close
|
109
|
-
@previous_run_path = previous_runs_file.path
|
110
|
-
previous_runs_file.delete
|
111
|
-
report_file = Tempfile.new('minitest-mean-time-report')
|
112
|
-
report_file.close
|
113
|
-
@report_file_path = report_file.path
|
114
|
-
report_file.delete
|
115
|
-
end
|
116
|
-
|
117
|
-
def generate_report(sort_column)
|
118
|
-
# Reset the reporter for the test run
|
119
|
-
@reporter = Minitest::Reporters::MeanTimeReporter.new(
|
120
|
-
previous_runs_filename: @previous_run_path,
|
121
|
-
report_filename: @report_file_path,
|
122
|
-
sort_column: sort_column
|
123
|
-
)
|
124
|
-
simulate_suite_runtime('MIDDLE', 5.0)
|
125
|
-
simulate_suite_runtime('MIN_FAST', 3.5)
|
126
|
-
simulate_suite_runtime('MIN_SLOW', 10.5)
|
127
|
-
simulate_suite_runtime('MAX_FAST', 0.9)
|
128
|
-
simulate_suite_runtime('MAX_SLOW', 6.3)
|
129
|
-
simulate_suite_runtime('AVG_FAST', 0.65)
|
130
|
-
simulate_suite_runtime('AVG_SLOW', 14.2)
|
131
|
-
@reporter.tests << Minitest::Test.new('Final')
|
132
|
-
|
133
|
-
report_output = StringIO.new
|
134
|
-
@reporter.io = report_output
|
135
|
-
@reporter.start
|
136
|
-
@reporter.report
|
137
|
-
report_output
|
138
|
-
end
|
139
|
-
|
140
|
-
def verify_result_order(report_output, expected_order)
|
141
|
-
report_output.rewind
|
142
|
-
test_lines = report_output.read.split("\n")
|
143
|
-
test_lines.select! { |line| line.start_with?('Avg:') }
|
144
|
-
|
145
|
-
# Exclude the final placeholder 0 second test from assertions
|
146
|
-
test_lines.reject! { |line| line.end_with?('Minitest::Test') }
|
147
|
-
actual_order = test_lines.map { |line| line.gsub(/.*Description: /, '') }
|
148
|
-
|
149
|
-
assert_equal(expected_order, actual_order, "\n#{test_lines.join("\n")}")
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
|
3
|
+
module MinitestReportersTest
|
4
|
+
class MeanTimeReporterUnitTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
configure_report_paths
|
7
|
+
previous_test_run
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
File.delete(@previous_run_path) if File.exist?(@previous_run_path)
|
12
|
+
File.delete(@report_file_path) if File.exist?(@report_file_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_sorts_avg_numerically
|
16
|
+
report_output = generate_report(:avg)
|
17
|
+
|
18
|
+
expected_order = [
|
19
|
+
'AVG_SLOW',
|
20
|
+
'MAX_SLOW',
|
21
|
+
'MIN_SLOW',
|
22
|
+
'MIDDLE',
|
23
|
+
'MIN_FAST',
|
24
|
+
'MAX_FAST',
|
25
|
+
'AVG_FAST'
|
26
|
+
]
|
27
|
+
verify_result_order(report_output, expected_order)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_sorts_min_numerically
|
31
|
+
report_output = generate_report(:min)
|
32
|
+
|
33
|
+
expected_order = [
|
34
|
+
'MIN_SLOW',
|
35
|
+
'AVG_SLOW',
|
36
|
+
'MAX_SLOW',
|
37
|
+
'MIDDLE',
|
38
|
+
'MAX_FAST',
|
39
|
+
'AVG_FAST',
|
40
|
+
'MIN_FAST'
|
41
|
+
]
|
42
|
+
verify_result_order(report_output, expected_order)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_sorts_max_numerically
|
46
|
+
report_output = generate_report(:max)
|
47
|
+
|
48
|
+
expected_order = [
|
49
|
+
'MAX_SLOW',
|
50
|
+
'AVG_SLOW',
|
51
|
+
'MIN_SLOW',
|
52
|
+
'MIDDLE',
|
53
|
+
'MIN_FAST',
|
54
|
+
'AVG_FAST',
|
55
|
+
'MAX_FAST'
|
56
|
+
]
|
57
|
+
verify_result_order(report_output, expected_order)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_sorts_last_numerically
|
61
|
+
report_output = generate_report(:last)
|
62
|
+
|
63
|
+
expected_order = [
|
64
|
+
'AVG_SLOW',
|
65
|
+
'MIN_SLOW',
|
66
|
+
'MAX_SLOW',
|
67
|
+
'MIDDLE',
|
68
|
+
'MIN_FAST',
|
69
|
+
'MAX_FAST',
|
70
|
+
'AVG_FAST'
|
71
|
+
]
|
72
|
+
verify_result_order(report_output, expected_order)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def simulate_suite_runtime(suite_name, run_time)
|
78
|
+
test_suite = Minitest::Test.new(suite_name)
|
79
|
+
base_clock_time = Minitest::Reporters.clock_time
|
80
|
+
Minitest::Reporters.stub(:clock_time, base_clock_time - run_time) do
|
81
|
+
@reporter.before_suite(test_suite)
|
82
|
+
end
|
83
|
+
@reporter.after_suite(test_suite)
|
84
|
+
end
|
85
|
+
|
86
|
+
def previous_test_run
|
87
|
+
@reporter = Minitest::Reporters::MeanTimeReporter.new(
|
88
|
+
previous_runs_filename: @previous_run_path,
|
89
|
+
report_filename: @report_file_path
|
90
|
+
)
|
91
|
+
|
92
|
+
simulate_suite_runtime('MIDDLE', 5.0)
|
93
|
+
simulate_suite_runtime('MIN_FAST', 0.5)
|
94
|
+
simulate_suite_runtime('MIN_SLOW', 10.5)
|
95
|
+
simulate_suite_runtime('MAX_FAST', 1.2)
|
96
|
+
simulate_suite_runtime('MAX_SLOW', 16.3)
|
97
|
+
simulate_suite_runtime('AVG_FAST', 1.3)
|
98
|
+
simulate_suite_runtime('AVG_SLOW', 10.2)
|
99
|
+
@reporter.tests << Minitest::Test.new('Final')
|
100
|
+
# Generate a "previous" run
|
101
|
+
@reporter.io = StringIO.new
|
102
|
+
@reporter.start
|
103
|
+
@reporter.report
|
104
|
+
end
|
105
|
+
|
106
|
+
def configure_report_paths
|
107
|
+
previous_runs_file = Tempfile.new('minitest-mean-time-previous-runs')
|
108
|
+
previous_runs_file.close
|
109
|
+
@previous_run_path = previous_runs_file.path
|
110
|
+
previous_runs_file.delete
|
111
|
+
report_file = Tempfile.new('minitest-mean-time-report')
|
112
|
+
report_file.close
|
113
|
+
@report_file_path = report_file.path
|
114
|
+
report_file.delete
|
115
|
+
end
|
116
|
+
|
117
|
+
def generate_report(sort_column)
|
118
|
+
# Reset the reporter for the test run
|
119
|
+
@reporter = Minitest::Reporters::MeanTimeReporter.new(
|
120
|
+
previous_runs_filename: @previous_run_path,
|
121
|
+
report_filename: @report_file_path,
|
122
|
+
sort_column: sort_column
|
123
|
+
)
|
124
|
+
simulate_suite_runtime('MIDDLE', 5.0)
|
125
|
+
simulate_suite_runtime('MIN_FAST', 3.5)
|
126
|
+
simulate_suite_runtime('MIN_SLOW', 10.5)
|
127
|
+
simulate_suite_runtime('MAX_FAST', 0.9)
|
128
|
+
simulate_suite_runtime('MAX_SLOW', 6.3)
|
129
|
+
simulate_suite_runtime('AVG_FAST', 0.65)
|
130
|
+
simulate_suite_runtime('AVG_SLOW', 14.2)
|
131
|
+
@reporter.tests << Minitest::Test.new('Final')
|
132
|
+
|
133
|
+
report_output = StringIO.new
|
134
|
+
@reporter.io = report_output
|
135
|
+
@reporter.start
|
136
|
+
@reporter.report
|
137
|
+
report_output
|
138
|
+
end
|
139
|
+
|
140
|
+
def verify_result_order(report_output, expected_order)
|
141
|
+
report_output.rewind
|
142
|
+
test_lines = report_output.read.split("\n")
|
143
|
+
test_lines.select! { |line| line.start_with?('Avg:') }
|
144
|
+
|
145
|
+
# Exclude the final placeholder 0 second test from assertions
|
146
|
+
test_lines.reject! { |line| line.end_with?('Minitest::Test') }
|
147
|
+
actual_order = test_lines.map { |line| line.gsub(/.*Description: /, '') }
|
148
|
+
|
149
|
+
assert_equal(expected_order, actual_order, "\n#{test_lines.join("\n")}")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|