Skip to content

Commit aeae922

Browse files
author
Paolo Tranquilli
committed
Rust: make ql tests extract files together
For the moment this removes the possibility to set custom flags or env variables for the extractor via comments, but that can be added back easily if needed with a different mechanism (like an `env` file).
1 parent 076dd07 commit aeae922

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

rust/ql/test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Cargo.toml
22
Cargo.lock
3+
lib.rs
34
target/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
| lib.rs:0:0:0:0 | lib.rs | DbFile | getName: | lib.rs |
12
| test.rs:0:0:0:0 | test.rs | DbFile | getName: | test.rs |

rust/tools/qltest.sh

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,20 @@ export RUST_BACKTRACE=full
77
QLTEST_LOG="$CODEQL_EXTRACTOR_RUST_LOG_DIR"/qltest.log
88

99
EXTRACTOR="$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor"
10+
echo > lib.rs
1011
for src in *.rs; do
11-
echo -e "[workspace]\n\n[package]\nname = \"test\"\nversion=\"0.0.1\"\n[lib]\npath=\"$src\"\n" > Cargo.toml
12-
env=()
13-
opts=("$src")
14-
opts+=($(sed -n '1 s=//codeql-extractor-options:==p' $src))
15-
expected_status=$(sed -n 's=//codeql-extractor-expected-status:[[:space:]]*==p' $src)
16-
expected_status=${expected_status:-0}
17-
env+=($(sed -n '1 s=//codeql-extractor-env:==p' $src))
18-
echo >> $QLTEST_LOG
19-
echo "env ${env[@]} $EXTRACTOR ${opts[@]}" >> "$QLTEST_LOG"
20-
env "${env[@]}" "$EXTRACTOR" "${opts[@]}" >> $QLTEST_LOG 2>&1
21-
actual_status=$?
22-
if [[ $actual_status != $expected_status ]]; then
23-
FAILED=1
24-
fi
12+
echo "mod ${src%.rs};" >> lib.rs
2513
done
26-
27-
rm -rf Cargo.*
28-
29-
if [ -n "$FAILED" ]; then
14+
cat > Cargo.toml << EOF
15+
[workspace]
16+
[package]
17+
name = "test"
18+
version="0.0.1"
19+
[lib]
20+
path="lib.rs"
21+
EOF
22+
"$EXTRACTOR" *.rs >> "$QLTEST_LOG"
23+
if [[ "$?" != 0 ]]; then
3024
cat "$QLTEST_LOG" # Show compiler errors on extraction failure
3125
exit 1
3226
fi

0 commit comments

Comments
 (0)