Skip to content

Commit

Permalink
Merge pull request #17445 from github/redsun82/rust-qltest
Browse files Browse the repository at this point in the history
Rust: make ql tests extract files together
  • Loading branch information
redsun82 authored Sep 12, 2024
2 parents 076dd07 + ed0370b commit a4c1ec7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions rust/ql/test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Cargo.toml
Cargo.lock
lib.rs
target/
1 change: 1 addition & 0 deletions rust/ql/test/extractor-tests/generated/File/File.expected
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
| lib.rs:0:0:0:0 | lib.rs | DbFile | getName: | lib.rs |
| test.rs:0:0:0:0 | test.rs | DbFile | getName: | test.rs |
31 changes: 13 additions & 18 deletions rust/tools/qltest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,21 @@ export RUST_BACKTRACE=full
QLTEST_LOG="$CODEQL_EXTRACTOR_RUST_LOG_DIR"/qltest.log

EXTRACTOR="$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor"
echo > lib.rs
for src in *.rs; do
echo -e "[workspace]\n\n[package]\nname = \"test\"\nversion=\"0.0.1\"\n[lib]\npath=\"$src\"\n" > Cargo.toml
env=()
opts=("$src")
opts+=($(sed -n '1 s=//codeql-extractor-options:==p' $src))
expected_status=$(sed -n 's=//codeql-extractor-expected-status:[[:space:]]*==p' $src)
expected_status=${expected_status:-0}
env+=($(sed -n '1 s=//codeql-extractor-env:==p' $src))
echo >> $QLTEST_LOG
echo "env ${env[@]} $EXTRACTOR ${opts[@]}" >> "$QLTEST_LOG"
env "${env[@]}" "$EXTRACTOR" "${opts[@]}" >> $QLTEST_LOG 2>&1
actual_status=$?
if [[ $actual_status != $expected_status ]]; then
FAILED=1
fi
echo "mod ${src%.rs};" >> lib.rs
done

rm -rf Cargo.*

if [ -n "$FAILED" ]; then
cat > Cargo.toml << EOF
[workspace]
[package]
name = "test"
version="0.0.1"
edition="2021"
[lib]
path="lib.rs"
EOF
"$EXTRACTOR" *.rs >> "$QLTEST_LOG"
if [[ "$?" != 0 ]]; then
cat "$QLTEST_LOG" # Show compiler errors on extraction failure
exit 1
fi

0 comments on commit a4c1ec7

Please sign in to comment.