From 4e8b6dc03832951fc3d0d621106ec43fd7a5dcb5 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Fri, 25 Oct 2024 12:15:15 +0200 Subject: [PATCH 1/2] Rust: fix qltest on macOS, and add CI cross-platform testing of it --- .../qltest/failing_cargo_check/does_not_compile.rs | 5 +++++ .../qltest/failing_cargo_check/functions.ql | 5 +++++ .../qltest/failing_cargo_check/options | 1 + .../qltest/lib/functions.expected | 1 + rust/ql/integration-tests/qltest/lib/functions.ql | 5 +++++ rust/ql/integration-tests/qltest/lib/test.rs | 1 + .../qltest/main/functions.expected | 2 ++ rust/ql/integration-tests/qltest/main/functions.ql | 5 +++++ rust/ql/integration-tests/qltest/main/main.rs | 1 + rust/ql/integration-tests/qltest/main/test.rs | 1 + rust/ql/integration-tests/qltest/qlpack.yml | 5 +++++ rust/ql/integration-tests/qltest/test.py | 14 ++++++++++++++ rust/tools/qltest.cmd | 2 +- rust/tools/qltest.sh | 2 +- 14 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 rust/ql/integration-tests/qltest/failing_cargo_check/does_not_compile.rs create mode 100644 rust/ql/integration-tests/qltest/failing_cargo_check/functions.ql create mode 100644 rust/ql/integration-tests/qltest/failing_cargo_check/options create mode 100644 rust/ql/integration-tests/qltest/lib/functions.expected create mode 100644 rust/ql/integration-tests/qltest/lib/functions.ql create mode 100644 rust/ql/integration-tests/qltest/lib/test.rs create mode 100644 rust/ql/integration-tests/qltest/main/functions.expected create mode 100644 rust/ql/integration-tests/qltest/main/functions.ql create mode 100644 rust/ql/integration-tests/qltest/main/main.rs create mode 100644 rust/ql/integration-tests/qltest/main/test.rs create mode 100644 rust/ql/integration-tests/qltest/qlpack.yml create mode 100644 rust/ql/integration-tests/qltest/test.py diff --git a/rust/ql/integration-tests/qltest/failing_cargo_check/does_not_compile.rs b/rust/ql/integration-tests/qltest/failing_cargo_check/does_not_compile.rs new file mode 100644 index 000000000000..f6b56de20474 --- /dev/null +++ b/rust/ql/integration-tests/qltest/failing_cargo_check/does_not_compile.rs @@ -0,0 +1,5 @@ +fn foo() { + wat + is + this? +} diff --git a/rust/ql/integration-tests/qltest/failing_cargo_check/functions.ql b/rust/ql/integration-tests/qltest/failing_cargo_check/functions.ql new file mode 100644 index 000000000000..8d9a3213dad7 --- /dev/null +++ b/rust/ql/integration-tests/qltest/failing_cargo_check/functions.ql @@ -0,0 +1,5 @@ +import rust + +from Function f +where exists(f.getLocation().getFile().getRelativePath()) +select f diff --git a/rust/ql/integration-tests/qltest/failing_cargo_check/options b/rust/ql/integration-tests/qltest/failing_cargo_check/options new file mode 100644 index 000000000000..c7a0beabb538 --- /dev/null +++ b/rust/ql/integration-tests/qltest/failing_cargo_check/options @@ -0,0 +1 @@ +qltest_cargo_check: true diff --git a/rust/ql/integration-tests/qltest/lib/functions.expected b/rust/ql/integration-tests/qltest/lib/functions.expected new file mode 100644 index 000000000000..613d53954dcc --- /dev/null +++ b/rust/ql/integration-tests/qltest/lib/functions.expected @@ -0,0 +1 @@ +| test.rs:1:1:1:11 | foo | diff --git a/rust/ql/integration-tests/qltest/lib/functions.ql b/rust/ql/integration-tests/qltest/lib/functions.ql new file mode 100644 index 000000000000..8d9a3213dad7 --- /dev/null +++ b/rust/ql/integration-tests/qltest/lib/functions.ql @@ -0,0 +1,5 @@ +import rust + +from Function f +where exists(f.getLocation().getFile().getRelativePath()) +select f diff --git a/rust/ql/integration-tests/qltest/lib/test.rs b/rust/ql/integration-tests/qltest/lib/test.rs new file mode 100644 index 000000000000..8f3b7ef112a0 --- /dev/null +++ b/rust/ql/integration-tests/qltest/lib/test.rs @@ -0,0 +1 @@ +fn foo() {} diff --git a/rust/ql/integration-tests/qltest/main/functions.expected b/rust/ql/integration-tests/qltest/main/functions.expected new file mode 100644 index 000000000000..9d3631034191 --- /dev/null +++ b/rust/ql/integration-tests/qltest/main/functions.expected @@ -0,0 +1,2 @@ +| main.rs:1:1:1:12 | main | +| test.rs:1:1:1:11 | foo | diff --git a/rust/ql/integration-tests/qltest/main/functions.ql b/rust/ql/integration-tests/qltest/main/functions.ql new file mode 100644 index 000000000000..8d9a3213dad7 --- /dev/null +++ b/rust/ql/integration-tests/qltest/main/functions.ql @@ -0,0 +1,5 @@ +import rust + +from Function f +where exists(f.getLocation().getFile().getRelativePath()) +select f diff --git a/rust/ql/integration-tests/qltest/main/main.rs b/rust/ql/integration-tests/qltest/main/main.rs new file mode 100644 index 000000000000..f328e4d9d04c --- /dev/null +++ b/rust/ql/integration-tests/qltest/main/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/rust/ql/integration-tests/qltest/main/test.rs b/rust/ql/integration-tests/qltest/main/test.rs new file mode 100644 index 000000000000..8f3b7ef112a0 --- /dev/null +++ b/rust/ql/integration-tests/qltest/main/test.rs @@ -0,0 +1 @@ +fn foo() {} diff --git a/rust/ql/integration-tests/qltest/qlpack.yml b/rust/ql/integration-tests/qltest/qlpack.yml new file mode 100644 index 000000000000..cf265260e0d1 --- /dev/null +++ b/rust/ql/integration-tests/qltest/qlpack.yml @@ -0,0 +1,5 @@ +dependencies: + codeql/rust-queries: '*' + codeql/rust-all: '*' +extractor: rust +warnOnImplicitThis: true diff --git a/rust/ql/integration-tests/qltest/test.py b/rust/ql/integration-tests/qltest/test.py new file mode 100644 index 000000000000..5ba552c28024 --- /dev/null +++ b/rust/ql/integration-tests/qltest/test.py @@ -0,0 +1,14 @@ +# these tests are meant to exercise QL test running on multiple platforms +# therefore they don't rely on integration test built-in QL test running +# (which skips `qltest.{sh,cmd}`) + +def test_lib(codeql, rust, cwd): + codeql.test.run("lib", threads=1) + +def test_main(codeql, rust): + codeql.test.run("main", threads=1) + +def test_failing_cargo_check(codeql, rust): + out = codeql.test.run("failing_cargo_check", threads=1, show_extractor_output=True, + _assert_failure=True, _capture="stderr") + assert "requested cargo check failed" in out diff --git a/rust/tools/qltest.cmd b/rust/tools/qltest.cmd index 533f200edd3a..72c9911d7d4b 100644 --- a/rust/tools/qltest.cmd +++ b/rust/tools/qltest.cmd @@ -3,7 +3,7 @@ set "RUST_BACKTRACE=full" set "QLTEST_LOG=%CODEQL_EXTRACTOR_RUST_LOG_DIR%/qltest.log" -type NUL && "%CODEQL_EXTRACTOR_RUST_ROOT%/tools/%CODEQL_PLATFORM%/extractor" --qltest >"%QLTEST_LOG%" +type NUL && "%CODEQL_EXTRACTOR_RUST_ROOT%/tools/%CODEQL_PLATFORM%/extractor" --qltest >"%QLTEST_LOG%" 2>&1 if %ERRORLEVEL% neq 0 ( type "%QLTEST_LOG%" diff --git a/rust/tools/qltest.sh b/rust/tools/qltest.sh index df7e7f235638..1d5868263146 100755 --- a/rust/tools/qltest.sh +++ b/rust/tools/qltest.sh @@ -4,7 +4,7 @@ set -eu export RUST_BACKTRACE=full QLTEST_LOG="$CODEQL_EXTRACTOR_RUST_LOG_DIR"/qltest.log -if ! "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor" --qltest &>> "$QLTEST_LOG"; then +if ! "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor" --qltest >> "$QLTEST_LOG" 2>&1; then cat "$QLTEST_LOG" exit 1 fi From 4485193f57b5fcdfb296b7935f35d21decb07fcb Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Fri, 25 Oct 2024 12:33:47 +0200 Subject: [PATCH 2/2] Rust: skip output redirection QL test on windows for now --- rust/ql/integration-tests/qltest/test.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust/ql/integration-tests/qltest/test.py b/rust/ql/integration-tests/qltest/test.py index 5ba552c28024..87d9a09cef4c 100644 --- a/rust/ql/integration-tests/qltest/test.py +++ b/rust/ql/integration-tests/qltest/test.py @@ -1,3 +1,4 @@ +import runs_on # these tests are meant to exercise QL test running on multiple platforms # therefore they don't rely on integration test built-in QL test running # (which skips `qltest.{sh,cmd}`) @@ -11,4 +12,6 @@ def test_main(codeql, rust): def test_failing_cargo_check(codeql, rust): out = codeql.test.run("failing_cargo_check", threads=1, show_extractor_output=True, _assert_failure=True, _capture="stderr") - assert "requested cargo check failed" in out + # TODO: QL test output redirection is currently broken on windows, leaving it up for follow-up work + if not runs_on.windows: + assert "requested cargo check failed" in out