Skip to content

Commit 9ba9558

Browse files
committed
Fix integration tests for single mode
1 parent 8abeb0b commit 9ba9558

File tree

4 files changed

+92
-18
lines changed

4 files changed

+92
-18
lines changed

lib/pmdtester/runner.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def initialize(argv)
1212

1313
def run
1414
clean unless @options.keep_reports
15+
1516
case @options.mode
1617
when Options::LOCAL
1718
run_local_mode
@@ -35,8 +36,8 @@ def run_local_mode
3536
rule_sets = RuleSetBuilder.new(@options).build if @options.auto_config_flag
3637
return if rule_sets&.empty?
3738

38-
base_branch_details = make_branch_details(config: @options.base_config, branch: @options.base_branch)
39-
patch_branch_details = make_branch_details(config: @options.patch_config, branch: @options.patch_branch)
39+
base_branch_details = create_pmd_report(config: @options.base_config, branch: @options.base_branch)
40+
patch_branch_details = create_pmd_report(config: @options.patch_config, branch: @options.patch_branch)
4041

4142
build_html_reports(@projects, base_branch_details, patch_branch_details)
4243
end
@@ -60,7 +61,7 @@ def run_online_mode
6061
logger.info "Using config #{@options.patch_config} which might differ from baseline"
6162
end
6263

63-
patch_branch_details = make_branch_details(config: @options.patch_config, branch: @options.patch_branch)
64+
patch_branch_details = create_pmd_report(config: @options.patch_config, branch: @options.patch_branch)
6465

6566
base_branch_details = PmdBranchDetail.load(@options.base_branch, logger)
6667
build_html_reports(@projects, base_branch_details, patch_branch_details)
@@ -106,12 +107,16 @@ def run_single_mode
106107
logger.info "Mode: #{@options.mode}"
107108

108109
get_projects(@options.project_list) unless @options.nil?
109-
patch_branch_details = make_branch_details(config: @options.patch_config, branch: @options.patch_branch)
110+
patch_branch_details = create_pmd_report(config: @options.patch_config, branch: @options.patch_branch)
110111
# copy list of projects file to the patch baseline
111112
FileUtils.cp(@options.project_list, patch_branch_details.target_branch_project_list_path)
112113

113-
base_branch_details = PmdBranchDetail.load(@options.base_branch, logger)
114-
build_html_reports(@projects, base_branch_details, patch_branch_details) unless @options.html_flag
114+
# for creating a baseline, no html report is needed
115+
return if @options.html_flag
116+
117+
# in single mode, we don't have a base branch, only a patch branch...
118+
empty_base_branch_details = PmdBranchDetail.load('single-mode', logger)
119+
build_html_reports(@projects, empty_base_branch_details, patch_branch_details)
115120
end
116121

117122
def get_projects(file_path)
@@ -125,8 +130,11 @@ def summarize_diffs
125130
@projects.each do |project|
126131
diff = project.report_diff
127132

128-
error_total.merge!(diff.error_counts)
129-
violations_total.merge!(diff.violation_counts)
133+
# in case we are in single mode, there might be no diffs (only the patch branch is available)
134+
unless diff.nil?
135+
error_total.merge!(diff.error_counts)
136+
violations_total.merge!(diff.violation_counts)
137+
end
130138
end
131139

