Skip to content

Commit

Permalink
test: test compilation in the llvm and gcc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 15, 2022
1 parent 9700bb5 commit 9770308
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/gcc/__tests__/gcc.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { testBin } from "../../utils/tests/test-helpers"
import { setupGcc } from "../gcc"
import { getVersion } from "../../default_versions"
import path from "path"
import execa from "execa"
import { addBinExtension } from "../../utils/extension/extension"
import { chmodSync } from "fs"

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

expect(process.env.CC?.includes("gcc")).toBeTruthy()
expect(process.env.CXX?.includes("g++")).toBeTruthy()

// test compilation
const file = path.join(__dirname, "main.cpp")
const main_exe = path.join(__dirname, addBinExtension("main"))
execa.sync("g++", [file, "-o", main_exe], { cwd: __dirname })
if (process.platform !== "win32") {
chmodSync(main_exe, "755")
}
execa.sync(main_exe, { cwd: __dirname, stdio: "inherit" })
})
})
18 changes: 18 additions & 0 deletions src/gcc/__tests__/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// test std libraries
#include <iostream>
#include <string>

// test c libraries
#include <cassert>
#include <cctype>
#include <cstddef>
#include <cstdint>
#include <cstring>

int main() {
const auto x = 10.0;
std::cout << "Testing " << x << '\n';

const auto y = std::to_string(x);
std::cout << "Testing " << y << '\n';
}
20 changes: 17 additions & 3 deletions src/llvm/__tests__/llvm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { getSpecificVersionAndUrl } from "../../utils/setup/version"
import { isValidUrl } from "../../utils/http/validate_url"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci"
import execa from "execa"
import path from "path"
import { addBinExtension } from "../../utils/extension/extension"
import { chmodSync } from "fs"

jest.setTimeout(400000)
async function testUrl(version: string) {
Expand All @@ -22,6 +26,7 @@ describe("setup-llvm", () => {
it("Finds valid LLVM URLs", async () => {
await Promise.all(
[
"13.0.0",
"12.0.0",
"12",
"11",
Expand All @@ -43,15 +48,24 @@ describe("setup-llvm", () => {
})

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

expect(process.env.CC?.includes("clang")).toBeTruthy()
expect(process.env.CXX?.includes("clang++")).toBeTruthy()

// test compilation
const file = path.join(__dirname, "main.cpp")
const main_exe = path.join(__dirname, addBinExtension("main"))
execa.sync("clang++", [file, "-o", main_exe], { cwd: __dirname })
if (process.platform !== "win32") {
chmodSync(main_exe, "755")
}
execa.sync(main_exe, { cwd: __dirname, stdio: "inherit" })
})

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

if (isGitHubCI()) {
Expand All @@ -68,7 +82,7 @@ describe("setup-llvm", () => {
})

it("should setup clang-tidy and clang-format", async () => {
const { binDir } = await setupClangTools("11.0.0", directory, process.arch)
const { binDir } = await setupClangTools("13.0.0", directory, process.arch)
await testBin("clang-tidy", ["--version"], binDir)
await testBin("clang-format", ["--version"], binDir)
})
Expand Down
18 changes: 18 additions & 0 deletions src/llvm/__tests__/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// test std libraries
#include <iostream>
#include <string>

// test c libraries
#include <cassert>
#include <cctype>
#include <cstddef>
#include <cstdint>
#include <cstring>

int main() {
const auto x = 10.0;
std::cout << "Testing " << x << '\n';

const auto y = std::to_string(x);
std::cout << "Testing " << y << '\n';
}

0 comments on commit 9770308

Please sign in to comment.