Coverage for rust2rpm/tests/test_cfg.py: 100%
9 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-21 18:46 +0100
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-21 18:46 +0100
1import pytest
3from rust2rpm import cfg
6def test_pyparsing_run_tests():
7 g = cfg.cfg_grammar()
9 g.runTests(
10 """\
11 cfg(target_os = "macos")
12 cfg(any(foo, bar))
13 cfg(all(unix, target_pointer_width = "32"))
14 cfg(not(foo))
15 """,
16 )
19@pytest.mark.parametrize(
20 ("expr", "expected"),
21 [
22 ('cfg(target_os = "macos")', False),
23 ("cfg(any(foo, bar))", False),
24 ('cfg(all(unix, target_pointer_width = "16"))', True),
25 ("cfg(not(foo))", True),
26 ("cfg(unix)", True),
27 ("cfg(not(unix))", False),
28 ("cfg(windows)", False),
29 ("cfg(miri)", False),
30 ("cfg(linux)", False), # not defined
31 ("cfg(not(windows))", True),
32 ("cfg(any(unix, windows))", True),
33 ("cfg(any(windows, unix))", True),
34 ("cfg(any(windows, windows, windows))", False),
35 ('cfg(target_os = "linux")', True),
36 ('cfg(any(target_os = "linux"))', True),
37 ('cfg(all(target_os = "linux"))', True),
38 ('cfg(any(target_os = "linux", target_os = "macos"))', True),
39 ('cfg(any(target_pointer_width = "16", target_pointer_width = "32", target_pointer_width = "64"))', True),
40 ('cfg(target_feature = "avx")', True),
41 ('cfg(target_family = "unix")', True),
42 ('cfg(target_env = "")', True),
43 ('cfg(target_env = "gnu")', True),
44 ('cfg(target_env = "msvc")', False),
45 ('cfg(target_env = "musl")', False),
46 ('cfg(target_pointer_width = "16")', True),
47 ('cfg(target_pointer_width = "32")', True),
48 ('cfg(target_pointer_width = "64")', True),
49 ('cfg(target_vendor = "unknown")', True),
50 ('cfg(target_vendor = "apple")', False),
51 ('cfg(target_vendor = "pc")', False),
52 ("cfg(hello)", False),
53 # from rustix 0.35.12
54 ('cfg(any(target_os = "android", target_os = "linux"))', True),
55 (
56 'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", '
57 'any(target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"), '
58 'all(target_endian = "little", any(target_arch = "arm", '
59 'all(target_arch = "aarch64", target_pointer_width = "64"), '
60 'target_arch = "powerpc64", target_arch = "riscv64", target_arch = "mips", target_arch = "mips64")))))',
61 True,
62 ),
63 (
64 'cfg(any(rustix_use_libc, miri, not(all(target_os = "linux", '
65 'any(target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"), '
66 'all(target_endian = "little", any(target_arch = "arm", '
67 'all(target_arch = "aarch64", target_pointer_width = "64"), '
68 'target_arch = "powerpc64", target_arch = "riscv64", target_arch = "mips", target_arch = "mips64")))))))',
69 True,
70 ),
71 ('cfg(not(target_os = "emscripten"))', True),
72 # from tokio 1.21.2
73 ('cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_os = "wasi")))', False),
74 ("cfg(loom)", False),
75 ('cfg(not(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown")))', True),
76 ('cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))', True),
77 ('cfg(target_os = "freebsd")', False),
78 ("cfg(tokio_unstable)", False),
79 ],
80)
81def test_expressions(expr: str, *, expected: bool):
82 value = cfg.parse_and_evaluate(expr)
83 assert value == expected