Skip to content

Commit 9770308

Browse files
committed
test: test compilation in the llvm and gcc tests
1 parent 9700bb5 commit 9770308

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

src/gcc/__tests__/gcc.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { testBin } from "../../utils/tests/test-helpers"
22
import { setupGcc } from "../gcc"
33
import { getVersion } from "../../default_versions"
4+
import path from "path"
5+
import execa from "execa"
6+
import { addBinExtension } from "../../utils/extension/extension"
7+
import { chmodSync } from "fs"
48

59
jest.setTimeout(3000000)
610
describe("setup-gcc", () => {
@@ -16,5 +20,14 @@ describe("setup-gcc", () => {
1620

1721
expect(process.env.CC?.includes("gcc")).toBeTruthy()
1822
expect(process.env.CXX?.includes("g++")).toBeTruthy()
23+
24+
// test compilation
25+
const file = path.join(__dirname, "main.cpp")
26+
const main_exe = path.join(__dirname, addBinExtension("main"))
27+
execa.sync("g++", [file, "-o", main_exe], { cwd: __dirname })
28+
if (process.platform !== "win32") {
29+
chmodSync(main_exe, "755")
30+
}
31+
execa.sync(main_exe, { cwd: __dirname, stdio: "inherit" })
1932
})
2033
})

src/gcc/__tests__/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// test std libraries
2+
#include <iostream>
3+
#include <string>
4+
5+
// test c libraries
6+
#include <cassert>
7+
#include <cctype>
8+
#include <cstddef>
9+
#include <cstdint>
10+
#include <cstring>
11+
12+
int main() {
13+
const auto x = 10.0;
14+
std::cout << "Testing " << x << '\n';
15+
16+
const auto y = std::to_string(x);
17+
std::cout << "Testing " << y << '\n';
18+
}

src/llvm/__tests__/llvm.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { getSpecificVersionAndUrl } from "../../utils/setup/version"
33
import { isValidUrl } from "../../utils/http/validate_url"
44
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
55
import { isGitHubCI } from "../../utils/env/isci"
6+
import execa from "execa"
7+
import path from "path"
8+
import { addBinExtension } from "../../utils/extension/extension"
9+
import { chmodSync } from "fs"
610

711
jest.setTimeout(400000)
812
async function testUrl(version: string) {
@@ -22,6 +26,7 @@ describe("setup-llvm", () => {
2226
it("Finds valid LLVM URLs", async () => {
2327
await Promise.all(
2428
[
29+
"13.0.0",
2530
"12.0.0",
2631
"12",
2732
"11",
@@ -43,15 +48,24 @@ describe("setup-llvm", () => {
4348
})
4449

4550
it("should setup LLVM", async () => {
46-
const { binDir } = await setupLLVM("11.0.0", directory, process.arch)
51+
const { binDir } = await setupLLVM("13.0.0", directory, process.arch)
4752
await testBin("clang++", ["--version"], binDir)
4853

4954
expect(process.env.CC?.includes("clang")).toBeTruthy()
5055
expect(process.env.CXX?.includes("clang++")).toBeTruthy()
56+
57+
// test compilation
58+
const file = path.join(__dirname, "main.cpp")
59+
const main_exe = path.join(__dirname, addBinExtension("main"))
60+
execa.sync("clang++", [file, "-o", main_exe], { cwd: __dirname })
61+
if (process.platform !== "win32") {
62+
chmodSync(main_exe, "755")
63+
}
64+
execa.sync(main_exe, { cwd: __dirname, stdio: "inherit" })
5165
})
5266

5367
it("should find llvm in the cache", async () => {
54-
const { binDir } = await setupLLVM("11.0.0", directory, process.arch)
68+
const { binDir } = await setupLLVM("13.0.0", directory, process.arch)
5569
await testBin("clang++", ["--version"], binDir)
5670

5771
if (isGitHubCI()) {
@@ -68,7 +82,7 @@ describe("setup-llvm", () => {
6882
})
6983

7084
it("should setup clang-tidy and clang-format", async () => {
71-
const { binDir } = await setupClangTools("11.0.0", directory, process.arch)
85+
const { binDir } = await setupClangTools("13.0.0", directory, process.arch)
7286
await testBin("clang-tidy", ["--version"], binDir)
7387
await testBin("clang-format", ["--version"], binDir)
7488
})

src/llvm/__tests__/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// test std libraries
2+
#include <iostream>
3+
#include <string>
4+
5+
// test c libraries
6+
#include <cassert>
7+
#include <cctype>
8+
#include <cstddef>
9+
#include <cstdint>
10+
#include <cstring>
11+
12+
int main() {
13+
const auto x = 10.0;
14+
std::cout << "Testing " << x << '\n';
15+
16+
const auto y = std::to_string(x);
17+
std::cout << "Testing " << y << '\n';
18+
}

0 commit comments

Comments
 (0)