Skip to content

Commit e8bcbbd

Browse files
committed
Just: add language-tests.ts helper
1 parent acc7e3f commit e8bcbbd

File tree

12 files changed

+77
-21
lines changed

12 files changed

+77
-21
lines changed

java/ql/test/justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ all_checks := default_db_checks + """\
1212
--consistency-queries=""" + consistency_queries
1313

1414
[no-cd]
15-
test *ARGS=".": (_codeql_test "java" base_flags all_checks ARGS)
15+
test *ARGS=".": (_codeql_test "java" base_flags all_checks ARGS)
16+

misc/just/codeql-test-run.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function codeqlTestRun(argv: string[]): number {
7979
}
8080
if (args.codeql === "build") {
8181
if (
82-
invoke(["python3", "build", `target/intree/codeql-${language}`], {
82+
invoke([process.env["JUST_EXECUTABLE"] || "just", language, "build"], {
8383
cwd: semmle_code,
8484
}) !== 0
8585
) {
@@ -114,6 +114,10 @@ function codeqlTestRun(argv: string[]): number {
114114
`codeql-${language}`,
115115
"codeql",
116116
);
117+
if (!fs.existsSync(codeql)) {
118+
console.error(`CodeQL executable not found: ${codeql}`);
119+
return 1;
120+
}
117121
} else if (args.codeql === "host") {
118122
codeql = "codeql";
119123
} else {

misc/just/forward-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function commonJustfile(paths: string[]): string {
77
const splitPaths = paths.map((p) => p.split(path.sep));
88
let justfile: string | undefined = undefined;
99
for (let i = 0; i < splitPaths[0].length; i++) {
10-
let candidate = path.join(...splitPaths[0].slice(0, i), "justfile");
10+
let candidate = path.resolve(path.join(splitPaths[0].slice(0, i).join(path.sep), "justfile"));
1111
if (fs.existsSync(candidate)) {
1212
justfile = candidate;
1313
}
@@ -57,7 +57,7 @@ function forwardCommand(args: string[]): number {
5757
...flags,
5858
...positionalArgs,
5959
];
60-
console.log(`-> ${justfile}: ${invocation.slice(1).join(" ")}`);
60+
console.log(`-> just ${invocation.slice(1).join(" ")}`);
6161
try {
6262
child_process.execFileSync(invocation[0], invocation.slice(1), {
6363
stdio: "inherit",

misc/just/language-tests.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as path from "path";
2+
import * as process from "process"
3+
import * as child_process from "child_process";
4+
5+
function languageTests(argv: string[]): number {
6+
const [extra_args, dir, ...relativeRoots] = argv;
7+
const semmle_code = process.env["SEMMLE_CODE"]!;
8+
let roots = relativeRoots.map((root) => path.relative(semmle_code, path.join(dir, root)));
9+
const invocation = [
10+
process.env["JUST_EXECUTABLE"] || "just",
11+
"--justfile",
12+
path.join(roots[0], "justfile"),
13+
"test",
14+
"--all-checks",
15+
"--codeql=built",
16+
...extra_args.split(" "),
17+
...roots,
18+
];
19+
console.log(`-> just ${invocation.slice(1).join(" ")}`);
20+
try {
21+
child_process.execFileSync(invocation[0], invocation.slice(1), {
22+
stdio: "inherit",
23+
cwd: semmle_code,
24+
});
25+
} catch (error) {
26+
return 1;
27+
}
28+
return 0;
29+
}
30+
31+
process.exit(languageTests(process.argv.slice(2)));

misc/just/lib.just

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ default_db_checks := """\
3939

4040
[no-cd, positional-arguments, no-exit-message]
4141
@_codeql_test LANGUAGE BASE_FLAGS ALL_CHECKS_FLAGS EXTRA_ARGS:
42-
#$language-tests|{{ LANGUAGE }}|{{{{ BASE_FLAGS }}|{{ ALL_CHECKS_FLAGS }}
4342
{{ tsx }} "{{ source_dir() }}/codeql-test-run.ts" "$@"
4443

44+
[no-cd, positional-arguments, no-exit-message]
45+
@_language_tests EXTRA_ARGS SOURCE_DIR +ROOTS: _require_semmle_code
46+
{{ tsx }} "{{ source_dir() }}/language-tests.ts" "$@"
4547

4648
[no-cd, no-exit-message]
4749
_ql_format +ARGS: (_maybe_build "nolang")

rust/codegen/codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -eu
44

5-
source misc/bazel/runfiles.sh 2>/dev/null || source external/ql+/misc/bazel/runfiles.sh
5+
source misc/bazel/runfiles.sh 2>/dev/null || source ../ql+/misc/bazel/runfiles.sh
66

77
ast_generator="$(rlocation "$1")"
88
grammar_file="$(rlocation "$2")"

rust/justfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import '../lib.just'
1+
import '../justfile'
22

33
install: (_bazel "run" "@codeql//rust:install")
44

5+
[group('build')]
56
build: generate (_build "rust")
67

78
generate: (_bazel "run" "@codeql//rust/codegen")
89

910
lint: (_run "python3" "lint.py")
1011

1112
format: (_run "python3" "lint.py" "--format-only")
13+
14+
[group('test')]
15+
language-tests *EXTRA_ARGS: (_language_tests EXTRA_ARGS source_dir() 'ql/test')

rust/ql/justfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@ import "../../lib.just"
33
[no-cd]
44
format *ARGS=".": (_ql_format ARGS)
55

6-
all_checks := default_db_checks + """\
7-
--consistency-queries=""" + source_dir() / "consistency-queries"
8-
9-
[no-cd]
10-
test *ARGS=".": (_just "generate") (_codeql_test "rust" "" all_checks ARGS)
6+
consistency_queries := source_dir() / "consistency-queries"

rust/ql/test/justfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "../justfile"
2+
3+
all_checks := default_db_checks + """\
4+
--consistency-queries=""" + consistency_queries
5+
6+
[no-cd]
7+
test *ARGS=".": (_codeql_test "rust" "" all_checks ARGS)

swift/justfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import '../lib.just'
22

33
install: (_bazel "run" "@codeql//swift:install")
44

5+
[group('build')]
56
build: (_build "swift")
67

78
generate: (_bazel "run" "@codeql//swift/codegen")
@@ -12,3 +13,10 @@ generate: (_bazel "run" "@codeql//swift/codegen")
1213
fi
1314

1415
format ARGS=".": _check_clang_format (_run "clang-format" "-i" ("$(find " + ARGS + " -type f -name '*.h' -or -name '*.cpp')"))
16+
import "../../ql/swift/ql/justfile"
17+
18+
[group('test')]
19+
language-tests *EXTRA_ARGS: (_language_tests EXTRA_ARGS source_dir() 'ql/test')
20+
21+
[group('test')]
22+
extra-tests: (_sembuild "target/test/check-queries-swift") (_sembuild "target/test/check-db-upgrades-swift") (_sembuild "target/test/check-db-downgrades-swift")

0 commit comments

Comments
 (0)