diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-20 09:46:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-20 09:46:52 +0100 |
| commit | 023079fb862afbe3002646f545bb465009aa2579 (patch) | |
| tree | 4d7d11748ee2c9dca42533e99f826cd22e2b5264 /src/bootstrap/bootstrap_test.py | |
| parent | 0e8085a095bfff4b8a5a3e1bcfbc5b0bae2dec5d (diff) | |
| parent | c7eccdaaee3cb5921d3d4cdb8dcb2639d4e7dec8 (diff) | |
| download | rust-023079fb862afbe3002646f545bb465009aa2579.tar.gz rust-023079fb862afbe3002646f545bb465009aa2579.zip | |
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 https://github.com/rust-lang/rust/pull/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
Diffstat (limited to 'src/bootstrap/bootstrap_test.py')
| -rw-r--r-- | src/bootstrap/bootstrap_test.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py index 06ca3ce21b3..20bd71f06e9 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,50 @@ 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: + print("warning: skipping TOML validation, need at least python 3.11", file=sys.stderr) + 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) |
