feat: add which test to testBin

This commit is contained in:
Amin Yahyaabadi 2021-09-16 10:07:14 -05:00
parent dc5ab1bf50
commit dde8036194
3 changed files with 12 additions and 8 deletions

View File

@ -4,7 +4,7 @@ import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-help
jest.setTimeout(200000) jest.setTimeout(200000)
async function testCmake(directory: string) { async function testCmake(directory: string) {
const { binDir } = await setupCmake("3.20.2", directory, "") const { binDir } = await setupCmake("3.20.2", directory, "")
testBin("cmake", binDir) await testBin("cmake", ["--version"], binDir)
return binDir return binDir
} }

View File

@ -4,7 +4,7 @@ import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-help
jest.setTimeout(200000) jest.setTimeout(200000)
async function testNinja(directory: string) { async function testNinja(directory: string) {
const { binDir } = await setupNinja("1.10.2", directory, "") const { binDir } = await setupNinja("1.10.2", directory, "")
testBin("ninja", binDir) await testBin("ninja", ["--version"], binDir)
return binDir return binDir
} }

View File

@ -33,16 +33,20 @@ export async function cleanupTmpDir(testName: string) {
} }
} }
export function testBin(binName: string, binDir: string) { export async function testBin(name: string, args: string[] = ["--version"], binDir: string | undefined = undefined) {
let bin = name
if (binDir !== undefined) {
expect(binDir).toBeDefined() expect(binDir).toBeDefined()
expect(binDir).not.toHaveLength(0) expect(binDir).not.toHaveLength(0)
bin = join(binDir, addBinExtension(name))
}
const cmakeBin = join(binDir, addBinExtension(binName)) const { status } = spawn(bin, args, {
const { status } = spawn(cmakeBin, ["--version"], {
encoding: "utf8", encoding: "utf8",
}) })
expect(status).toBe(0) expect(status).toBe(0)
expect(await io.which(name, true)).toBe(bin)
return binDir return binDir
} }