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..87d9a09cef4c --- /dev/null +++ b/rust/ql/integration-tests/qltest/test.py @@ -0,0 +1,17 @@ +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}`) + +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") + # 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 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