2023-04-22 17:19:33 +08:00
|
|
|
import { execaSync } from "execa"
|
2022-02-15 15:10:02 +08:00
|
|
|
import { chmodSync } from "fs"
|
2024-04-03 15:15:43 +08:00
|
|
|
import { addExeExt, join } from "patha"
|
2022-11-21 09:51:40 +08:00
|
|
|
import { ubuntuVersion } from "../../utils/env/ubuntu_version"
|
2024-04-03 15:15:43 +08:00
|
|
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
|
|
|
import { getVersion } from "../../versions/versions"
|
|
|
|
import { setupGcc } from "../gcc"
|
2021-09-16 22:03:54 +08:00
|
|
|
|
2021-12-07 21:45:29 +08:00
|
|
|
jest.setTimeout(3000000)
|
2021-09-16 22:03:54 +08:00
|
|
|
describe("setup-gcc", () => {
|
2022-05-21 08:07:25 +08:00
|
|
|
let directory: string
|
|
|
|
beforeAll(async () => {
|
2022-05-21 08:52:48 +08:00
|
|
|
directory = await setupTmpDir("gcc")
|
2022-05-21 08:07:25 +08:00
|
|
|
})
|
|
|
|
|
2021-09-16 22:03:54 +08:00
|
|
|
it("should setup gcc", async () => {
|
2022-11-21 09:51:40 +08:00
|
|
|
const version = getVersion("gcc", undefined, await ubuntuVersion())
|
2022-05-21 08:07:25 +08:00
|
|
|
const installInfo = await setupGcc(version, directory, process.arch)
|
2021-09-16 22:03:54 +08:00
|
|
|
|
2021-09-17 07:15:25 +08:00
|
|
|
let gpp = "g++"
|
|
|
|
if (process.platform !== "win32") {
|
2021-09-17 07:21:11 +08:00
|
|
|
gpp = `g++-${version}`
|
2021-09-17 07:15:25 +08:00
|
|
|
}
|
|
|
|
await testBin(gpp, ["--version"], installInfo?.binDir)
|
2022-01-30 04:47:02 +08:00
|
|
|
|
|
|
|
expect(process.env.CC?.includes("gcc")).toBeTruthy()
|
|
|
|
expect(process.env.CXX?.includes("g++")).toBeTruthy()
|
2022-02-15 15:10:02 +08:00
|
|
|
|
|
|
|
// test compilation
|
2022-08-21 06:38:51 +08:00
|
|
|
const file = join(__dirname, "main.cpp")
|
|
|
|
const main_exe = join(__dirname, addExeExt("main"))
|
2023-04-22 17:19:33 +08:00
|
|
|
execaSync("g++", [file, "-o", main_exe], { cwd: __dirname })
|
2022-02-15 15:10:02 +08:00
|
|
|
if (process.platform !== "win32") {
|
|
|
|
chmodSync(main_exe, "755")
|
|
|
|
}
|
2023-04-22 17:19:33 +08:00
|
|
|
execaSync(main_exe, { cwd: __dirname, stdio: "inherit" })
|
2021-09-16 22:03:54 +08:00
|
|
|
})
|
2022-05-21 08:07:25 +08:00
|
|
|
|
|
|
|
afterAll(async () => {
|
2022-05-21 08:52:48 +08:00
|
|
|
await cleanupTmpDir("gcc")
|
2022-05-21 08:07:25 +08:00
|
|
|
}, 100000)
|
2021-09-16 22:03:54 +08:00
|
|
|
})
|