Skip to content

Commit 0ba8ef5

Browse files
committed
pytests: add some tests for the cfg_builder
This uses pytest not unittest, unittest is such a pain in the ass and pytest is so much nicer..
1 parent 1593ed5 commit 0ba8ef5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pytests/cfg_builder_tests.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-license-identifier: Apache-2.0
2+
# Copyright © 2021 Intel Corporation
3+
4+
from pathlib import Path
5+
6+
from mesonbuild import mparser
7+
from mesonbuild.cargo.cfg_builder import *
8+
from mesonbuild.cargo.cfg_parser import *
9+
from mesonbuild.cargo.nodebuilder import NodeBuilder
10+
11+
12+
class TestCfgBuilder:
13+
14+
def test_eq(self) -> None:
15+
builder = NodeBuilder(Path(''))
16+
17+
id = builder.id('host_machine')
18+
left = mparser.MethodNode('', 0, 0, id, 'system', mparser.ArgumentNode(builder._builder.token()))
19+
right = builder.string('sunos')
20+
expected = mparser.ComparisonNode('==', left, right)
21+
22+
# use illumos to test the translation from cargo names to meson names
23+
ast = parse('cfg(target_os = "illumos")')
24+
builder = NodeBuilder(Path(''))
25+
build(builder, ast)
26+
final = builder.finalize()
27+
assert len(final.lines) == 1
28+
29+
actual = final.lines[0]
30+
assert actual == expected

0 commit comments

Comments
 (0)