|
11 | 11 | from shutil import rmtree
|
12 | 12 |
|
13 | 13 | import bootstrap
|
| 14 | +import configure |
14 | 15 |
|
15 | 16 |
|
16 | 17 | class VerifyTestCase(unittest.TestCase):
|
@@ -74,12 +75,50 @@ def test_same_dates(self):
|
74 | 75 | self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
|
75 | 76 |
|
76 | 77 |
|
| 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 | + |
77 | 115 | if __name__ == '__main__':
|
78 | 116 | SUITE = unittest.TestSuite()
|
79 | 117 | TEST_LOADER = unittest.TestLoader()
|
80 | 118 | SUITE.addTest(doctest.DocTestSuite(bootstrap))
|
81 | 119 | SUITE.addTests([
|
82 | 120 | TEST_LOADER.loadTestsFromTestCase(VerifyTestCase),
|
| 121 | + TEST_LOADER.loadTestsFromTestCase(GenerateAndParseConfig), |
83 | 122 | TEST_LOADER.loadTestsFromTestCase(ProgramOutOfDate)])
|
84 | 123 |
|
85 | 124 | RUNNER = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
|
|
0 commit comments