test: test compilation in the llvm and gcc tests

This commit is contained in:
Amin Yahyaabadi 2022-02-14 23:10:02 -08:00
parent 9700bb5f87
commit 9770308530
4 changed files with 66 additions and 3 deletions

View File

@ -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", () => {
@ -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" })
})
})

View File

@ -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';
}

View File

@ -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) {
@ -22,6 +26,7 @@ describe("setup-llvm", () => {
it("Finds valid LLVM URLs", async () => {
await Promise.all(
[
"13.0.0",
"12.0.0",
"12",
"11",
@ -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()) {
@ -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)
})

View File

@ -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';
}