Skip to content

Commit a4c1ec7

Browse files
authored
Merge pull request github#17445 from github/redsun82/rust-qltest
Rust: make ql tests extract files together
2 parents 076dd07 + ed0370b commit a4c1ec7

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

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: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,21 @@ 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+
edition="2021"
20+
[lib]
21+
path="lib.rs"
22+
EOF
23+
"$EXTRACTOR" *.rs >> "$QLTEST_LOG"
24+
if [[ "$?" != 0 ]]; then
3025
cat "$QLTEST_LOG" # Show compiler errors on extraction failure
3126
exit 1
3227
fi

0 commit comments

Comments
 (0)