Skip to content

Commit 023079f

Browse files
authored
Rollup merge of #109267 - jyn514:test-configure, r=Mark-Simulacrum
Add tests for configure.py I highly recommend reviewing this with whitespace disabled. Notably, verifying that we generate valid toml relies on python 3.11 so we can use `tomllib`, so this also switches`x86_64-gnu-llvm-14` (one of the PR builders) to use 3.11. While fixing that, I noticed that we stopped testing python2.7 support on PR CI in #106085. `@fee1-dead` `@pietroalbini` please be more careful in the future, there is no CI for CI itself that verifies we are testing everything we should be. - Separate out functions so that each unit test doesn't create a file on disk - Add a few unit tests
2 parents 0e8085a + c7eccda commit 023079f

File tree

4 files changed

+263
-202
lines changed

4 files changed

+263
-202
lines changed

src/bootstrap/bootstrap_test.py

+39
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from shutil import rmtree
1212

1313
import bootstrap
14+
import configure
1415

1516

1617
class VerifyTestCase(unittest.TestCase):
@@ -74,12 +75,50 @@ def test_same_dates(self):
7475
self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
7576

7677

78+
class GenerateAndParseConfig(unittest.TestCase):
79+
"""Test that we can serialize and deserialize a config.toml file"""
80+
def serialize_and_parse(self, args):
81+
from io import StringIO
82+
83+
section_order, sections, targets = configure.parse_args(args)
84+
buffer = StringIO()
85+
configure.write_config_toml(buffer, section_order, targets, sections)
86+
build = bootstrap.RustBuild()
87+
build.config_toml = buffer.getvalue()
88+
89+
try:
90+
import tomllib
91+
# Verify this is actually valid TOML.
92+
tomllib.loads(build.config_toml)
93+
except ImportError:
94+
print("warning: skipping TOML validation, need at least python 3.11", file=sys.stderr)
95+
return build
96+
97+
def test_no_args(self):
98+
build = self.serialize_and_parse([])
99+
self.assertEqual(build.get_toml("changelog-seen"), '2')
100+
self.assertIsNone(build.get_toml("llvm.download-ci-llvm"))
101+
102+
def test_set_section(self):
103+
build = self.serialize_and_parse(["--set", "llvm.download-ci-llvm"])
104+
self.assertEqual(build.get_toml("download-ci-llvm", section="llvm"), 'true')
105+
106+
def test_set_target(self):
107+
build = self.serialize_and_parse(["--set", "target.x86_64-unknown-linux-gnu.cc=gcc"])
108+
self.assertEqual(build.get_toml("cc", section="target.x86_64-unknown-linux-gnu"), 'gcc')
109+
110+
# Uncomment when #108928 is fixed.
111+
# def test_set_top_level(self):
112+
# build = self.serialize_and_parse(["--set", "profile=compiler"])
113+
# self.assertEqual(build.get_toml("profile"), 'compiler')
114+
77115
if __name__ == '__main__':
78116
SUITE = unittest.TestSuite()
79117
TEST_LOADER = unittest.TestLoader()
80118
SUITE.addTest(doctest.DocTestSuite(bootstrap))
81119
SUITE.addTests([
82120
TEST_LOADER.loadTestsFromTestCase(VerifyTestCase),
121+
TEST_LOADER.loadTestsFromTestCase(GenerateAndParseConfig),
83122
TEST_LOADER.loadTestsFromTestCase(ProgramOutOfDate)])
84123

85124
RUNNER = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)

0 commit comments

Comments
 (0)