132140
{
@@ -138,7 +146,7 @@ def summarize_diffs
138146

139147
private
140148

141-
def make_branch_details(config:, branch:)
149+
def create_pmd_report(config:, branch:)
142150
PmdReportBuilder.new(@projects, @options, config, branch).build
143151
end
144152
end

test/integration_test_runner.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def test_local_mode
2727

2828
def test_single_mode
2929
argv = '-r target/repositories/pmd -m single' \
30-
' -p pmd_releases/6.7.0 -pc config/design.xml -l test/resources/project-test.xml'
30+
' -p pmd_releases/6.7.0 -pc config/design.xml' \
31+
' -l test/resources/integration_test_runner/project-list-single.xml'
3132

3233
system("bundle exec bin/pmdtester #{argv}")
3334

@@ -42,7 +43,9 @@ def test_single_mode
4243

4344
def test_single_mode_with_html_flag_option
4445
argv = '-r target/repositories/pmd -m single' \
45-
' -p pmd_releases/6.7.0 -pc config/design.xml -l test/resources/project-test.xml -f'
46+
' -p pmd_releases/6.7.0 -pc config/design.xml' \
47+
' -l test/resources/integration_test_runner/project-list-single.xml' \
48+
' -f'
4649

4750
system("bundle exec bin/pmdtester #{argv}")
4851

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
3+
<projectlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="projectlist_1_1_0.xsd">
5+
<description>Projects used in integration_test_runner.rb</description>
6+
7+
<project>
8+
<name>checkstyle</name>
9+
<type>git</type>
10+
<connection>https://github.com/checkstyle/checkstyle</connection>
11+
<tag>checkstyle-8.10</tag>
12+
<exclude-pattern>.*/target/test-classes/com/puppycrawl/tools/checkstyle/.*</exclude-pattern>
13+
<exclude-pattern>.*/target/generated-sources/.*</exclude-pattern>
14+
15+
<build-command><![CDATA[#!/usr/bin/env bash
16+
if test -e classpath.txt; then
17+
exit
18+
fi
19+
20+
set -e
21+
22+
mvn clean test-compile
23+
mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=classpath.txt
24+
]]></build-command>
25+
<auxclasspath-command>echo -n "$(pwd)/target/classes:$(pwd)/target/test-classes:"; cat classpath.txt</auxclasspath-command>
26+
</project>
27+
28+
<!-- this project configuration is here, so that PMD's repo is cloned into target/repositories for integration tests -->
29+
<project>
30+
<name>pmd</name>
31+
<type>git</type>
32+
<connection>https://github.com/pmd/pmd</connection>
33+
<tag>pmd_releases/6.7.0</tag> <!-- this is already the correct checkout to speed up repeated integration tests -->
34+
</project>
35+
</projectlist>

test/test_runner.rb

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def setup
1212

1313
def run_runner(argv)
1414
runner = Runner.new(argv)
15-
runner.expects(:summarize_diffs).once
1615
runner.run
1716
end
1817

@@ -27,7 +26,22 @@ def test_single_mode
2726

2827
argv = %w[-r target/repositories/pmd -p pmd_releases/6.1.0
2928
-pc config/design.xml -l test/resources/project-test.xml -m single]
30-
run_runner(argv)
29+
summarized_results = run_runner(argv)
30+
assert_summarized_diffs(summarized_results)
31+
end
32+
33+
def test_single_mode_no_html
34+
project_list_path = 'test/resources/project-test.xml'
35+
target_project_list_path = 'target/reports/test_branch/project-list.xml'
36+
PmdReportBuilder.any_instance.stubs(:build)
37+
.returns(PmdBranchDetail.new('test_branch')).once
38+
FileUtils.expects(:cp).with(project_list_path, target_project_list_path).once
39+
40+
argv = %w[-r target/repositories/pmd -p pmd_releases/6.1.0
41+
-pc config/design.xml -l test/resources/project-test.xml -m single
42+
--html-flag]
43+
summarized_results = run_runner(argv)
44+
assert_summarized_diffs(summarized_results)
3145
end
3246

3347
def test_single_mode_multithreading
@@ -45,7 +59,8 @@ def test_single_mode_multithreading
4559

4660
argv = %w[-r target/repositories/pmd -p pmd_releases/6.1.0
4761
-pc config/design.xml -l test/resources/project-test.xml -m single -t 4]
48-
run_runner(argv)
62+
summarized_results = run_runner(argv)
63+
assert_summarized_diffs(summarized_results)
4964
end
5065

5166
def test_local_mode
@@ -55,7 +70,8 @@ def test_local_mode
5570

5671
argv = %w[-r target/repositories/pmd -b master -bc config/design.xml -p pmd_releases/6.1.0
5772
-pc config/design.xml -l test/resources/project-test.xml]
58-
run_runner(argv)
73+
summarized_results = run_runner(argv)
74+
assert_summarized_diffs(summarized_results)
5975
end
6076

6177
def test_local_mode_multithreading
@@ -72,7 +88,8 @@ def test_local_mode_multithreading
7288

7389
argv = %w[-r target/repositories/pmd -b master -bc config/design.xml -p pmd_releases/6.1.0
7490
-pc config/design.xml -l test/resources/project-test.xml -t 5]
75-
run_runner(argv)
91+
summarized_results = run_runner(argv)
92+
assert_summarized_diffs(summarized_results)
7693
end
7794

7895
def test_online_mode
@@ -92,7 +109,8 @@ def test_online_mode
92109
PmdReportBuilder.any_instance.stubs(:build).returns(PmdBranchDetail.new('test_branch')).once
93110

94111
argv = %w[-r target/repositories/pmd -m online -b master -p pmd_releases/6.7.0]
95-
run_runner(argv)
112+
summarized_results = run_runner(argv)
113+
assert_summarized_diffs(summarized_results)
96114
end
97115

98116
def test_online_mode_multithreading
@@ -114,6 +132,16 @@ def test_online_mode_multithreading
114132
SummaryReportBuilder.any_instance.stubs(:write_all_projects).once
115133

116134
argv = %w[-r target/repositories/pmd -m online -b master -p pmd_releases/6.7.0 -t 3]
117-
run_runner(argv)
135+
summarized_results = run_runner(argv)
136+
assert_summarized_diffs(summarized_results)
137+
end
138+
139+
private
140+
141+
def assert_summarized_diffs(diffs)
142+
refute_nil(diffs)
143+
refute_nil(diffs[:errors])
144+
refute_nil(diffs[:violations])
145+
refute_nil(diffs[:configerrors])
118146
end
119147
end

0 commit comments

Comments
 (0)