From 596c9438b57957e84c1fe56d7250c90f366e223f Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 16 Sep 2021 10:15:43 -0500 Subject: [PATCH] test: use testBin in all the tests --- src/brew/__tests__/brew.test.ts | 10 +++------- src/ccache/__tests__/ccache.test.ts | 7 ++----- src/chocolatey/__tests__/chocolatey.test.ts | 8 ++------ src/conan/__tests__/conan.test.ts | 7 ++----- src/cppcheck/__tests__/cppcheck.test.ts | 7 ++----- src/doxygen/__tests__/doxygen.test.ts | 7 ++----- src/gcc/__tests__/gcc.test.ts | 7 ++----- src/gcovr/__tests__/gcovr.test.ts | 7 ++----- src/llvm/__tests__/llvm.test.ts | 18 ++---------------- src/meson/__tests__/meson.test.ts | 8 ++------ src/msvc/__tests__/msvc.test.ts | 12 ++++++------ .../__tests__/opencppcoverage.test.ts | 7 ++----- 12 files changed, 29 insertions(+), 76 deletions(-) diff --git a/src/brew/__tests__/brew.test.ts b/src/brew/__tests__/brew.test.ts index 651513a1..23aeffb1 100644 --- a/src/brew/__tests__/brew.test.ts +++ b/src/brew/__tests__/brew.test.ts @@ -1,5 +1,5 @@ import { setupBrew } from "../brew" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-brew", () => { @@ -7,11 +7,7 @@ describe("setup-brew", () => { if (process.platform !== "darwin") { return } - await setupBrew("", "", "") - - const { status } = spawn("brew", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + setupBrew("", "", "") + await testBin("brew") }) }) diff --git a/src/ccache/__tests__/ccache.test.ts b/src/ccache/__tests__/ccache.test.ts index 7f8982f0..bdf4fcd7 100644 --- a/src/ccache/__tests__/ccache.test.ts +++ b/src/ccache/__tests__/ccache.test.ts @@ -1,14 +1,11 @@ import { setupCcache } from "../ccache" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-ccache", () => { it("should setup ccache", async () => { await setupCcache("", "", "") - const { status } = spawn("ccache", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("ccache") }) }) diff --git a/src/chocolatey/__tests__/chocolatey.test.ts b/src/chocolatey/__tests__/chocolatey.test.ts index 0846da17..387dbd58 100644 --- a/src/chocolatey/__tests__/chocolatey.test.ts +++ b/src/chocolatey/__tests__/chocolatey.test.ts @@ -1,5 +1,5 @@ +import { testBin } from "../../utils/tests/test-helpers" import { setupChocolatey } from "../chocolatey" -import { spawnSync as spawn } from "child_process" jest.setTimeout(200000) describe("setup-chocolatey", () => { @@ -8,10 +8,6 @@ describe("setup-chocolatey", () => { return } await setupChocolatey("", "", "") - - const { status } = spawn("choco", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("choco") }) }) diff --git a/src/conan/__tests__/conan.test.ts b/src/conan/__tests__/conan.test.ts index bec97b94..3b6c9cf4 100644 --- a/src/conan/__tests__/conan.test.ts +++ b/src/conan/__tests__/conan.test.ts @@ -1,14 +1,11 @@ import { setupConan } from "../conan" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-conan", () => { it("should setup conan", async () => { await setupConan("1.40.1", "", "") - const { status } = spawn("conan", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("conan") }) }) diff --git a/src/cppcheck/__tests__/cppcheck.test.ts b/src/cppcheck/__tests__/cppcheck.test.ts index 0bfeedd6..0c6c7bf4 100644 --- a/src/cppcheck/__tests__/cppcheck.test.ts +++ b/src/cppcheck/__tests__/cppcheck.test.ts @@ -1,14 +1,11 @@ import { setupCppcheck } from "../cppcheck" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-cppcheck", () => { it("should setup cppcheck", async () => { await setupCppcheck("", "", "") - const { status } = spawn("cppcheck", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("cppcheck") }) }) diff --git a/src/doxygen/__tests__/doxygen.test.ts b/src/doxygen/__tests__/doxygen.test.ts index 5fc399cb..4b1c31f2 100644 --- a/src/doxygen/__tests__/doxygen.test.ts +++ b/src/doxygen/__tests__/doxygen.test.ts @@ -1,14 +1,11 @@ import { setupDoxygen } from "../doxygen" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-doxygen", () => { it("should setup doxygen", async () => { await setupDoxygen("", "", "") - const { status } = spawn("doxygen", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("doxygen") }) }) diff --git a/src/gcc/__tests__/gcc.test.ts b/src/gcc/__tests__/gcc.test.ts index 17b778b7..86ae497a 100644 --- a/src/gcc/__tests__/gcc.test.ts +++ b/src/gcc/__tests__/gcc.test.ts @@ -1,4 +1,4 @@ -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" import { setupGcc } from "../gcc" jest.setTimeout(200000) @@ -6,9 +6,6 @@ describe("setup-gcc", () => { it("should setup gcc", async () => { await setupGcc("", "", "") - const { status } = spawn("g++", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("g++") }) }) diff --git a/src/gcovr/__tests__/gcovr.test.ts b/src/gcovr/__tests__/gcovr.test.ts index c6a18f26..8df1f449 100644 --- a/src/gcovr/__tests__/gcovr.test.ts +++ b/src/gcovr/__tests__/gcovr.test.ts @@ -1,14 +1,11 @@ import { setupGcovr } from "../gcovr" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-gcovr", () => { it("should setup gcovr", async () => { await setupGcovr("5.0", "", "") - const { status } = spawn("gcovr", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("gcovr") }) }) diff --git a/src/llvm/__tests__/llvm.test.ts b/src/llvm/__tests__/llvm.test.ts index b80dc10d..1e8d56a1 100644 --- a/src/llvm/__tests__/llvm.test.ts +++ b/src/llvm/__tests__/llvm.test.ts @@ -1,11 +1,7 @@ import { setupLLVM, VERSIONS, getUrl } from "../llvm" import { getSpecificVersionAndUrl } from "../../utils/setup/version" import { isValidUrl } from "../../utils/http/validate_url" -import { setupTmpDir, cleanupTmpDir } from "../../utils/tests/test-helpers" -import { addBinExtension } from "../../utils/setup/setupBin" -import { join } from "path" -import { spawnSync as spawn } from "child_process" -import { which } from "@actions/io" +import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) async function testUrl(version: string) { @@ -47,17 +43,7 @@ describe("setup-llvm", () => { it("should setup LLVM", async () => { const { binDir } = await setupLLVM("11.0.0", directory, "") - expect(binDir).toBeDefined() - expect(binDir).not.toHaveLength(0) - - const clangBin = join(binDir, addBinExtension("clang")) - - const { status } = spawn(clangBin, ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) - - expect(await which("clang", true)).toBe(clangBin) + await testBin("clang++", ["--version"], binDir) }) afterAll(async () => { diff --git a/src/meson/__tests__/meson.test.ts b/src/meson/__tests__/meson.test.ts index b4bc9c04..35ce8d6e 100644 --- a/src/meson/__tests__/meson.test.ts +++ b/src/meson/__tests__/meson.test.ts @@ -1,14 +1,10 @@ import { setupMeson } from "../meson" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-meson", () => { it("should setup meson", async () => { await setupMeson("0.59.1", "", "") - - const { status } = spawn("meson", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("meson") }) }) diff --git a/src/msvc/__tests__/msvc.test.ts b/src/msvc/__tests__/msvc.test.ts index 02825427..4239fc5e 100644 --- a/src/msvc/__tests__/msvc.test.ts +++ b/src/msvc/__tests__/msvc.test.ts @@ -1,5 +1,5 @@ +import { testBin } from "../../utils/tests/test-helpers" import { setupMSVC } from "../msvc" -import { spawnSync as spawn } from "child_process" jest.setTimeout(200000) describe("setup-msvc", () => { @@ -9,10 +9,10 @@ describe("setup-msvc", () => { } await setupMSVC("2019", "", "") - spawn("cl", { - encoding: "utf8", - }) - // TODO see #1 - // expect(status).toBe(0) + try { + await testBin("cl", []) + } catch (err) { + // TODO see #1 + } }) }) diff --git a/src/opencppcoverage/__tests__/opencppcoverage.test.ts b/src/opencppcoverage/__tests__/opencppcoverage.test.ts index 42a1065e..3a561049 100644 --- a/src/opencppcoverage/__tests__/opencppcoverage.test.ts +++ b/src/opencppcoverage/__tests__/opencppcoverage.test.ts @@ -1,5 +1,5 @@ import { setupOpencppcoverage } from "../opencppcoverage" -import { spawnSync as spawn } from "child_process" +import { testBin } from "../../utils/tests/test-helpers" jest.setTimeout(200000) describe("setup-OpenCppCoverage", () => { @@ -9,9 +9,6 @@ describe("setup-OpenCppCoverage", () => { } await setupOpencppcoverage("", "", "") - const { status } = spawn("OpenCppCoverage", ["--version"], { - encoding: "utf8", - }) - expect(status).toBe(0) + await testBin("OpenCppCoverage") }) })