Skip to content

Commit 3d93b38

Browse files
author
Paolo Tranquilli
committed
Just test PoC
This is a rough PoC showcasing [just](https://github.com/casey/just) as a builder/test runner. After installing `just` you can (in this PoC <language> can only be `rust`): * `just install <language>` to install a language pack in-tree `<language>` can be omitted if running from inside its directory. * `just build <language>` will build `target/intree/codeql-<language>` from the internal repository, if available, otherwise it will fall back to `install`. * `just test TESTS... FLAGS...` will run the provided tests, if they are of the same kind (integration or QL tests), passing FLAGS to the runner. For QL tests the appropriate `build <language>` is run. Notably, for QL tests this command works also if using `codeql` standalone from the internal repository (using `install` and `codeql` from `PATH`). If running from within a test directory, `TESTS` can be omitted and defaults to all tests in the current directory.
1 parent 066db76 commit 3d93b38

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

Diff for: impl.just

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env just --justfile
2+
3+
set allow-duplicate-recipes
4+
set allow-duplicate-variables
5+
set unstable
6+
set quiet
7+
8+
_install LANGUAGE:
9+
bazel run //{{ trim_end_match(LANGUAGE, '/') }}:install
10+
11+
_build LANGUAGE:
12+
if [ -n ${SEMMLE_CODE:-} ]; then \
13+
cd $SEMMLE_CODE; ./build target/intree/codeql-{{ LANGUAGE }}; \
14+
else \
15+
just install {{ LANGUAGE }}; \
16+
fi
17+
18+
build LANGUAGE: (_build LANGUAGE)
19+
install LANGUAGE: (_install LANGUAGE)
20+
21+
[no-cd, script:'python3', positional-arguments, no-exit-message]
22+
test +ARGS: # TODO: fuzzy test chooser when no arguments are provided!
23+
import pathlib
24+
import subprocess
25+
import os
26+
import sys
27+
# avoid infinite recursion: this happens when arguments have kinds of tests
28+
if os.environ.get("CODEQL_JUSTFILE_TEST"):
29+
print("No common test handler found", file=sys.stderr)
30+
sys.exit(1)
31+
os.environ["CODEQL_JUSTFILE_TEST"] = "true"
32+
33+
flags = [arg for arg in sys.argv[1:] if arg.startswith('-')]
34+
args = [arg for arg in sys.argv[1:] if not arg.startswith('-')]
35+
common_path = pathlib.Path(os.path.commonpath(args)).resolve()
36+
if not common_path.is_dir():
37+
common_path = common_path.parent
38+
ret = subprocess.run(
39+
['{{ just_executable() }}', 'test'] + flags + [pathlib.Path(a).resolve().relative_to(common_path) for a in args],
40+
cwd=common_path).returncode
41+
sys.exit(ret)
42+
43+
[no-cd]
44+
_run_language_tests LANGUAGE *ARGS: (_build LANGUAGE)
45+
if [ -n ${SEMMLE_CODE:-} ]; then \
46+
$SEMMLE_CODE/target/intree/codeql-{{ LANGUAGE }}/codeql test run $ARGS; \
47+
else \
48+
codeql --search-path={{ source_dir() }} test run $ARGS; \
49+
fi
50+
51+
[no-cd]
52+
_run_integration_tests *ARGS:
53+
if [ -n ${SEMMLE_CODE:-} ]; then \
54+
$SEMMLE_CODE/tools/pytest $ARGS; \
55+
else \
56+
echo "integration tests require running from an internal repository working copy" >&2; \
57+
exit 1; \
58+
fi

Diff for: justfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'impl.just'
2+
import? '../justfile' # internal repo just file, if present
3+
4+
@_default:
5+
{{ just_executable() }} --list

Diff for: rust/justfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import '../justfile'
2+
3+
install LANGUAGE='rust': (_install LANGUAGE)
4+
build LANGUAGE='rust': (_build LANGUAGE)

Diff for: rust/ql/integration-tests/justfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import '../../justfile'
2+
3+
test *ARGS=".": (_run_integration_tests ARGS)

Diff for: rust/ql/test/justfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env just --justfile
2+
3+
import '../../justfile'
4+
5+
test *ARGS=".": (_run_language_tests "rust" ARGS)

0 commit comments

Comments
 (0)