From d0788d01cf80faa4a5b185ae37308f78ea8e07a6 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 3 Dec 2019 14:18:54 -0500 Subject: [PATCH] Unit test (#236) --- __tests__/exec.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/__tests__/exec.test.ts b/__tests__/exec.test.ts index 6f9811c..a4fbc23 100644 --- a/__tests__/exec.test.ts +++ b/__tests__/exec.test.ts @@ -575,6 +575,36 @@ describe('@actions/exec', () => { }) if (IS_WINDOWS) { + it('Exec roots relative tool path using process.cwd (Windows path separator)', async () => { + let exitCode: number + const command = 'scripts\\print-args-cmd' // let ToolRunner resolve the extension + const execOptions = getExecOptions() + const outStream = new StringStream() + execOptions.outStream = outStream + let output = '' + execOptions.listeners = { + stdout: (data: Buffer) => { + output += data.toString() + } + } + + const originalCwd = process.cwd() + try { + process.chdir(__dirname) + exitCode = await exec.exec(`${command} hello world`, [], execOptions) + } catch (err) { + process.chdir(originalCwd) + throw err + } + + expect(exitCode).toBe(0) + const toolPath = path.resolve(__dirname, `${command}.cmd`) + expect(outStream.getContents().split(os.EOL)[0]).toBe( + `[command]${process.env.ComSpec} /D /S /C "${toolPath} hello world"` + ) + expect(output.trim()).toBe(`args[0]: "hello"${os.EOL}args[1]: "world"`) + }) + // Win specific quoting tests it('execs .exe with verbatim args (Windows)', async () => { const exePath = process.env.ComSpec