Just: add language-tests.ts helper

This commit is contained in:
Paolo Tranquilli
2025-07-08 14:06:14 +02:00
parent acc7e3f32d
commit e8bcbbd6df
12 changed files with 77 additions and 21 deletions

View File

@@ -79,7 +79,7 @@ function codeqlTestRun(argv: string[]): number {
}
if (args.codeql === "build") {
if (
invoke(["python3", "build", `target/intree/codeql-${language}`], {
invoke([process.env["JUST_EXECUTABLE"] || "just", language, "build"], {
cwd: semmle_code,
}) !== 0
) {
@@ -114,6 +114,10 @@ function codeqlTestRun(argv: string[]): number {
`codeql-${language}`,
"codeql",
);
if (!fs.existsSync(codeql)) {
console.error(`CodeQL executable not found: ${codeql}`);
return 1;
}
} else if (args.codeql === "host") {
codeql = "codeql";
} else {

View File

@@ -7,7 +7,7 @@ function commonJustfile(paths: string[]): string {
const splitPaths = paths.map((p) => p.split(path.sep));
let justfile: string | undefined = undefined;
for (let i = 0; i < splitPaths[0].length; i++) {
let candidate = path.join(...splitPaths[0].slice(0, i), "justfile");
let candidate = path.resolve(path.join(splitPaths[0].slice(0, i).join(path.sep), "justfile"));
if (fs.existsSync(candidate)) {
justfile = candidate;
}
@@ -57,7 +57,7 @@ function forwardCommand(args: string[]): number {
...flags,
...positionalArgs,
];
console.log(`-> ${justfile}: ${invocation.slice(1).join(" ")}`);
console.log(`-> just ${invocation.slice(1).join(" ")}`);
try {
child_process.execFileSync(invocation[0], invocation.slice(1), {
stdio: "inherit",

View File

@@ -0,0 +1,31 @@
import * as path from "path";
import * as process from "process"
import * as child_process from "child_process";
function languageTests(argv: string[]): number {
const [extra_args, dir, ...relativeRoots] = argv;
const semmle_code = process.env["SEMMLE_CODE"]!;
let roots = relativeRoots.map((root) => path.relative(semmle_code, path.join(dir, root)));
const invocation = [
process.env["JUST_EXECUTABLE"] || "just",
"--justfile",
path.join(roots[0], "justfile"),
"test",
"--all-checks",
"--codeql=built",
...extra_args.split(" "),
...roots,
];
console.log(`-> just ${invocation.slice(1).join(" ")}`);
try {
child_process.execFileSync(invocation[0], invocation.slice(1), {
stdio: "inherit",
cwd: semmle_code,
});
} catch (error) {
return 1;
}
return 0;
}
process.exit(languageTests(process.argv.slice(2)));

View File

@@ -39,9 +39,11 @@ default_db_checks := """\
[no-cd, positional-arguments, no-exit-message]
@_codeql_test LANGUAGE BASE_FLAGS ALL_CHECKS_FLAGS EXTRA_ARGS:
#$language-tests|{{ LANGUAGE }}|{{{{ BASE_FLAGS }}|{{ ALL_CHECKS_FLAGS }}
{{ tsx }} "{{ source_dir() }}/codeql-test-run.ts" "$@"
[no-cd, positional-arguments, no-exit-message]
@_language_tests EXTRA_ARGS SOURCE_DIR +ROOTS: _require_semmle_code
{{ tsx }} "{{ source_dir() }}/language-tests.ts" "$@"
[no-cd, no-exit-message]
_ql_format +ARGS: (_maybe_build "nolang")