summaryrefslogtreecommitdiffstats
path: root/src/bootstrap/bootstrap_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/bootstrap_test.py')
-rw-r--r--src/bootstrap/bootstrap_test.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py
index 06ca3ce21..20bd71f06 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)