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

@@ -12,4 +12,5 @@ all_checks := default_db_checks + """\
--consistency-queries=""" + consistency_queries
[no-cd]
test *ARGS=".": (_codeql_test "java" base_flags all_checks ARGS)
test *ARGS=".": (_codeql_test "java" base_flags all_checks ARGS)

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")

View File

@@ -2,7 +2,7 @@
set -eu
source misc/bazel/runfiles.sh 2>/dev/null || source external/ql+/misc/bazel/runfiles.sh
source misc/bazel/runfiles.sh 2>/dev/null || source ../ql+/misc/bazel/runfiles.sh
ast_generator="$(rlocation "$1")"
grammar_file="$(rlocation "$2")"

View File

@@ -1,7 +1,8 @@
import '../lib.just'
import '../justfile'
install: (_bazel "run" "@codeql//rust:install")
[group('build')]
build: generate (_build "rust")
generate: (_bazel "run" "@codeql//rust/codegen")
@@ -9,3 +10,6 @@ generate: (_bazel "run" "@codeql//rust/codegen")
lint: (_run "python3" "lint.py")
format: (_run "python3" "lint.py" "--format-only")
[group('test')]
language-tests *EXTRA_ARGS: (_language_tests EXTRA_ARGS source_dir() 'ql/test')

View File

@@ -3,8 +3,4 @@ import "../../lib.just"
[no-cd]
format *ARGS=".": (_ql_format ARGS)
all_checks := default_db_checks + """\
--consistency-queries=""" + source_dir() / "consistency-queries"
[no-cd]
test *ARGS=".": (_just "generate") (_codeql_test "rust" "" all_checks ARGS)
consistency_queries := source_dir() / "consistency-queries"

7
rust/ql/test/justfile Normal file
View File

@@ -0,0 +1,7 @@
import "../justfile"
all_checks := default_db_checks + """\
--consistency-queries=""" + consistency_queries
[no-cd]
test *ARGS=".": (_codeql_test "rust" "" all_checks ARGS)

View File

@@ -2,6 +2,7 @@ import '../lib.just'
install: (_bazel "run" "@codeql//swift:install")
[group('build')]
build: (_build "swift")
generate: (_bazel "run" "@codeql//swift/codegen")
@@ -12,3 +13,10 @@ generate: (_bazel "run" "@codeql//swift/codegen")
fi
format ARGS=".": _check_clang_format (_run "clang-format" "-i" ("$(find " + ARGS + " -type f -name '*.h' -or -name '*.cpp')"))
import "../../ql/swift/ql/justfile"
[group('test')]
language-tests *EXTRA_ARGS: (_language_tests EXTRA_ARGS source_dir() 'ql/test')
[group('test')]
extra-tests: (_sembuild "target/test/check-queries-swift") (_sembuild "target/test/check-db-upgrades-swift") (_sembuild "target/test/check-db-downgrades-swift")

View File

@@ -3,12 +3,4 @@ import "../../lib.just"
[no-cd]
format *ARGS=".": (_ql_format ARGS)
all_checks := default_db_checks + """\
--check-repeated-labels \
--check-redefined-labels \
--check-use-before-definition \
--consistency-queries=""" + source_dir() / "consistency-queries"
[no-cd]
test *ARGS=".": (_codeql_test "swift" "" all_checks ARGS)
consistency_queries := source_dir() / "consistency-queries"

11
swift/ql/test/justfile Normal file
View File

@@ -0,0 +1,11 @@
import "../justfile"
all_checks := default_db_checks + """\
--check-repeated-labels \
--check-redefined-labels \
--check-use-before-definition \
--consistency-queries=""" + consistency_queries
[no-cd]
test *ARGS=".": (_codeql_test "swift" "" all_checks ARGS)