Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1d88e13

Browse filesBrowse 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 1d88e13
Copy full SHA for 1d88e13

File tree

5 files changed

+78
-0
lines changed
Filter options

5 files changed

+78
-0
lines changed

‎impl.just

Copy file name to clipboard
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 test args are of different kinds
28+
# or for different languages, or also if they are across the external/internal
29+
# repository boundary
30+
# TODO: allow some degree of mixing maybe?
31+
if os.environ.get("CODEQL_JUSTFILE_TEST"):
32+
print("No common test handler found", file=sys.stderr)
33+
sys.exit(1)
34+
os.environ["CODEQL_JUSTFILE_TEST"] = "true"
35+
36+
flags = [arg for arg in sys.argv[1:] if arg.startswith('-')]
37+
args = [arg for arg in sys.argv[1:] if not arg.startswith('-')]
38+
common_path = pathlib.Path(os.path.commonpath(args)).resolve()
39+
if not common_path.is_dir():
40+
common_path = common_path.parent
41+
ret = subprocess.run(
42+
['{{ just_executable() }}', 'test'] + flags + [pathlib.Path(a).resolve().relative_to(common_path) for a in args],
43+
cwd=common_path).returncode
44+
sys.exit(ret)
45+
46+
[no-cd]
47+
_run_language_tests LANGUAGE *ARGS: (_build LANGUAGE)
48+
if [ -n ${SEMMLE_CODE:-} ]; then \
49+
$SEMMLE_CODE/target/intree/codeql-{{ LANGUAGE }}/codeql test run $ARGS; \
50+
else \
51+
codeql --search-path={{ source_dir() }} test run $ARGS; \
52+
fi
53+
54+
[no-cd]
55+
_run_integration_tests *ARGS:
56+
if [ -n ${SEMMLE_CODE:-} ]; then \
57+
$SEMMLE_CODE/tools/pytest $ARGS; \
58+
else \
59+
echo "integration tests require running from an internal repository working copy" >&2; \
60+
exit 1; \
61+
fi

‎justfile

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
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

‎rust/justfile

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
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)

‎rust/ql/integration-tests/justfile

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import '../../justfile'
2+
3+
test *ARGS=".": (_run_integration_tests ARGS)

‎rust/ql/test/justfile

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.