Skip to content

Commit

Permalink
Merge pull request #17841 from github/redsun82/rust-fix-qltest-macos
Browse files Browse the repository at this point in the history
Rust: fix qltest on macOS, and add CI cross-platform testing of it
  • Loading branch information
redsun82 authored Oct 25, 2024
2 parents ba600b0 + 4485193 commit 45e9c2f
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn foo() {
wat
is
this?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import rust

from Function f
where exists(f.getLocation().getFile().getRelativePath())
select f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
qltest_cargo_check: true
1 change: 1 addition & 0 deletions rust/ql/integration-tests/qltest/lib/functions.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| test.rs:1:1:1:11 | foo |
5 changes: 5 additions & 0 deletions rust/ql/integration-tests/qltest/lib/functions.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import rust

from Function f
where exists(f.getLocation().getFile().getRelativePath())
select f
1 change: 1 addition & 0 deletions rust/ql/integration-tests/qltest/lib/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo() {}
2 changes: 2 additions & 0 deletions rust/ql/integration-tests/qltest/main/functions.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| main.rs:1:1:1:12 | main |
| test.rs:1:1:1:11 | foo |
5 changes: 5 additions & 0 deletions rust/ql/integration-tests/qltest/main/functions.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import rust

from Function f
where exists(f.getLocation().getFile().getRelativePath())
select f
1 change: 1 addition & 0 deletions rust/ql/integration-tests/qltest/main/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
1 change: 1 addition & 0 deletions rust/ql/integration-tests/qltest/main/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo() {}
5 changes: 5 additions & 0 deletions rust/ql/integration-tests/qltest/qlpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies:
codeql/rust-queries: '*'
codeql/rust-all: '*'
extractor: rust
warnOnImplicitThis: true
17 changes: 17 additions & 0 deletions rust/ql/integration-tests/qltest/test.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion rust/tools/qltest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
Expand Down
2 changes: 1 addition & 1 deletion rust/tools/qltest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 45e9c2f

Please sign in to comment.