Skip to content

Commit

Permalink
Rollup merge of rust-lang#109267 - jyn514:test-configure, r=Mark-Simu…
Browse files Browse the repository at this point in the history
…lacrum

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 rust-lang#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
  • Loading branch information
matthiaskrgr authored Mar 20, 2023
2 parents 0e8085a + c7eccda commit 023079f
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 202 deletions.
39 changes: 39 additions & 0 deletions src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from shutil import rmtree

import bootstrap
import configure


class VerifyTestCase(unittest.TestCase):
Expand Down Expand Up @@ -74,12 +75,50 @@ def test_same_dates(self):
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)
Expand Down
Loading

0 comments on commit 023079f

Please sign in to comment.