simplecov 0.7.1 → 0.8.0.pre
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.
- data/.travis.yml +9 -2
- data/CHANGELOG.md +17 -2
- data/Gemfile +13 -2
- data/{LICENSE → MIT-LICENSE} +0 -0
- data/README.md +174 -117
- data/Rakefile +8 -3
- data/features/config_command_name.feature +12 -0
- data/features/config_merge_timeout.feature +3 -3
- data/features/config_profiles.feature +44 -0
- data/features/config_project_name.feature +2 -2
- data/features/cucumber_basic.feature +1 -1
- data/features/step_definitions/html_steps.rb +1 -1
- data/features/support/env.rb +23 -5
- data/gemfiles/multi_json_legacy.gemfile +12 -0
- data/gemfiles/multi_json_new.gemfile +12 -0
- data/lib/simplecov.rb +33 -25
- data/lib/simplecov/command_guesser.rb +6 -6
- data/lib/simplecov/configuration.rb +7 -2
- data/lib/simplecov/defaults.rb +9 -5
- data/lib/simplecov/file_list.rb +1 -1
- data/lib/simplecov/jruby16_fix.rb +43 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/{adapters.rb → profiles.rb} +8 -8
- data/lib/simplecov/result.rb +10 -2
- data/lib/simplecov/source_file.rb +2 -3
- data/lib/simplecov/version.rb +1 -1
- data/simplecov.gemspec +8 -9
- data/test/faked_project/Gemfile +1 -1
- data/test/helper.rb +0 -1
- data/test/shoulda_macros.rb +0 -10
- data/test/test_1_8_fallbacks.rb +16 -18
- data/test/test_command_guesser.rb +13 -15
- data/test/test_deleted_source.rb +5 -7
- data/test/test_file_list.rb +15 -17
- data/test/test_filters.rb +56 -58
- data/test/test_merge_helpers.rb +73 -75
- data/test/test_result.rb +114 -116
- data/test/test_return_codes.rb +24 -26
- data/test/test_source_file.rb +75 -64
- data/test/test_source_file_line.rb +78 -82
- metadata +38 -86
- data/features/config_adapters.feature +0 -44
- data/gemfiles/multi_json-legacy.gemfile +0 -7
- data/gemfiles/multi_json-new.gemfile +0 -7
data/test/test_result.rb
CHANGED
@@ -1,162 +1,160 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestResult < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
4
|
+
context "With a (mocked) Coverage.result" do
|
5
|
+
setup do
|
6
|
+
SimpleCov.filters = []
|
7
|
+
SimpleCov.groups = {}
|
8
|
+
SimpleCov.formatter = nil
|
9
|
+
@original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
10
|
+
source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
11
|
+
source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
context "a simple cov result initialized from that" do
|
15
|
+
setup { @result = SimpleCov::Result.new(@original_result) }
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
should "have 3 filenames" do
|
18
|
+
assert_equal 3, @result.filenames.count
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
should "have 3 source files" do
|
22
|
+
assert_equal 3, @result.source_files.count
|
23
|
+
assert @result.source_files.all? {|s| s.instance_of?(SimpleCov::SourceFile)}, "Not all instances are of SimpleCov::SourceFile type"
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
should "return an instance of SimpleCov::FileList for source_files and files" do
|
27
|
+
assert_equal SimpleCov::FileList, @result.source_files.class
|
28
|
+
assert_equal SimpleCov::FileList, @result.files.class
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
should "have files equal to source_files" do
|
32
|
+
assert_equal @result.files, @result.source_files
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
should "have accurate covered percent" do
|
36
|
+
# in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
|
37
|
+
assert_equal 100.0*13/15, @result.covered_percent
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
context "dumped with to_hash" do
|
41
|
+
setup { @hash = @result.to_hash }
|
42
|
+
should("be a hash") { assert_equal Hash, @hash.class }
|
44
43
|
|
45
|
-
|
46
|
-
|
44
|
+
context "loaded back with from_yaml" do
|
45
|
+
setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
should "have 3 source files" do
|
48
|
+
assert_equal @result.source_files.count, @dumped_result.source_files.count
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
should "have the same covered_percent" do
|
52
|
+
assert_equal @result.covered_percent, @dumped_result.covered_percent
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
should "have the same timestamp" do
|
56
|
+
assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
|
57
|
+
end
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
should "have the same command_name" do
|
60
|
+
assert_equal @result.command_name, @dumped_result.command_name
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
63
|
+
should "have the same original_result" do
|
64
|
+
assert_equal @result.original_result, @dumped_result.original_result
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
68
|
+
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
should "have 2 files in a new simple cov result" do
|
77
|
-
assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length
|
78
|
-
end
|
79
|
-
|
80
|
-
should "have 80 covered percent" do
|
81
|
-
assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
|
82
|
-
end
|
70
|
+
context "with some filters set up" do
|
71
|
+
setup do
|
72
|
+
SimpleCov.add_filter 'sample.rb'
|
83
73
|
end
|
84
74
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
SimpleCov.add_group 'Controllers', 'app/controllers'
|
89
|
-
SimpleCov.add_group 'Other' do |src_file|
|
90
|
-
File.basename(src_file.filename) == 'sample.rb'
|
91
|
-
end
|
92
|
-
@result = SimpleCov::Result.new(@original_result)
|
93
|
-
end
|
75
|
+
should "have 2 files in a new simple cov result" do
|
76
|
+
assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length
|
77
|
+
end
|
94
78
|
|
95
|
-
|
96
|
-
|
97
|
-
|
79
|
+
should "have 80 covered percent" do
|
80
|
+
assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
|
81
|
+
end
|
82
|
+
end
|
98
83
|
|
99
|
-
|
100
|
-
|
84
|
+
context "with groups set up for all files" do
|
85
|
+
setup do
|
86
|
+
SimpleCov.add_group 'Models', 'app/models'
|
87
|
+
SimpleCov.add_group 'Controllers', 'app/controllers'
|
88
|
+
SimpleCov.add_group 'Other' do |src_file|
|
89
|
+
File.basename(src_file.filename) == 'sample.rb'
|
101
90
|
end
|
91
|
+
@result = SimpleCov::Result.new(@original_result)
|
92
|
+
end
|
102
93
|
|
103
|
-
|
104
|
-
|
105
|
-
|
94
|
+
should "have 3 groups" do
|
95
|
+
assert_equal 3, @result.groups.length
|
96
|
+
end
|
106
97
|
|
107
|
-
|
108
|
-
|
98
|
+
should "have user.rb in 'Models' group" do
|
99
|
+
assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
|
100
|
+
end
|
109
101
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
102
|
+
should "have sample_controller.rb in 'Controllers' group" do
|
103
|
+
assert_equal 'sample_controller.rb', File.basename(@result.groups['Controllers'].first.filename)
|
104
|
+
end
|
114
105
|
|
115
|
-
|
116
|
-
|
117
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
118
|
-
SimpleCov::Formatter::SimpleFormatter,
|
119
|
-
SimpleCov::Formatter::SimpleFormatter,
|
120
|
-
]
|
121
|
-
end
|
106
|
+
context "and simple formatter being used" do
|
107
|
+
setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
|
122
108
|
|
123
|
-
|
124
|
-
|
125
|
-
assert_equal 2, formated.count
|
126
|
-
assert_equal String, formated.first.class
|
127
|
-
end
|
109
|
+
should "return a formatted string with result.format!" do
|
110
|
+
assert_equal String, @result.format!.class
|
128
111
|
end
|
129
112
|
end
|
130
113
|
|
131
|
-
context "
|
114
|
+
context "and multi formatter being used" do
|
132
115
|
setup do
|
133
|
-
SimpleCov.
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
@result = SimpleCov::Result.new(@original_result)
|
116
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
117
|
+
SimpleCov::Formatter::SimpleFormatter,
|
118
|
+
SimpleCov::Formatter::SimpleFormatter,
|
119
|
+
]
|
138
120
|
end
|
139
121
|
|
140
|
-
should "
|
141
|
-
|
122
|
+
should "return an array containing formatted string with result.format!" do
|
123
|
+
formated = @result.format!
|
124
|
+
assert_equal 2, formated.count
|
125
|
+
assert_equal String, formated.first.class
|
142
126
|
end
|
127
|
+
end
|
128
|
+
end
|
143
129
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
130
|
+
context "with groups set up that do not match all files" do
|
131
|
+
setup do
|
132
|
+
SimpleCov.configure do
|
133
|
+
add_group 'Models', 'app/models'
|
134
|
+
add_group 'Controllers', 'app/controllers'
|
148
135
|
end
|
136
|
+
@result = SimpleCov::Result.new(@original_result)
|
137
|
+
end
|
149
138
|
|
150
|
-
|
151
|
-
|
139
|
+
should "have 3 groups" do
|
140
|
+
assert_equal 3, @result.groups.length
|
141
|
+
end
|
142
|
+
|
143
|
+
should "have 1 item per group" do
|
144
|
+
@result.groups.each do |name, files|
|
145
|
+
assert_equal 1, files.length, "Group #{name} should have 1 file"
|
152
146
|
end
|
147
|
+
end
|
153
148
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
149
|
+
should "have sample.rb in 'Ungrouped' group" do
|
150
|
+
assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename)
|
151
|
+
end
|
152
|
+
|
153
|
+
should "return all groups as instances of SimpleCov::FileList" do
|
154
|
+
@result.groups.each do |name, files|
|
155
|
+
assert_equal SimpleCov::FileList, files.class
|
158
156
|
end
|
159
157
|
end
|
160
158
|
end
|
161
159
|
end
|
162
|
-
end
|
160
|
+
end if SimpleCov.usable?
|
data/test/test_return_codes.rb
CHANGED
@@ -3,37 +3,35 @@ require 'helper'
|
|
3
3
|
# Make sure that exit codes of tests are propagated properly when using
|
4
4
|
# simplecov. See github issue #5
|
5
5
|
class TestReturnCodes < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
6
|
+
context "Inside fixtures/frameworks" do
|
7
|
+
setup do
|
8
|
+
@current_dir = Dir.getwd
|
9
|
+
Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures', 'frameworks'))
|
10
|
+
FileUtils.rm_rf('./coverage')
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
should "have return code 0 when running testunit_good.rb" do
|
14
|
+
`ruby testunit_good.rb`
|
15
|
+
assert_equal 0, $?.exitstatus
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
should "have return code 0 when running rspec_good.rb" do
|
19
|
+
`rspec rspec_good.rb`
|
20
|
+
assert_equal 0, $?.exitstatus
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
should "have non-0 return code when running testunit_bad.rb" do
|
24
|
+
`ruby testunit_bad.rb`
|
25
|
+
assert_not_equal 0, $?.exitstatus
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
should "have return code 1 when running rspec_bad.rb" do
|
29
|
+
`rspec rspec_bad.rb`
|
30
|
+
assert_not_equal 0, $?.exitstatus
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
33
|
+
teardown do
|
34
|
+
Dir.chdir(@current_dir)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/test/test_source_file.rb
CHANGED
@@ -1,95 +1,106 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestSourceFile < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
4
|
+
COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil]
|
5
|
+
context "A source file initialized with some coverage data" do
|
6
|
+
setup do
|
7
|
+
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB)
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
should "have a filename" do
|
11
|
+
assert @source_file.filename
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
should "have source equal to src" do
|
15
|
+
assert_equal @source_file.source, @source_file.src
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
should "have source_lines equal to lines" do
|
19
|
+
assert_equal @source_file.source_lines, @source_file.lines
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
should "have 16 source lines" do
|
23
|
+
assert_equal 16, @source_file.lines.count
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
should "have all source lines of type SimpleCov::SourceFile::Line" do
|
27
|
+
assert @source_file.lines.all? {|l| l.instance_of?(SimpleCov::SourceFile::Line)}
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
should "have 'class Foo' as line(2).source" do
|
31
|
+
assert_equal "class Foo\n", @source_file.line(2).source
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
should "return lines number 2, 3, 4, 7 for covered_lines" do
|
35
|
+
assert_equal [2, 3, 4, 7], @source_file.covered_lines.map(&:line)
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
should "return lines number 8 for missed_lines" do
|
39
|
+
assert_equal [8], @source_file.missed_lines.map(&:line)
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
should "return lines number 1, 5, 6, 9, 10, 11, 15, 16 for never_lines" do
|
43
|
+
assert_equal [1, 5, 6, 9, 10, 11, 15, 16], @source_file.never_lines.map(&:line)
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
should "return line numbers 12, 13, 14 for skipped_lines" do
|
47
|
+
assert_equal [12, 13, 14], @source_file.skipped_lines.map(&:line)
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
end
|
50
|
+
should "have 80% covered_percent" do
|
51
|
+
assert_equal 80.0, @source_file.covered_percent
|
54
52
|
end
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
context "Simulating potential Ruby 1.9 defect -- see Issue #56" do
|
56
|
+
setup do
|
57
|
+
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB + [nil])
|
58
|
+
end
|
59
|
+
|
60
|
+
should "have 16 source lines regardless of extra data in coverage array" do
|
61
|
+
# Do not litter test output with known warning
|
62
|
+
capture_stderr { assert_equal 16, @source_file.lines.count }
|
63
|
+
end
|
60
64
|
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
should "print a warning to stderr if coverage array contains more data than lines in the file" do
|
66
|
+
captured_output = capture_stderr do
|
67
|
+
@source_file.lines
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
+
assert_match(/^Warning: coverage data provided/, captured_output)
|
71
|
+
end
|
72
|
+
end
|
70
73
|
|
71
|
-
|
74
|
+
context "Encoding" do
|
75
|
+
should "handle utf-8 encoded source files" do
|
76
|
+
source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1])
|
77
|
+
|
78
|
+
assert_nothing_raised do
|
79
|
+
source_file.process_skipped_lines!
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
|
-
|
76
|
-
|
77
|
-
source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1])
|
83
|
+
should "handle iso-8859 encoded source files" do
|
84
|
+
source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1])
|
78
85
|
|
79
|
-
|
80
|
-
|
81
|
-
end
|
86
|
+
assert_nothing_raised do
|
87
|
+
source_file.process_skipped_lines!
|
82
88
|
end
|
89
|
+
end
|
83
90
|
|
84
|
-
|
85
|
-
|
91
|
+
should "handle utf-8 encoded source files when the default_internal encoding is binary" do
|
92
|
+
original_internal_encoding = Encoding.default_internal
|
93
|
+
Encoding.default_internal = "BINARY"
|
94
|
+
begin
|
95
|
+
source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1])
|
96
|
+
ensure
|
97
|
+
Encoding.default_internal = original_internal_encoding
|
98
|
+
end
|
86
99
|
|
87
|
-
|
88
|
-
|
89
|
-
end
|
100
|
+
assert_nothing_raised do
|
101
|
+
source_file.process_skipped_lines!
|
90
102
|
end
|
91
103
|
end
|
92
|
-
|
93
104
|
end
|
94
|
-
end
|
105
|
+
end if SimpleCov.usable?
|
95
106
|
|