@@ -4,6 +4,7 @@ const nock = require('nock');
44const io = require ( '@actions/io' ) ;
55const os = require ( 'os' ) ;
66const fs = require ( 'fs' ) ;
7+ const exec = require ( '@actions/exec' ) ;
78const util = require ( '../lib/util' ) ;
89
910const cachePath = path . join ( __dirname , 'CACHE' )
@@ -13,19 +14,26 @@ process.env['RUNNER_TEMP'] = tempPath
1314process . env [ 'RUNNER_TOOL_CACHE' ] = cachePath
1415
1516describe ( 'pmd-github-action-util' , function ( ) {
17+ let platformMock ;
18+ let execMock ;
19+
1620 beforeAll ( function ( ) {
1721 setGlobal ( 'TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS' , 0 )
1822 setGlobal ( 'TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS' , 0 )
1923 } )
2024
2125 beforeEach ( async function ( ) {
26+ platformMock = jest . spyOn ( os , 'platform' ) ;
27+ execMock = jest . spyOn ( exec , 'getExecOutput' ) ;
2228 await io . rmRF ( cachePath )
2329 await io . rmRF ( tempPath )
2430 await io . mkdirP ( cachePath )
2531 await io . mkdirP ( tempPath )
2632 } )
2733
2834 afterEach ( function ( ) {
35+ platformMock . mockRestore ( ) ;
36+ execMock . mockRestore ( ) ;
2937 } )
3038
3139 afterAll ( async function ( ) {
@@ -86,6 +94,33 @@ describe('pmd-github-action-util', function() {
8694 expect ( report . runs [ 0 ] . tool . driver . version ) . toBe ( '6.40.0' ) ;
8795 await io . rmRF ( reportFile )
8896 } )
97+
98+ it ( 'can execute PMD win32' , async ( ) => {
99+ platformMock . mockReturnValueOnce ( 'win32' ) ;
100+ execMock . mockReturnValueOnce ( { exitCode : 0 , stdout : '' , stderr : '' } ) ;
101+ nock ( 'https://api.github.com' )
102+ . get ( '/repos/pmd/pmd/releases/latest' )
103+ . replyWithFile ( 200 , __dirname + '/data/releases-latest.json' , {
104+ 'Content-Type' : 'application/json' ,
105+ } )
106+ nock ( 'https://github.com' )
107+ . get ( '/pmd/pmd/releases/download/pmd_releases/6.40.0/pmd-bin-6.40.0.zip' )
108+ . replyWithFile ( 200 , __dirname + '/data/pmd-bin-6.40.0.zip' )
109+
110+ const cachedPmdPath = await util . downloadPmd ( 'latest' ) ;
111+ await util . executePmd ( cachedPmdPath , '.' , 'ruleset.xml' , 'sarif' , 'pmd-report.sarif' ) ;
112+
113+ expect ( execMock ) . toBeCalledWith ( `${ cachedPmdPath } \\bin\\pmd.bat` , [
114+ '-no-cache' ,
115+ '-d' , '.' ,
116+ '-f' , 'sarif' ,
117+ '-R' , 'ruleset.xml' ,
118+ '-r' , 'pmd-report.sarif' ,
119+ ] ,
120+ {
121+ ignoreReturnCode : true
122+ } ) ;
123+ } )
89124} ) ;
90125
91126function setGlobal ( key , value ) {
0 commit comments