2022-11-03 11:01:42 +08:00
|
|
|
import { syncVersions, getVersion } from "../versions/versions"
|
2023-08-22 12:41:17 +08:00
|
|
|
import { parseArgs } from "../cli-options"
|
2023-05-25 14:48:26 +08:00
|
|
|
import { getCompilerInfo } from "../compilers"
|
2023-08-22 12:41:17 +08:00
|
|
|
import { Inputs } from "../tool"
|
2023-09-01 18:52:13 +08:00
|
|
|
import { DefaultLinuxVersion } from "../versions/default_versions"
|
2021-11-22 06:40:30 +08:00
|
|
|
|
|
|
|
jest.setTimeout(300000)
|
|
|
|
describe("getCompilerInfo", () => {
|
|
|
|
it("version will be undefined if not provided", () => {
|
|
|
|
const { compiler, version } = getCompilerInfo("llvm")
|
|
|
|
expect(compiler).toBe("llvm")
|
|
|
|
expect(version).toBeUndefined()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("extracts version", () => {
|
|
|
|
const { compiler, version } = getCompilerInfo("llvm-12.0.0")
|
|
|
|
expect(compiler).toBe("llvm")
|
|
|
|
expect(version).toBe("12.0.0")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("finds a version even if not semver", () => {
|
|
|
|
const { compiler, version } = getCompilerInfo("llvm-12")
|
|
|
|
expect(compiler).toBe("llvm")
|
|
|
|
expect(version).toBe("12")
|
|
|
|
})
|
|
|
|
})
|
2022-05-06 09:37:44 +08:00
|
|
|
|
|
|
|
describe("syncVersion", () => {
|
2022-05-13 03:55:00 +08:00
|
|
|
it("Syncs llvm tools versions", () => {
|
2022-05-06 09:37:44 +08:00
|
|
|
const llvmTools = ["llvm", "clangtidy", "clangformat"] as Inputs[]
|
|
|
|
expect(syncVersions(parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)
|
|
|
|
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "true"]), llvmTools)).toBe(true)
|
|
|
|
expect(syncVersions(parseArgs(["--llvm", "13.0.0", "--clangtidy", "12.0.0"]), llvmTools)).toBe(false)
|
|
|
|
|
2023-01-18 03:39:39 +08:00
|
|
|
const opts1 = parseArgs(["--llvm", "14.0.0", "--clangtidy", "true"])
|
|
|
|
expect(syncVersions(opts1, llvmTools)).toBe(true)
|
|
|
|
expect(opts1.llvm).toBe(opts1.clangtidy)
|
|
|
|
expect(opts1.clangformat).toBe(undefined)
|
|
|
|
|
|
|
|
const opts2 = parseArgs(["--clangtidy", "15.0.0", "--clangformat", "true"])
|
|
|
|
expect(syncVersions(opts2, llvmTools)).toBe(true)
|
|
|
|
expect(opts2.llvm).toBe(undefined)
|
|
|
|
expect(opts2.clangtidy).toBe("15.0.0")
|
|
|
|
expect(opts2.clangformat).toBe("15.0.0")
|
|
|
|
|
|
|
|
const opts3 = parseArgs(["--llvm", "true", "--clangformat", "true"])
|
|
|
|
expect(syncVersions(opts3, llvmTools)).toBe(true)
|
|
|
|
expect(opts3.llvm).toBe("true")
|
|
|
|
expect(opts3.clangtidy).toBe(undefined)
|
|
|
|
expect(opts3.clangformat).toBe("true")
|
2022-05-06 09:37:44 +08:00
|
|
|
})
|
2022-05-21 10:28:05 +08:00
|
|
|
})
|
2022-05-21 10:16:58 +08:00
|
|
|
|
2022-05-21 10:28:05 +08:00
|
|
|
describe("getVersion", () => {
|
|
|
|
it("gcovr", () => {
|
|
|
|
expect(getVersion("gcovr", "5.0")).toBe("5.0")
|
|
|
|
if (process.platform === "linux") {
|
2023-09-05 10:25:56 +08:00
|
|
|
expect(getVersion("gcovr", "true", [22, 4])).toBe(DefaultLinuxVersion.gcovr![22])
|
|
|
|
expect(getVersion("gcovr", "true", [20, 4])).toBe(DefaultLinuxVersion.gcovr![20])
|
|
|
|
expect(getVersion("gcovr", "true", [18, 4])).toBe(DefaultLinuxVersion.gcovr![18])
|
2022-05-21 10:28:05 +08:00
|
|
|
}
|
|
|
|
})
|
2022-05-21 10:16:58 +08:00
|
|
|
|
2022-05-21 10:28:05 +08:00
|
|
|
it("llvm", () => {
|
|
|
|
expect(getVersion("llvm", "13.0.0")).toBe("13.0.0")
|
|
|
|
if (process.platform === "linux") {
|
2023-09-05 10:25:56 +08:00
|
|
|
expect(getVersion("llvm", "true", [20, 4])).toBe(DefaultLinuxVersion.llvm![20])
|
|
|
|
expect(getVersion("llvm", "true", [18, 4])).toBe(DefaultLinuxVersion.llvm![18])
|
|
|
|
expect(getVersion("llvm", "true", [16, 4])).toBe(DefaultLinuxVersion.llvm![16])
|
2022-05-21 10:28:05 +08:00
|
|
|
}
|
2022-05-21 10:16:58 +08:00
|
|
|
})
|
2022-05-06 09:37:44 +08:00
|
|
|
})
|