mirror of
https://github.com/github/codeql.git
synced 2026-04-21 06:55:31 +02:00
Rust: reorganize options integration tests
This commit is contained in:
@@ -1 +0,0 @@
|
||||
| src/arch.rs:7:1:8:13 | macos |
|
||||
@@ -1 +0,0 @@
|
||||
| src/arch.rs:1:1:2:13 | linux |
|
||||
@@ -1 +0,0 @@
|
||||
| src/arch.rs:4:1:5:15 | windows |
|
||||
@@ -1,5 +0,0 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where f.getLocation().getFile().getBaseName() = "arch.rs" and f.hasExtendedCanonicalPath()
|
||||
select f
|
||||
5
rust/ql/integration-tests/options/cfg/Cargo.toml
Normal file
5
rust/ql/integration-tests/options/cfg/Cargo.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
[workspace]
|
||||
[package]
|
||||
name = "cfg"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
3
rust/ql/integration-tests/options/cfg/functions.expected
Normal file
3
rust/ql/integration-tests/options/cfg/functions.expected
Normal file
@@ -0,0 +1,3 @@
|
||||
| src/lib.rs:7:1:8:19 | cfg_no_flag |
|
||||
| src/lib.rs:10:1:11:18 | cfg_no_key |
|
||||
| src/lib.rs:16:1:17:24 | pointer_width_64 |
|
||||
@@ -0,0 +1,4 @@
|
||||
| src/lib.rs:1:1:2:16 | cfg_flag |
|
||||
| src/lib.rs:4:1:5:15 | cfg_key |
|
||||
| src/lib.rs:13:1:14:12 | test |
|
||||
| src/lib.rs:19:1:20:24 | pointer_width_32 |
|
||||
5
rust/ql/integration-tests/options/cfg/functions.ql
Normal file
5
rust/ql/integration-tests/options/cfg/functions.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where f.hasExtendedCanonicalPath()
|
||||
select f
|
||||
@@ -13,5 +13,8 @@ fn cfg_no_key() {}
|
||||
#[cfg(test)]
|
||||
fn test() {}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
fn pointer_width_64() {}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
fn pointer_width_32() {}
|
||||
@@ -0,0 +1,19 @@
|
||||
import pytest
|
||||
import platform
|
||||
import os
|
||||
|
||||
|
||||
def test_default(codeql, rust):
|
||||
codeql.database.create()
|
||||
|
||||
|
||||
@pytest.mark.ql_test(expected=".override.expected")
|
||||
def test_cfg_overrides(codeql, rust):
|
||||
overrides = ",".join((
|
||||
"cfg_flag",
|
||||
"cfg_key=value",
|
||||
"-target_pointer_width=64",
|
||||
"target_pointer_width=32",
|
||||
"test",
|
||||
))
|
||||
codeql.database.create(extractor_option=f"cargo_cfg_overrides={overrides}")
|
||||
@@ -1,2 +0,0 @@
|
||||
| src/cfg.rs:7:1:8:19 | cfg_no_flag |
|
||||
| src/cfg.rs:10:1:11:18 | cfg_no_key |
|
||||
@@ -1,4 +0,0 @@
|
||||
| src/cfg.rs:1:1:2:16 | cfg_flag |
|
||||
| src/cfg.rs:4:1:5:15 | cfg_key |
|
||||
| src/cfg.rs:13:1:14:12 | test |
|
||||
| src/cfg.rs:16:1:17:24 | pointer_width_32 |
|
||||
@@ -1,5 +0,0 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where f.getLocation().getFile().getBaseName() = "cfg.rs" and f.hasExtendedCanonicalPath()
|
||||
select f
|
||||
@@ -1,3 +0,0 @@
|
||||
| src/features.rs:1:1:2:11 | foo |
|
||||
| src/features.rs:4:1:5:11 | bar |
|
||||
| src/features.rs:7:1:7:14 | always |
|
||||
@@ -1,2 +0,0 @@
|
||||
| src/features.rs:4:1:5:11 | bar |
|
||||
| src/features.rs:7:1:7:14 | always |
|
||||
@@ -1 +0,0 @@
|
||||
| src/features.rs:7:1:7:14 | always |
|
||||
@@ -1,2 +0,0 @@
|
||||
| src/features.rs:1:1:2:11 | foo |
|
||||
| src/features.rs:7:1:7:14 | always |
|
||||
@@ -1,5 +0,0 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where f.getLocation().getFile().getBaseName() = "features.rs" and f.hasExtendedCanonicalPath()
|
||||
select f
|
||||
@@ -1,6 +1,6 @@
|
||||
[workspace]
|
||||
[package]
|
||||
name = "options"
|
||||
name = "features"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
| src/lib.rs:1:1:2:11 | foo |
|
||||
| src/lib.rs:4:1:5:11 | bar |
|
||||
| src/lib.rs:7:1:7:14 | always |
|
||||
@@ -0,0 +1,2 @@
|
||||
| src/lib.rs:4:1:5:11 | bar |
|
||||
| src/lib.rs:7:1:7:14 | always |
|
||||
@@ -0,0 +1 @@
|
||||
| src/lib.rs:7:1:7:14 | always |
|
||||
@@ -0,0 +1,2 @@
|
||||
| src/lib.rs:1:1:2:11 | foo |
|
||||
| src/lib.rs:7:1:7:14 | always |
|
||||
5
rust/ql/integration-tests/options/features/functions.ql
Normal file
5
rust/ql/integration-tests/options/features/functions.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where f.hasExtendedCanonicalPath()
|
||||
select f
|
||||
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("option",
|
||||
[
|
||||
pytest.param(p,
|
||||
marks=pytest.mark.ql_test(expected=f".{e}.expected"))
|
||||
for p, e in (
|
||||
(None, "default"),
|
||||
("cargo_features=foo", "foo"),
|
||||
("cargo_features=bar", "bar"),
|
||||
("cargo_features=*", "all"),
|
||||
("cargo_features=foo,bar", "all"))
|
||||
])
|
||||
def test_features(codeql, rust, option):
|
||||
codeql.database.create(extractor_option=option)
|
||||
@@ -1,3 +0,0 @@
|
||||
mod arch;
|
||||
mod features;
|
||||
mod cfg;
|
||||
5
rust/ql/integration-tests/options/target/Cargo.toml
Normal file
5
rust/ql/integration-tests/options/target/Cargo.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
[workspace]
|
||||
[package]
|
||||
name = "target"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
@@ -0,0 +1 @@
|
||||
| src/lib.rs:7:1:8:13 | macos |
|
||||
@@ -0,0 +1 @@
|
||||
| src/lib.rs:1:1:2:13 | linux |
|
||||
@@ -0,0 +1 @@
|
||||
| src/lib.rs:4:1:5:15 | windows |
|
||||
5
rust/ql/integration-tests/options/target/functions.ql
Normal file
5
rust/ql/integration-tests/options/target/functions.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where f.hasExtendedCanonicalPath()
|
||||
select f
|
||||
@@ -0,0 +1,19 @@
|
||||
import pytest
|
||||
import platform
|
||||
|
||||
|
||||
@pytest.mark.ql_test(expected=f".{platform.system()}.expected")
|
||||
def test_default(codeql, rust):
|
||||
codeql.database.create()
|
||||
|
||||
@pytest.mark.ql_test(expected=".Windows.expected")
|
||||
def test_target_windows(codeql, rust):
|
||||
codeql.database.create(extractor_option="cargo_target=x86_64-pc-windows-msvc")
|
||||
|
||||
@pytest.mark.ql_test(expected=".Darwin.expected")
|
||||
def test_target_macos(codeql, rust):
|
||||
codeql.database.create(extractor_option="cargo_target=aarch64-apple-darwin")
|
||||
|
||||
@pytest.mark.ql_test(expected=".Linux.expected")
|
||||
def test_target_linux(codeql, rust):
|
||||
codeql.database.create(extractor_option="cargo_target=x86_64-unknown-linux-gnu")
|
||||
@@ -1,49 +0,0 @@
|
||||
import pytest
|
||||
import platform
|
||||
import os
|
||||
|
||||
|
||||
@pytest.mark.ql_test("arch_functions.ql", expected=f".{platform.system()}.expected")
|
||||
def test_default(codeql, rust):
|
||||
codeql.database.create()
|
||||
|
||||
@pytest.mark.ql_test("arch_functions.ql", expected=".Windows.expected")
|
||||
def test_target_windows(codeql, rust):
|
||||
codeql.database.create(extractor_option="cargo_target=x86_64-pc-windows-msvc")
|
||||
|
||||
@pytest.mark.ql_test("arch_functions.ql", expected=".Darwin.expected")
|
||||
def test_target_macos(codeql, rust):
|
||||
codeql.database.create(extractor_option="cargo_target=aarch64-apple-darwin")
|
||||
|
||||
@pytest.mark.ql_test("arch_functions.ql", expected=".Linux.expected")
|
||||
def test_target_linux(codeql, rust):
|
||||
codeql.database.create(extractor_option="cargo_target=x86_64-unknown-linux-gnu")
|
||||
|
||||
@pytest.mark.ql_test("cfg_functions.ql", expected=".override.expected")
|
||||
@pytest.mark.ql_test("arch_functions.ql", expected=f".{platform.system()}.expected")
|
||||
def test_cfg_override(codeql, rust):
|
||||
overrides = ",".join((
|
||||
"cfg_flag",
|
||||
"cfg_key=value",
|
||||
"-target_pointer_width=64",
|
||||
"target_pointer_width=32",
|
||||
"test",
|
||||
))
|
||||
codeql.database.create(extractor_option=f"cargo_cfg_overrides={overrides}")
|
||||
|
||||
@pytest.mark.ql_test("arch_functions.ql", expected=f".{platform.system()}.expected")
|
||||
@pytest.mark.parametrize("features",
|
||||
[
|
||||
pytest.param(p,
|
||||
marks=pytest.mark.ql_test("feature_functions.ql", expected=f".{e}.expected"),
|
||||
id=id)
|
||||
for p, e, id in (
|
||||
("foo", "foo", "foo"),
|
||||
("bar", "bar", "bar"),
|
||||
# as long as the integration test runner does not sanitize filenames we must
|
||||
# replace `*` and `,` in the parameter id
|
||||
("*", "all", "all"),
|
||||
("foo,bar", "all", "foo+bar"))
|
||||
])
|
||||
def test_features(codeql, rust, features):
|
||||
codeql.database.create(extractor_option=f"cargo_features={features}")
|
||||
Reference in New Issue
Block a user