Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not artificially restrict the set of supported languages #779

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/analyze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { runQueries } from "./analyze";
import { setCodeQL } from "./codeql";
import { Config } from "./config-utils";
import * as count from "./count-loc";
import { Language } from "./languages";
import { KnownLanguage } from "./languages";
import { getRunnerLogger } from "./logging";
import { setupTests, setupActionsVars } from "./testing-utils";
import * as util from "./util";
Expand All @@ -21,8 +21,8 @@ setupTests(test);
// and correct case of builtin or custom. Also checks the correct search
// paths are set in the database analyze invocation.
test("status report fields and search path setting", async (t) => {
const mockLinesOfCode = Object.values(Language).reduce((obj, lang, i) => {
// use a different line count for each language
const mockLinesOfCode = Object.values(KnownLanguage).reduce((obj, lang, i) => {
// use a different line count for each KnownLanguage
obj[lang] = i + 1;
return obj;
}, {});
Expand All @@ -35,21 +35,21 @@ test("status report fields and search path setting", async (t) => {
const addSnippetsFlag = "";
const threadsFlag = "";
const packs = {
[Language.cpp]: [
[KnownLanguage.cpp]: [
{
packName: "a/b",
version: clean("1.0.0")!,
},
],
[Language.java]: [
[KnownLanguage.java]: [
{
packName: "c/d",
version: clean("2.0.0")!,
},
],
};

for (const language of Object.values(Language)) {
for (const language of Object.values(KnownLanguage)) {
setCodeQL({
packDownload: async () => ({ packs: [] }),
databaseRunQueries: async (
Expand Down Expand Up @@ -203,7 +203,7 @@ test("status report fields and search path setting", async (t) => {

function verifyLineCounts(tmpDir: string) {
// eslint-disable-next-line github/array-foreach
Object.keys(Language).forEach((lang, i) => {
Object.keys(KnownLanguage).forEach((lang, i) => {
verifyLineCountForFile(path.join(tmpDir, `${lang}.sarif`), i + 1);
});
}
Expand Down Expand Up @@ -249,14 +249,14 @@ test("status report fields and search path setting", async (t) => {
version: "2.0.0",
},
];
for (const lang of Object.values(Language)) {
for (const lang of Object.values(KnownLanguage)) {
t.deepEqual(readContents(`${lang}-queries-builtin.qls`), qlsContent);
t.deepEqual(readContents(`${lang}-queries-custom-0.qls`), qlsContent);
t.deepEqual(readContents(`${lang}-queries-custom-1.qls`), qlsContent2);
const packSuiteName = `${lang}-queries-packs.qls`;
if (lang === Language.cpp) {
if (lang === KnownLanguage.cpp) {
t.deepEqual(readContents(packSuiteName), qlsPackContentCpp);
} else if (lang === Language.java) {
} else if (lang === KnownLanguage.java) {
t.deepEqual(readContents(packSuiteName), qlsPackContentJava);
} else {
t.false(
Expand Down
4 changes: 2 additions & 2 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as analysisPaths from "./analysis-paths";
import { CODEQL_VERSION_COUNTS_LINES, getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { countLoc } from "./count-loc";
import { isScannedLanguage, Language } from "./languages";
import { isScannedLanguage, KnownLanguage, Language } from "./languages";
import { Logger } from "./logging";
import * as sharedEnv from "./shared-environment";
import * as util from "./util";
Expand Down Expand Up @@ -124,7 +124,7 @@ async function createdDBForScannedLanguages(
) {
logger.startGroup(`Extracting ${language}`);

if (language === Language.python) {
if (language === KnownLanguage.python) {
await setupPythonExtractor(logger);
}

Expand Down
74 changes: 37 additions & 37 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as sinon from "sinon";
import * as api from "./api-client";
import { getCachedCodeQL, setCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { Language } from "./languages";
import { KnownLanguage, Language } from "./languages";
import { getRunnerLogger } from "./logging";
import { setupTests } from "./testing-utils";
import * as util from "./util";
Expand Down Expand Up @@ -299,7 +299,7 @@ test("load non-empty input", async (t) => {

// And the config we expect it to parse to
const expectedConfig: configUtils.Config = {
languages: [Language.javascript],
languages: [KnownLanguage.javascript],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have a new unit test here for a language is not a known language, but it is valid since it was returned by a mocked call to codeql resolve languages.

queries: {
javascript: {
builtin: [],
Expand Down Expand Up @@ -998,7 +998,7 @@ test("Unknown languages", async (t) => {
} catch (err) {
t.deepEqual(
err,
new Error(configUtils.getUnknownLanguagesError(["rubbish", "english"]))
new Error(configUtils.getUnsupportedLanguagesError(["rubbish", "english"]))
);
}
});
Expand Down Expand Up @@ -1044,7 +1044,7 @@ test("Config specifies packages", async (t) => {
getRunnerLogger(true)
);
t.deepEqual(packs as unknown, {
[Language.javascript]: [
[KnownLanguage.javascript]: [
{
packName: "a/b",
version: clean("1.2.3"),
Expand Down Expand Up @@ -1102,13 +1102,13 @@ test("Config specifies packages for multiple languages", async (t) => {
getRunnerLogger(true)
);
t.deepEqual(packs as unknown, {
[Language.javascript]: [
[KnownLanguage.javascript]: [
{
packName: "a/b",
version: clean("1.2.3"),
},
],
[Language.python]: [
[KnownLanguage.python]: [
{
packName: "c/d",
version: clean("1.2.3"),
Expand Down Expand Up @@ -1377,8 +1377,8 @@ parsePacksErrorMacro.title = (providedTitle: string) =>
function invalidPackNameMacro(t: ExecutionContext<unknown>, name: string) {
parsePacksErrorMacro(
t,
{ [Language.cpp]: [name] },
[Language.cpp],
{ [KnownLanguage.cpp]: [name] },
[KnownLanguage.cpp],
new RegExp(
`The configuration file "/a/b" is invalid: property "packs" "${name}" is not a valid pack`
)
Expand All @@ -1388,8 +1388,8 @@ invalidPackNameMacro.title = (_: string, arg: string) =>
`Invalid pack string: ${arg}`;

test("no packs", parsePacksMacro, {}, [], {});
test("two packs", parsePacksMacro, ["a/b", "c/[email protected]"], [Language.cpp], {
[Language.cpp]: [
test("two packs", parsePacksMacro, ["a/b", "c/[email protected]"], [KnownLanguage.cpp], {
[KnownLanguage.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: clean("1.2.3") },
],
Expand All @@ -1398,9 +1398,9 @@ test(
"two packs with spaces",
parsePacksMacro,
[" a/b ", " c/[email protected] "],
[Language.cpp],
[KnownLanguage.cpp],
{
[Language.cpp]: [
[KnownLanguage.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: clean("1.2.3") },
],
Expand All @@ -1410,16 +1410,16 @@ test(
"two packs with language",
parsePacksMacro,
{
[Language.cpp]: ["a/b", "c/[email protected]"],
[Language.java]: ["d/e", "f/[email protected]"],
[KnownLanguage.cpp]: ["a/b", "c/[email protected]"],
[KnownLanguage.java]: ["d/e", "f/[email protected]"],
},
[Language.cpp, Language.java, Language.csharp],
[KnownLanguage.cpp, KnownLanguage.java, KnownLanguage.csharp],
{
[Language.cpp]: [
[KnownLanguage.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: clean("1.2.3") },
],
[Language.java]: [
[KnownLanguage.java]: [
{ packName: "d/e", version: undefined },
{ packName: "f/g", version: clean("1.2.3") },
],
Expand All @@ -1430,21 +1430,21 @@ test(
"no language",
parsePacksErrorMacro,
["a/[email protected]"],
[Language.java, Language.python],
[KnownLanguage.java, KnownLanguage.python],
/The configuration file "\/a\/b" is invalid: property "packs" must split packages by language/
);
test(
"invalid language",
parsePacksErrorMacro,
{ [Language.java]: ["c/d"] },
[Language.cpp],
{ [KnownLanguage.java]: ["c/d"] },
[KnownLanguage.cpp],
/The configuration file "\/a\/b" is invalid: property "packs" has "java", but it is not one of the languages to analyze/
);
test(
"not an array",
parsePacksErrorMacro,
{ [Language.cpp]: "c/d" },
[Language.cpp],
{ [KnownLanguage.cpp]: "c/d" },
[KnownLanguage.cpp],
/The configuration file "\/a\/b" is invalid: property "packs" must be an array of non-empty strings/
);

Expand Down Expand Up @@ -1496,18 +1496,18 @@ function parseInputAndConfigErrorMacro(
parseInputAndConfigErrorMacro.title = (providedTitle: string) =>
`Parse Packs input and config Error: ${providedTitle}`;

test("input only", parseInputAndConfigMacro, {}, " c/d ", [Language.cpp], {
[Language.cpp]: [{ packName: "c/d", version: undefined }],
test("input only", parseInputAndConfigMacro, {}, " c/d ", [KnownLanguage.cpp], {
[KnownLanguage.cpp]: [{ packName: "c/d", version: undefined }],
});

test(
"input only with multiple",
parseInputAndConfigMacro,
{},
"a/b , c/[email protected]",
[Language.cpp],
[KnownLanguage.cpp],
{
[Language.cpp]: [
[KnownLanguage.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: "1.2.3" },
],
Expand All @@ -1519,9 +1519,9 @@ test(
parseInputAndConfigMacro,
{},
" + a/b , c/[email protected] ",
[Language.cpp],
[KnownLanguage.cpp],
{
[Language.cpp]: [
[KnownLanguage.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: "1.2.3" },
],
Expand All @@ -1533,9 +1533,9 @@ test(
parseInputAndConfigMacro,
["a/b", "c/d"],
" ",
[Language.cpp],
[KnownLanguage.cpp],
{
[Language.cpp]: [
[KnownLanguage.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: undefined },
],
Expand All @@ -1547,9 +1547,9 @@ test(
parseInputAndConfigMacro,
["a/b", "c/d"],
" e/f, g/[email protected] ",
[Language.cpp],
[KnownLanguage.cpp],
{
[Language.cpp]: [
[KnownLanguage.cpp]: [
{ packName: "e/f", version: undefined },
{ packName: "g/h", version: "1.2.3" },
],
Expand All @@ -1561,9 +1561,9 @@ test(
parseInputAndConfigMacro,
["a/b", "c/d"],
" +e/f, g/[email protected] ",
[Language.cpp],
[KnownLanguage.cpp],
{
[Language.cpp]: [
[KnownLanguage.cpp]: [
{ packName: "e/f", version: undefined },
{ packName: "g/h", version: "1.2.3" },
{ packName: "a/b", version: undefined },
Expand All @@ -1586,7 +1586,7 @@ test(
parseInputAndConfigErrorMacro,
{},
"c/d",
[Language.cpp, Language.csharp],
[KnownLanguage.cpp, KnownLanguage.csharp],
/multi-language analysis/
);

Expand All @@ -1595,7 +1595,7 @@ test(
parseInputAndConfigErrorMacro,
{},
" + ",
[Language.cpp],
[KnownLanguage.cpp],
/remove the '\+'/
);

Expand All @@ -1604,7 +1604,7 @@ test(
parseInputAndConfigErrorMacro,
{},
" xxx",
[Language.cpp],
[KnownLanguage.cpp],
/"xxx" is not a valid pack/
);

Expand Down
Loading