danger-dangermattic 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.buildkite/gem-push.sh +15 -0
- data/.buildkite/pipeline.yml +69 -0
- data/.bundle/config +2 -0
- data/.github/workflows/reusable-check-labels-on-issues.yml +91 -0
- data/.github/workflows/reusable-run-danger.yml +54 -0
- data/.gitignore +30 -0
- data/.rubocop.yml +67 -0
- data/.ruby-version +1 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +191 -0
- data/Guardfile +21 -0
- data/LICENSE +373 -0
- data/README.md +68 -0
- data/Rakefile +24 -0
- data/danger-dangermattic.gemspec +58 -0
- data/lib/danger_dangermattic.rb +3 -0
- data/lib/danger_plugin.rb +4 -0
- data/lib/dangermattic/gem_version.rb +5 -0
- data/lib/dangermattic/plugins/android_release_checker.rb +50 -0
- data/lib/dangermattic/plugins/android_strings_checker.rb +31 -0
- data/lib/dangermattic/plugins/android_unit_test_checker.rb +187 -0
- data/lib/dangermattic/plugins/common/common_release_checker.rb +113 -0
- data/lib/dangermattic/plugins/common/git_utils.rb +166 -0
- data/lib/dangermattic/plugins/common/github_utils.rb +68 -0
- data/lib/dangermattic/plugins/common/reporter.rb +38 -0
- data/lib/dangermattic/plugins/ios_release_checker.rb +106 -0
- data/lib/dangermattic/plugins/labels_checker.rb +74 -0
- data/lib/dangermattic/plugins/manifest_pr_checker.rb +106 -0
- data/lib/dangermattic/plugins/milestone_checker.rb +98 -0
- data/lib/dangermattic/plugins/podfile_checker.rb +122 -0
- data/lib/dangermattic/plugins/pr_size_checker.rb +125 -0
- data/lib/dangermattic/plugins/tracks_checker.rb +72 -0
- data/lib/dangermattic/plugins/view_changes_checker.rb +46 -0
- data/spec/android_release_checker_spec.rb +93 -0
- data/spec/android_strings_checker_spec.rb +185 -0
- data/spec/android_unit_test_checker_spec.rb +343 -0
- data/spec/common_release_checker_spec.rb +70 -0
- data/spec/fixtures/android_unit_test_checker/Abc.java +7 -0
- data/spec/fixtures/android_unit_test_checker/AbcFeatureConfig.java +7 -0
- data/spec/fixtures/android_unit_test_checker/Abcdef.kt +5 -0
- data/spec/fixtures/android_unit_test_checker/AbcdefgViewHelper.java +7 -0
- data/spec/fixtures/android_unit_test_checker/AnotherViewHelper.kt +7 -0
- data/spec/fixtures/android_unit_test_checker/MyNewClass.java +7 -0
- data/spec/fixtures/android_unit_test_checker/Polygon.kt +3 -0
- data/spec/fixtures/android_unit_test_checker/Shape.kt +10 -0
- data/spec/fixtures/android_unit_test_checker/TestsINeedThem.java +5 -0
- data/spec/fixtures/android_unit_test_checker/TestsINeedThem.kt +7 -0
- data/spec/fixtures/android_unit_test_checker/TestsINeedThem2.kt +12 -0
- data/spec/fixtures/android_unit_test_checker/src/android/java/org/activities/MyActivity.kt +7 -0
- data/spec/fixtures/android_unit_test_checker/src/android/java/org/activities/MyJavaActivity.java +7 -0
- data/spec/fixtures/android_unit_test_checker/src/android/java/org/fragments/MyFragment.kt +6 -0
- data/spec/fixtures/android_unit_test_checker/src/android/java/org/fragments/MyNewJavaFragment.java +7 -0
- data/spec/fixtures/android_unit_test_checker/src/android/java/org/module/MyModule.java +13 -0
- data/spec/fixtures/android_unit_test_checker/src/android/java/org/view/ActionCardViewHolder.kt +22 -0
- data/spec/fixtures/android_unit_test_checker/src/android/java/org/view/MyRecyclerView.java +7 -0
- data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/AbcTests.java +5 -0
- data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/AnotherTestClass.java +7 -0
- data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/PolygonTest.kt +4 -0
- data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/TestMyNewClass.java +9 -0
- data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/ToolTest.kt +5 -0
- data/spec/fixtures/android_unit_test_checker/src/main/java/org/wordpress/android/widgets/NestedWebView.kt +32 -0
- data/spec/fixtures/android_unit_test_checker/src/main/java/org/wordpress/util/config/BloggingPromptsFeatureConfig.kt +23 -0
- data/spec/fixtures/android_unit_test_checker/src/test/java/org/test/TestsINeedThem.java +9 -0
- data/spec/github_utils_spec.rb +110 -0
- data/spec/ios_release_checker_spec.rb +191 -0
- data/spec/labels_checker_spec.rb +169 -0
- data/spec/manifest_pr_checker_spec.rb +140 -0
- data/spec/milestone_checker_spec.rb +222 -0
- data/spec/podfile_checker_spec.rb +595 -0
- data/spec/pr_size_checker_spec.rb +250 -0
- data/spec/spec_helper.rb +115 -0
- data/spec/tracks_checker_spec.rb +156 -0
- data/spec/view_changes_checker_spec.rb +168 -0
- metadata +341 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
module Danger
|
6
|
+
describe Danger::AndroidReleaseChecker do
|
7
|
+
it 'is a plugin' do
|
8
|
+
expect(described_class.new(nil)).to be_a Danger::Plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'with Dangerfile' do
|
12
|
+
before do
|
13
|
+
@dangerfile = testing_dangerfile
|
14
|
+
@plugin = @dangerfile.android_release_checker
|
15
|
+
|
16
|
+
allow(@plugin.git).to receive_messages(added_files: [], modified_files: [], deleted_files: [])
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when changing the release notes' do
|
20
|
+
it 'reports a warning when a PR changes the release notes but not the Play Store strings file' do
|
21
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['metadata/release_notes.txt'])
|
22
|
+
|
23
|
+
@plugin.check_release_notes_and_play_store_strings
|
24
|
+
|
25
|
+
expect(@dangerfile).to report_messages([format(CommonReleaseChecker::MESSAGE_STORE_FILE_NOT_CHANGED, 'metadata/PlayStoreStrings.po', 'metadata/release_notes.txt')])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'does nothing when a PR changes the release notes and the AppStore strings file' do
|
29
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['Resources/release_notes.txt', 'Resources/AppStoreStrings.po'])
|
30
|
+
|
31
|
+
@plugin.check_release_notes_and_play_store_strings
|
32
|
+
|
33
|
+
expect(@dangerfile).to not_report
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does nothing when a PR does not change the release notes or the AppStore strings file' do
|
37
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['MyView.swift', 'Resources/AppStoreStrings.tmp'])
|
38
|
+
|
39
|
+
@plugin.check_release_notes_and_play_store_strings
|
40
|
+
|
41
|
+
expect(@dangerfile).to not_report
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#check_modified_localizable_strings_on_release' do
|
46
|
+
it 'reports a warning when a PR on a regular branch changes the source strings.xml' do
|
47
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['./src/main/res/values/strings.xml'])
|
48
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('develop')
|
49
|
+
|
50
|
+
@plugin.check_modified_strings_on_release
|
51
|
+
|
52
|
+
expect(@dangerfile).to report_warnings([AndroidReleaseChecker::MESSAGE_STRINGS_FILE_UPDATED])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'reports an error when a PR on a regular branch changes the source strings.xml' do
|
56
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['./src/main/res/values/strings.xml'])
|
57
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('develop')
|
58
|
+
|
59
|
+
@plugin.check_modified_strings_on_release(report_type: :error)
|
60
|
+
|
61
|
+
expect(@dangerfile).to report_errors([AndroidReleaseChecker::MESSAGE_STRINGS_FILE_UPDATED])
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'reports a warning when a PR on a regular branch changes a translated strings.xml' do
|
65
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['src/main/res/values-fr/strings.xml'])
|
66
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('trunk')
|
67
|
+
|
68
|
+
@plugin.check_modified_strings_on_release
|
69
|
+
|
70
|
+
expect(@dangerfile).to report_warnings([AndroidReleaseChecker::MESSAGE_STRINGS_FILE_UPDATED])
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does nothing when a PR changes the strings.xml on a release branch' do
|
74
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['src/main/res/values/strings.xml'])
|
75
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('release/30.6')
|
76
|
+
|
77
|
+
@plugin.check_modified_strings_on_release
|
78
|
+
|
79
|
+
expect(@dangerfile).to not_report
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'does nothing when a PR does not change the strings.xml on a regular branch' do
|
83
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['./path/to/view/model/MyViewModel.kt'])
|
84
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('develop')
|
85
|
+
|
86
|
+
@plugin.check_modified_strings_on_release
|
87
|
+
|
88
|
+
expect(@dangerfile).to not_report
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
module Danger
|
6
|
+
describe Danger::AndroidStringsChecker do
|
7
|
+
it 'is a plugin' do
|
8
|
+
expect(described_class.new(nil)).to be_a Danger::Plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'with Dangerfile' do
|
12
|
+
before do
|
13
|
+
@dangerfile = testing_dangerfile
|
14
|
+
@plugin = @dangerfile.android_strings_checker
|
15
|
+
|
16
|
+
allow(@plugin.git).to receive_messages(added_files: [], modified_files: [], deleted_files: [])
|
17
|
+
|
18
|
+
stub_const('GitDiffStruct', Struct.new(:type, :path, :patch))
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when changing strings.xml files' do
|
22
|
+
it 'reports a warning when a PR adds a string resource reference inside a strings.xml file' do
|
23
|
+
strings_xml_path = './src/main/res/values/strings.xml'
|
24
|
+
allow(@plugin.git).to receive(:modified_files).and_return([strings_xml_path])
|
25
|
+
|
26
|
+
strings_xml_diff = <<~STRINGS
|
27
|
+
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
|
28
|
+
index 5794d472..772e2b99 100644
|
29
|
+
--- a/src/main/res/values/strings.xml
|
30
|
+
+++ b/src/main/res/values/strings.xml
|
31
|
+
@@ -1,3 +1,6 @@
|
32
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
33
|
+
<resources xmlns:tools="http://schemas.android.com/tools">
|
34
|
+
+ <string name="select_categories">Select categories</string>
|
35
|
+
+ <string name="video_quality">Video Quality</string>
|
36
|
+
+ <string name="screen_title">@string/app_name</string>
|
37
|
+
</resources>
|
38
|
+
STRINGS
|
39
|
+
|
40
|
+
diff = GitDiffStruct.new('modified', strings_xml_path, strings_xml_diff)
|
41
|
+
|
42
|
+
allow(@plugin.git).to receive(:diff_for_file).with(strings_xml_path).and_return(diff)
|
43
|
+
|
44
|
+
@plugin.check_strings_do_not_refer_resource
|
45
|
+
|
46
|
+
expected_warning = <<~WARNING
|
47
|
+
#{AndroidStringsChecker::MESSAGE}
|
48
|
+
File `#{strings_xml_path}`:
|
49
|
+
```diff
|
50
|
+
+ <string name="screen_title">@string/app_name</string>
|
51
|
+
```
|
52
|
+
WARNING
|
53
|
+
|
54
|
+
expect(@dangerfile).to report_warnings([expected_warning])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'reports multiple warnings when a PR adds multiple string resource references inside multiple strings.xml files' do
|
58
|
+
main_strings_xml = './src/main/res/values/strings.xml'
|
59
|
+
ptbr_strings_xml = './src/main/res/values-pt-rBR/strings.xml'
|
60
|
+
strings_xml_paths = [main_strings_xml, ptbr_strings_xml]
|
61
|
+
allow(@plugin.git).to receive(:modified_files).and_return(strings_xml_paths)
|
62
|
+
|
63
|
+
main_xml_diff = <<~STRINGS
|
64
|
+
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
|
65
|
+
index 5794d472..772e2b99 100644
|
66
|
+
--- a/src/main/res/values/strings.xml
|
67
|
+
+++ b/src/main/res/values/strings.xml
|
68
|
+
@@ -1,3 +1,6 @@
|
69
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
70
|
+
<resources xmlns:tools="http://schemas.android.com/tools">
|
71
|
+
+ <string name="select_categories">Select categories</string>
|
72
|
+
+ <string name="video_quality">Video Quality</string>
|
73
|
+
+ <string name="screen_title">@string/app_name</string>
|
74
|
+
+ <string name="screen_button">@string/button</string>
|
75
|
+
- <string name="field_hint">@string/hint</string>
|
76
|
+
</resources>
|
77
|
+
STRINGS
|
78
|
+
|
79
|
+
main_diff = GitDiffStruct.new('modified', main_strings_xml, main_xml_diff)
|
80
|
+
|
81
|
+
allow(@plugin.git).to receive(:diff_for_file).with(main_strings_xml).and_return(main_diff)
|
82
|
+
|
83
|
+
ptbr_xml_diff = <<~STRINGS
|
84
|
+
diff --git a/src/main/res/values-pt-rBR/strings.xml b/src/main/res/values-pt-rBR/strings.xml
|
85
|
+
index 5794d472..772e2b99 100644
|
86
|
+
--- a/src/main/res/values-pt-rBR/strings.xml
|
87
|
+
+++ b/src/main/res/values-pt-rBR/strings.xml
|
88
|
+
@@ -1,3 +1,6 @@
|
89
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
90
|
+
<resources xmlns:tools="http://schemas.android.com/tools">
|
91
|
+
+ <string name="video_quality">Video Quality</string>
|
92
|
+
+ <string name="popup_title">@string/app_name_title</string>
|
93
|
+
- <string name="toast">@string/common_toast</string>
|
94
|
+
</resources>
|
95
|
+
STRINGS
|
96
|
+
|
97
|
+
ptbr_diff = GitDiffStruct.new('modified', ptbr_strings_xml, ptbr_xml_diff)
|
98
|
+
|
99
|
+
allow(@plugin.git).to receive(:diff_for_file).with(ptbr_strings_xml).and_return(ptbr_diff)
|
100
|
+
|
101
|
+
@plugin.check_strings_do_not_refer_resource
|
102
|
+
|
103
|
+
expected_warning = <<~WARNING
|
104
|
+
#{AndroidStringsChecker::MESSAGE}
|
105
|
+
File `#{main_strings_xml}`:
|
106
|
+
```diff
|
107
|
+
+ <string name="screen_title">@string/app_name</string>
|
108
|
+
```
|
109
|
+
WARNING
|
110
|
+
|
111
|
+
expected_warning2 = <<~WARNING
|
112
|
+
#{AndroidStringsChecker::MESSAGE}
|
113
|
+
File `#{main_strings_xml}`:
|
114
|
+
```diff
|
115
|
+
+ <string name="screen_button">@string/button</string>
|
116
|
+
```
|
117
|
+
WARNING
|
118
|
+
|
119
|
+
expected_warning3 = <<~WARNING
|
120
|
+
#{AndroidStringsChecker::MESSAGE}
|
121
|
+
File `#{ptbr_strings_xml}`:
|
122
|
+
```diff
|
123
|
+
+ <string name="popup_title">@string/app_name_title</string>
|
124
|
+
```
|
125
|
+
WARNING
|
126
|
+
|
127
|
+
expect(@dangerfile.status_report[:warnings]).to contain_exactly(expected_warning, expected_warning2, expected_warning3)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'does nothing when a PR adds a string resource reference inside a strings.xml file but with translatable=\"false\"' do
|
131
|
+
strings_xml_path = './src/main/res/values/strings.xml'
|
132
|
+
allow(@plugin.git).to receive(:modified_files).and_return([strings_xml_path])
|
133
|
+
|
134
|
+
strings_xml_diff = <<~STRINGS
|
135
|
+
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
|
136
|
+
index 5794d472..772e2b99 100644
|
137
|
+
--- a/src/main/res/values/strings.xml
|
138
|
+
+++ b/src/main/res/values/strings.xml
|
139
|
+
@@ -1,3 +1,6 @@
|
140
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
141
|
+
<resources xmlns:tools="http://schemas.android.com/tools">
|
142
|
+
+ <string name="select_categories">Select categories</string>
|
143
|
+
+ <string name="video_quality">Video Quality</string>
|
144
|
+
+ <string name="screen_title" translatable="false">@string/app_name</string>
|
145
|
+
</resources>
|
146
|
+
STRINGS
|
147
|
+
|
148
|
+
diff = GitDiffStruct.new('modified', strings_xml_path, strings_xml_diff)
|
149
|
+
|
150
|
+
allow(@plugin.git).to receive(:diff_for_file).with(strings_xml_path).and_return(diff)
|
151
|
+
|
152
|
+
@plugin.check_strings_do_not_refer_resource
|
153
|
+
|
154
|
+
expect(@dangerfile).to not_report
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'does nothing when a PR adds strings without resource references' do
|
158
|
+
strings_xml_path = './src/main/res/values/strings.xml'
|
159
|
+
allow(@plugin.git).to receive(:modified_files).and_return([strings_xml_path])
|
160
|
+
|
161
|
+
strings_xml_diff = <<~STRINGS
|
162
|
+
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
|
163
|
+
index 5794d472..772e2b99 100644
|
164
|
+
--- a/src/main/res/values/strings.xml
|
165
|
+
+++ b/src/main/res/values/strings.xml
|
166
|
+
@@ -1,3 +1,6 @@
|
167
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
168
|
+
<resources xmlns:tools="http://schemas.android.com/tools">
|
169
|
+
+ <string name="select_categories">Select categories</string>
|
170
|
+
+ <string name="video_quality">Video Quality</string>
|
171
|
+
</resources>
|
172
|
+
STRINGS
|
173
|
+
|
174
|
+
diff = GitDiffStruct.new('modified', strings_xml_path, strings_xml_diff)
|
175
|
+
|
176
|
+
allow(@plugin.git).to receive(:diff_for_file).with(strings_xml_path).and_return(diff)
|
177
|
+
|
178
|
+
@plugin.check_strings_do_not_refer_resource
|
179
|
+
|
180
|
+
expect(@dangerfile).to not_report
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,343 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
module Danger
|
6
|
+
describe Danger::AndroidUnitTestChecker do
|
7
|
+
it 'is a plugin' do
|
8
|
+
expect(described_class.new(nil)).to be_a Danger::Plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'with Dangerfile' do
|
12
|
+
before do
|
13
|
+
@dangerfile = testing_dangerfile
|
14
|
+
@plugin = @dangerfile.android_unit_test_checker
|
15
|
+
|
16
|
+
allow(@plugin.github).to receive(:pr_labels).and_return(['my_label'])
|
17
|
+
|
18
|
+
stub_const('GitDiffStruct', Struct.new(:type, :path, :patch))
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'reports the right errors when a PR adds new classes that do not have corresponding tests' do
|
22
|
+
added_files = %w[
|
23
|
+
src/main/java/org/wordpress/util/config/BloggingPromptsFeatureConfig.kt
|
24
|
+
Abc.java
|
25
|
+
src/androidTest/java/org/test/ToolTest.kt
|
26
|
+
Polygon.kt
|
27
|
+
Abcdef.kt
|
28
|
+
TestsINeedThem.java
|
29
|
+
TestsINeedThem2.kt
|
30
|
+
]
|
31
|
+
|
32
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
33
|
+
|
34
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
35
|
+
|
36
|
+
@plugin.check_missing_tests
|
37
|
+
|
38
|
+
classes = %w[
|
39
|
+
BloggingPromptsFeatureConfig
|
40
|
+
Abc
|
41
|
+
Polygon
|
42
|
+
Abcdef
|
43
|
+
TestsINeedThem
|
44
|
+
TestsINeedThem2
|
45
|
+
TestsINeedThem2AnotherClass
|
46
|
+
]
|
47
|
+
|
48
|
+
expect_class_names_match_report(class_names: classes, error_report: @dangerfile.status_report[:errors])
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'does not report errors when new classes have corresponding tests' do
|
52
|
+
added_files = %w[
|
53
|
+
Abc.java
|
54
|
+
src/androidTest/java/org/test/AbcTests.java
|
55
|
+
Polygon.kt
|
56
|
+
src/androidTest/java/org/test/PolygonTest.kt
|
57
|
+
TestsINeedThem.java
|
58
|
+
src/androidTest/java/org/test/AnotherTestClass.java
|
59
|
+
MyNewClass.java
|
60
|
+
src/androidTest/java/org/test/TestMyNewClass.java
|
61
|
+
]
|
62
|
+
|
63
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
64
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
65
|
+
|
66
|
+
@plugin.check_missing_tests
|
67
|
+
|
68
|
+
expect(@dangerfile).to not_report
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'does not report errors when we are deleting classes' do
|
72
|
+
deleted_files = %w[
|
73
|
+
Abc.java
|
74
|
+
Polygon.kt
|
75
|
+
TestsINeedThem.java
|
76
|
+
]
|
77
|
+
|
78
|
+
diff = generate_delete_diff_from_fixtures(deleted_files)
|
79
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
80
|
+
|
81
|
+
@plugin.check_missing_tests
|
82
|
+
|
83
|
+
expect(@dangerfile).to not_report
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'reports errors when we remove test classes for classes we refactored' do
|
87
|
+
added_files = %w[
|
88
|
+
Abc.java
|
89
|
+
Polygon.kt
|
90
|
+
TestsINeedThem.kt
|
91
|
+
]
|
92
|
+
|
93
|
+
removed_files = %w[
|
94
|
+
src/androidTest/java/org/test/AbcTests.java
|
95
|
+
src/androidTest/java/org/test/PolygonTest.kt
|
96
|
+
src/test/java/org/test/TestsINeedThem.java
|
97
|
+
]
|
98
|
+
|
99
|
+
diff = generate_add_diff_from_fixtures(added_files) + generate_delete_diff_from_fixtures(removed_files)
|
100
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
101
|
+
|
102
|
+
@plugin.check_missing_tests
|
103
|
+
|
104
|
+
classes = %w[
|
105
|
+
Abc
|
106
|
+
Polygon
|
107
|
+
TestsINeedThem
|
108
|
+
]
|
109
|
+
|
110
|
+
expect_class_names_match_report(class_names: classes, error_report: @dangerfile.status_report[:errors])
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'does nothing when a PR adds only tests' do
|
114
|
+
added_files = %w[
|
115
|
+
src/androidTest/java/org/test/AbcTests.java
|
116
|
+
src/androidTest/java/org/test/PolygonTest.kt
|
117
|
+
src/test/java/org/test/TestsINeedThem.java
|
118
|
+
]
|
119
|
+
|
120
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
121
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
122
|
+
|
123
|
+
@plugin.check_missing_tests
|
124
|
+
|
125
|
+
expect(@dangerfile).to not_report
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'does nothing when a PR adds classes that dont need tests' do
|
129
|
+
added_files = %w[
|
130
|
+
src/android/java/org/activities/MyActivity.kt
|
131
|
+
src/android/java/org/activities/MyJavaActivity.java
|
132
|
+
src/android/java/org/fragments/MyFragment.kt
|
133
|
+
src/android/java/org/fragments/MyNewJavaFragment.java
|
134
|
+
src/android/java/org/module/MyModule.java
|
135
|
+
src/android/java/org/view/MyRecyclerView.java
|
136
|
+
src/android/java/org/view/ActionCardViewHolder.kt
|
137
|
+
]
|
138
|
+
|
139
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
140
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
141
|
+
|
142
|
+
@plugin.check_missing_tests
|
143
|
+
|
144
|
+
expect(@dangerfile).to not_report
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'does not report that a PR with the tests bypass label is missing tests' do
|
148
|
+
added_files = %w[
|
149
|
+
Abc.java
|
150
|
+
Abcdef.kt
|
151
|
+
TestsINeedThem2.kt
|
152
|
+
]
|
153
|
+
|
154
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
155
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
156
|
+
allow(@plugin.github).to receive(:pr_labels).and_return(['unit-tests-exemption'])
|
157
|
+
|
158
|
+
@plugin.check_missing_tests
|
159
|
+
|
160
|
+
expected_warnings = [
|
161
|
+
'Class `Abc` is missing tests, but `unit-tests-exemption` label was set to ignore this.',
|
162
|
+
'Class `Abcdef` is missing tests, but `unit-tests-exemption` label was set to ignore this.',
|
163
|
+
'Class `TestsINeedThem2` is missing tests, but `unit-tests-exemption` label was set to ignore this.',
|
164
|
+
'Class `TestsINeedThem2AnotherClass` is missing tests, but `unit-tests-exemption` label was set to ignore this.'
|
165
|
+
]
|
166
|
+
expect(@dangerfile).to report_warnings(expected_warnings)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'does not report errors when a PR without tests with a custom bypass label is missing tests' do
|
170
|
+
added_files = %w[
|
171
|
+
Abc.java
|
172
|
+
src/androidTest/java/org/test/AnotherTestClass.java
|
173
|
+
Abcdef.kt
|
174
|
+
]
|
175
|
+
|
176
|
+
ignore_label = 'ignore-no-tests'
|
177
|
+
|
178
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
179
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
180
|
+
allow(@plugin.github).to receive(:pr_labels).and_return([ignore_label])
|
181
|
+
|
182
|
+
@plugin.check_missing_tests(bypass_label: ignore_label)
|
183
|
+
|
184
|
+
expected_warnings = [
|
185
|
+
'Class `Abc` is missing tests, but `ignore-no-tests` label was set to ignore this.',
|
186
|
+
'Class `Abcdef` is missing tests, but `ignore-no-tests` label was set to ignore this.'
|
187
|
+
]
|
188
|
+
expect(@dangerfile).to report_warnings(expected_warnings)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'does not report that added classes that need tests but with custom classes exception patterns are missing tests' do
|
192
|
+
added_files = %w[
|
193
|
+
src/androidTest/java/org/test/ToolTest.kt
|
194
|
+
AnotherViewHelper.kt
|
195
|
+
AbcdefgViewHelper.java
|
196
|
+
TestsINeedThem.java
|
197
|
+
]
|
198
|
+
|
199
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
200
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
201
|
+
|
202
|
+
classes_to_ignore = [
|
203
|
+
/ViewHelper$/
|
204
|
+
].freeze
|
205
|
+
|
206
|
+
@plugin.check_missing_tests(classes_exceptions: classes_to_ignore)
|
207
|
+
|
208
|
+
classes = ['TestsINeedThem']
|
209
|
+
expect_class_names_match_report(class_names: classes, error_report: @dangerfile.status_report[:errors])
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'does not report that added classes that need tests but with custom subclasses exception patterns are missing tests' do
|
213
|
+
added_files = %w[
|
214
|
+
AbcFeatureConfig.java
|
215
|
+
src/main/java/org/wordpress/android/widgets/NestedWebView.kt
|
216
|
+
src/androidTest/java/org/test/AnotherTestClass.java
|
217
|
+
src/main/java/org/wordpress/util/config/BloggingPromptsFeatureConfig.kt
|
218
|
+
]
|
219
|
+
|
220
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
221
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
222
|
+
|
223
|
+
subclasses_to_ignore = [
|
224
|
+
/FeatureConfig$/
|
225
|
+
].freeze
|
226
|
+
|
227
|
+
@plugin.check_missing_tests(subclasses_exceptions: subclasses_to_ignore)
|
228
|
+
|
229
|
+
classes = ['NestedWebView']
|
230
|
+
expect_class_names_match_report(class_names: classes, error_report: @dangerfile.status_report[:errors])
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'does not report that added classes with a path filter are missing tests' do
|
234
|
+
added_files = %w[
|
235
|
+
AbcFeatureConfig.java
|
236
|
+
AnotherViewHelper.kt
|
237
|
+
src/main/java/org/wordpress/util/config/BloggingPromptsFeatureConfig.kt
|
238
|
+
]
|
239
|
+
|
240
|
+
diff = generate_add_diff_from_fixtures(added_files)
|
241
|
+
allow(@dangerfile.git).to receive(:diff).and_return(diff)
|
242
|
+
|
243
|
+
path_exceptions = ['src/main/java/org/wordpress/**', '*.java']
|
244
|
+
|
245
|
+
@plugin.check_missing_tests(path_exceptions: path_exceptions)
|
246
|
+
|
247
|
+
classes = ['AnotherViewHelper']
|
248
|
+
expect_class_names_match_report(class_names: classes, error_report: @dangerfile.status_report[:errors])
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'does nothing when a PR moves code around with both additions and removals in the diff' do
|
252
|
+
shape_file = 'Shape.kt'
|
253
|
+
|
254
|
+
polygon_test_diff_str = <<~PATCH
|
255
|
+
diff --git a/PolygonTest.kt b/PolygonTest.kt
|
256
|
+
index 8c2bed6..ae81c49 100644
|
257
|
+
--- a/PolygonTest.kt
|
258
|
+
+++ b/PolygonTest.kt
|
259
|
+
@@ -1,8 +1,9 @@
|
260
|
+
-class PolygonTest {
|
261
|
+
- val sut10: Shape = Polygon(sides = 10)
|
262
|
+
- val sut5: Shape = Polygon(sides = 5)
|
263
|
+
-
|
264
|
+
- fun testDraw() {
|
265
|
+
- Polygon(sides = 5).draw()
|
266
|
+
+class ShapesTest {
|
267
|
+
+ fun testPentagon() {
|
268
|
+
+ draw(Polygon(sides = 5))
|
269
|
+
+ }
|
270
|
+
+
|
271
|
+
+ private fun draw(shape: Shape) {
|
272
|
+
+ shape.draw()
|
273
|
+
}
|
274
|
+
}
|
275
|
+
PATCH
|
276
|
+
|
277
|
+
shape_diff = generate_add_diff_from_fixtures([shape_file])
|
278
|
+
polygon_diff = GitDiffStruct.new('modified', 'project/src/androidTest/java/shapes/PolygonTest.kt', polygon_test_diff_str)
|
279
|
+
|
280
|
+
allow(@dangerfile.git).to receive(:diff).and_return(shape_diff + [polygon_diff])
|
281
|
+
|
282
|
+
@plugin.check_missing_tests
|
283
|
+
|
284
|
+
expect(@dangerfile).to not_report
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def generate_add_diff_from_fixtures(paths)
|
289
|
+
paths.map do |path|
|
290
|
+
content = fixture(File.join('android_unit_test_checker', path))
|
291
|
+
diff_str = generate_add_diff(file_path: path, content: content)
|
292
|
+
|
293
|
+
GitDiffStruct.new('new', path, diff_str)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
def generate_delete_diff_from_fixtures(paths)
|
298
|
+
paths.map do |path|
|
299
|
+
content = fixture(File.join('android_unit_test_checker', path))
|
300
|
+
diff_str = generate_delete_diff(file_path: path, content: content)
|
301
|
+
|
302
|
+
GitDiffStruct.new('deleted', path, diff_str)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def generate_delete_diff(file_path:, content:)
|
307
|
+
<<~PATCH
|
308
|
+
diff --git a/#{file_path} b/#{file_path}
|
309
|
+
deleted file mode 100644
|
310
|
+
index fd48a22..0000000
|
311
|
+
--- a/#{file_path}
|
312
|
+
+++ /dev/null
|
313
|
+
@@ -1 +0,0 @@
|
314
|
+
#{prefix_text_lines(content: content, prefix: '-')}
|
315
|
+
\
|
316
|
+
PATCH
|
317
|
+
end
|
318
|
+
|
319
|
+
def generate_add_diff(file_path:, content:)
|
320
|
+
<<~PATCH
|
321
|
+
diff --git a/#{file_path} b/#{file_path}
|
322
|
+
new file mode 100644
|
323
|
+
index 0000000..fd48a22
|
324
|
+
--- /dev/null
|
325
|
+
+++ b/#{file_path}
|
326
|
+
@@ -0,0 +1 @@
|
327
|
+
#{prefix_text_lines(content: content, prefix: '+')}
|
328
|
+
\
|
329
|
+
PATCH
|
330
|
+
end
|
331
|
+
|
332
|
+
def prefix_text_lines(content:, prefix:)
|
333
|
+
content.lines.map { |line| "#{prefix}#{line.chomp}" }.join("\n")
|
334
|
+
end
|
335
|
+
|
336
|
+
def expect_class_names_match_report(class_names:, error_report:)
|
337
|
+
expect(class_names.length).to eq(error_report.length)
|
338
|
+
class_names.zip(error_report).each do |cls, error|
|
339
|
+
expect(error).to include "Please add tests for class `#{cls}`"
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
module Danger
|
6
|
+
describe Danger::CommonReleaseChecker do
|
7
|
+
it 'is a plugin' do
|
8
|
+
expect(described_class.new(nil)).to be_a Danger::Plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'with the common_release_checker plugin' do
|
12
|
+
before do
|
13
|
+
@dangerfile = testing_dangerfile
|
14
|
+
@plugin = @dangerfile.common_release_checker
|
15
|
+
|
16
|
+
allow(@plugin.git).to receive_messages(added_files: [], modified_files: [], deleted_files: [])
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when changing the internal release notes' do
|
20
|
+
it 'reports a warning when a PR on a release branch changes the internal release notes' do
|
21
|
+
notes_file = 'RELEASE-NOTES.txt'
|
22
|
+
allow(@plugin.git).to receive(:modified_files).and_return([notes_file])
|
23
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('release/30.6')
|
24
|
+
|
25
|
+
@plugin.check_internal_release_notes_changed
|
26
|
+
|
27
|
+
expect(@dangerfile).to report_warnings([format(CommonReleaseChecker::MESSAGE_INTERNAL_RELEASE_NOTES_CHANGED, notes_file)])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'reports a warning when a PR on a release branch changes the internal release notes using a custom filename' do
|
31
|
+
notes_file = 'MY-CUSTOM-RELEASE-NOTES.md'
|
32
|
+
allow(@plugin.git).to receive(:modified_files).and_return([notes_file])
|
33
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('release/30.6')
|
34
|
+
|
35
|
+
@plugin.check_internal_release_notes_changed(release_notes_file: notes_file)
|
36
|
+
|
37
|
+
expect(@dangerfile).to report_warnings([format(CommonReleaseChecker::MESSAGE_INTERNAL_RELEASE_NOTES_CHANGED, notes_file)])
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'does nothing when a PR changes the release notes file on a regular branch' do
|
41
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['RELEASE-NOTES.txt'])
|
42
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('develop')
|
43
|
+
|
44
|
+
@plugin.check_internal_release_notes_changed
|
45
|
+
|
46
|
+
expect(@dangerfile).to not_report
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'does nothing when a PR changes a custom release notes file on a regular branch' do
|
50
|
+
notes_file = 'MY-CUSTOM-RELEASE-NOTES.md'
|
51
|
+
allow(@plugin.git).to receive(:modified_files).and_return([notes_file])
|
52
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('develop')
|
53
|
+
|
54
|
+
@plugin.check_internal_release_notes_changed(release_notes_file: notes_file)
|
55
|
+
|
56
|
+
expect(@dangerfile).to not_report
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'does nothing when a PR ca warning when a PR does not change the release notes file on the release branch' do
|
60
|
+
allow(@plugin.git).to receive(:modified_files).and_return(['./path/to/view/MyView.swift'])
|
61
|
+
allow(@plugin.github).to receive(:branch_for_base).and_return('release/30.6')
|
62
|
+
|
63
|
+
@plugin.check_internal_release_notes_changed
|
64
|
+
|
65
|
+
expect(@dangerfile).to not_report
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|