diff options
| author | Joshua Nelson <github@jyn.dev> | 2023-03-17 10:24:40 -0500 |
|---|---|---|
| committer | Joshua Nelson <github@jyn.dev> | 2023-03-17 10:24:40 -0500 |
| commit | d808bc296dc147ddf0d17e1816be7b84ba51675a (patch) | |
| tree | fc11e80dae6d8b40a38ff0420b250ca7783302e0 /src/bootstrap/bootstrap_test.py | |
| parent | 2d64f229a09515978e6f338b821057a64334a0b5 (diff) | |
| download | rust-d808bc296dc147ddf0d17e1816be7b84ba51675a.tar.gz rust-d808bc296dc147ddf0d17e1816be7b84ba51675a.zip | |
Add tests for configure.py
- Separate out functions so that each unit test doesn't create a file on disk - Add a few unit tests Notably, verifying that we generate valid toml relies on python 3.11 so we can use `tomllib`.
Diffstat (limited to 'src/bootstrap/bootstrap_test.py')
| -rw-r--r-- | src/bootstrap/bootstrap_test.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py index 06ca3ce21b3..6a4a64a1ed5 100644 --- a/src/bootstrap/bootstrap_test.py +++ b/src/bootstrap/bootstrap_test.py @@ -11,6 +11,7 @@ import sys from shutil import rmtree import bootstrap +import configure class VerifyTestCase(unittest.TestCase): @@ -74,12 +75,51 @@ class ProgramOutOfDate(unittest.TestCase): self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key)) +class GenerateAndParseConfig(unittest.TestCase): + """Test that we can serialize and deserialize a config.toml file""" + def serialize_and_parse(self, args): + from io import StringIO + + section_order, sections, targets = configure.parse_args(args) + buffer = StringIO() + configure.write_config_toml(buffer, section_order, targets, sections) + build = bootstrap.RustBuild() + build.config_toml = buffer.getvalue() + + try: + import tomllib + # Verify this is actually valid TOML. + tomllib.loads(build.config_toml) + except ImportError: + # too old a version of python + pass + return build + + def test_no_args(self): + build = self.serialize_and_parse([]) + self.assertEqual(build.get_toml("changelog-seen"), '2') + self.assertIsNone(build.get_toml("llvm.download-ci-llvm")) + + def test_set_section(self): + build = self.serialize_and_parse(["--set", "llvm.download-ci-llvm"]) + self.assertEqual(build.get_toml("download-ci-llvm", section="llvm"), 'true') + + def test_set_target(self): + build = self.serialize_and_parse(["--set", "target.x86_64-unknown-linux-gnu.cc=gcc"]) + self.assertEqual(build.get_toml("cc", section="target.x86_64-unknown-linux-gnu"), 'gcc') + + # Uncomment when #108928 is fixed. + # def test_set_top_level(self): + # build = self.serialize_and_parse(["--set", "profile=compiler"]) + # self.assertEqual(build.get_toml("profile"), 'compiler') + if __name__ == '__main__': SUITE = unittest.TestSuite() TEST_LOADER = unittest.TestLoader() SUITE.addTest(doctest.DocTestSuite(bootstrap)) SUITE.addTests([ TEST_LOADER.loadTestsFromTestCase(VerifyTestCase), + TEST_LOADER.loadTestsFromTestCase(GenerateAndParseConfig), TEST_LOADER.loadTestsFromTestCase(ProgramOutOfDate)]) RUNNER = unittest.TextTestRunner(stream=sys.stdout, verbosity=2) |
