@@ -97,7 +97,7 @@ def test_build_with_projects
9797 projects [ 0 ] . auxclasspath = 'extra:dirs'
9898 record_expectations ( 'sha1abc' , 'sha1abc' , true )
9999 record_expectations_after_build
100- record_expectations_project_build ( 'sha1abc' )
100+ record_expectations_project_build ( sha1 : 'sha1abc' )
101101
102102 PmdTester ::PmdReportBuilder
103103 . new ( projects , options , options . base_config , options . base_branch )
@@ -120,7 +120,7 @@ def test_build_error_recovery
120120 projects [ 0 ] . auxclasspath = 'extra:dirs'
121121 record_expectations ( 'sha1abc' , 'sha1abc' , true )
122122 record_expectations_after_build
123- record_expectations_project_build ( 'sha1abc' , true )
123+ record_expectations_project_build ( sha1 : 'sha1abc' , error : true )
124124
125125 PmdTester ::PmdReportBuilder
126126 . new ( projects , options , options . base_config , options . base_branch )
@@ -140,7 +140,7 @@ def test_build_long_cli_options
140140 projects [ 0 ] . auxclasspath = 'extra:dirs'
141141 record_expectations ( 'sha1abc' , 'sha1abc' , true )
142142 record_expectations_after_build
143- record_expectations_project_build ( 'sha1abc' , true , true )
143+ record_expectations_project_build ( sha1 : 'sha1abc' , error : true , long_cli_options : true )
144144
145145 PmdTester ::PmdReportBuilder
146146 . new ( projects , options , options . base_config , options . base_branch )
@@ -149,6 +149,7 @@ def test_build_long_cli_options
149149
150150 def test_build_pmd7
151151 @pmd_version = '7.0.0-SNAPSHOT'
152+ sha1 = 'sha1abc'
152153 project_list = 'test/resources/pmd_report_builder/project-list.xml'
153154 projects = PmdTester ::ProjectsParser . new . parse ( project_list )
154155 assert_equal ( 1 , projects . size )
@@ -158,13 +159,19 @@ def test_build_pmd7
158159 options = PmdTester ::Options . new ( argv )
159160
160161 projects [ 0 ] . auxclasspath = 'extra:dirs'
161- record_expectations ( 'sha1abc' , 'sha1abc' , true )
162+ record_expectations ( sha1 , sha1 , true )
162163 record_expectations_after_build
163- record_expectations_project_build ( 'sha1abc' , true , true , true )
164-
165- PmdTester ::PmdReportBuilder
166- . new ( projects , options , options . base_config , options . base_branch )
167- . build
164+ record_expectations_project_build ( sha1 : sha1 , error : true , long_cli_options : true ,
165+ no_progress_bar : true , base_cmd : 'pmd check' )
166+
167+ pmd_cli_cmd = prepare_pmd_dist_dir ( version : @pmd_version , sha1 : sha1 )
168+ begin
169+ PmdTester ::PmdReportBuilder
170+ . new ( projects , options , options . base_config , options . base_branch )
171+ . build
172+ ensure
173+ cleanup_pmd_dist_dir ( base_dir : pmd_cli_cmd )
174+ end
168175 end
169176
170177 #
@@ -183,7 +190,7 @@ def test_build_failing
183190 projects [ 0 ] . auxclasspath = 'extra:dirs'
184191 record_expectations ( 'sha1abc' , 'sha1abc' , true )
185192 record_expectations_after_build
186- record_expectations_project_build ( 'sha1abc' , true , false , false , 1 )
193+ record_expectations_project_build ( sha1 : 'sha1abc' , error : true , exit_status : 1 )
187194
188195 PmdTester ::PmdReportBuilder
189196 . new ( projects , options , options . base_config , options . base_branch )
@@ -192,8 +199,8 @@ def test_build_failing
192199
193200 private
194201
195- def record_expectations_project_build ( sha1 , error = false , long_cli_options = false ,
196- no_progress_bar = false , exit_status = 0 )
202+ def record_expectations_project_build ( sha1 : , error : false , long_cli_options : false ,
203+ no_progress_bar : false , exit_status : 0 , base_cmd : 'run.sh pmd' )
197204 PmdTester ::ProjectBuilder . any_instance . stubs ( :clone_projects ) . once
198205 PmdTester ::ProjectBuilder . any_instance . stubs ( :build_projects ) . once
199206 PmdTester ::SimpleProgressLogger . any_instance . stubs ( :start ) . once
@@ -204,8 +211,8 @@ def record_expectations_project_build(sha1, error = false, long_cli_options = fa
204211 process_status . expects ( :exitstatus ) . returns ( exit_status ) . once
205212 PmdTester ::Cmd . stubs ( :execute )
206213 . with ( "#{ error_prefix } " \
207- "#{ distro_path } /bin/run.sh " \
208- 'pmd -d target/repositories/checkstyle -f xml ' \
214+ "#{ distro_path } /bin/#{ base_cmd } " \
215+ '-d target/repositories/checkstyle -f xml ' \
209216 '-R target/reports/master/checkstyle/config.xml ' \
210217 '-r target/reports/master/checkstyle/pmd_report.xml ' \
211218 "#{ long_cli_options ? '--fail-on-violation false' : '-failOnViolation false' } -t 1 " \
@@ -244,4 +251,18 @@ def record_expectations_after_build
244251 PmdTester ::PmdBranchDetail . any_instance . stubs ( :save ) . once
245252 FileUtils . stubs ( :cp ) . with ( 'config/design.xml' , 'target/reports/master/config.xml' ) . once
246253 end
254+
255+ # Creates a fake pmd script file as .../bin/pmd.
256+ # This is used in the new PMD 7 CLI interface
257+ def prepare_pmd_dist_dir ( version :, sha1 :)
258+ pmd_cli_cmd = "#{ Dir . getwd } /target/pmd-bin-#{ version } -master-#{ sha1 } /bin"
259+ FileUtils . mkdir_p ( pmd_cli_cmd )
260+ File . new ( "#{ pmd_cli_cmd } /pmd" , 'w' )
261+ pmd_cli_cmd
262+ end
263+
264+ def cleanup_pmd_dist_dir ( base_dir :)
265+ File . unlink ( "#{ base_dir } /pmd" )
266+ Dir . rmdir ( base_dir )
267+ end
247268end
0 commit comments