diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2025-03-04 12:57:40 -0800 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-03-06 23:01:53 -0500 |
commit | f64cda3d80f34db42cc59fefd3abbe904fc3231a (patch) | |
tree | 73166ee94b18f44bc9771131ea6a75e50fc1ac72 | |
parent | e7a405c7e2a384e68c39ee3d6397a974df4df36f (diff) | |
download | meson-f64cda3d80f34db42cc59fefd3abbe904fc3231a.zip meson-f64cda3d80f34db42cc59fefd3abbe904fc3231a.tar.gz meson-f64cda3d80f34db42cc59fefd3abbe904fc3231a.tar.bz2 |
unittests: Use more subtests
-rw-r--r-- | unittests/linuxliketests.py | 78 | ||||
-rw-r--r-- | unittests/optiontests.py | 32 | ||||
-rw-r--r-- | unittests/platformagnostictests.py | 20 |
3 files changed, 73 insertions, 57 deletions
diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index 2b56436..08eb4b9 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -43,7 +43,7 @@ PKG_CONFIG = os.environ.get('PKG_CONFIG', 'pkg-config') from run_tests import ( - get_fake_env + get_fake_env, Backend, ) from .baseplatformtests import BasePlatformTests @@ -1876,47 +1876,57 @@ class LinuxlikeTests(BasePlatformTests): self.assertTrue(False, f'Source {src} not found in compdb') def test_persp_options(self): + if self.backend is not Backend.ninja: + raise SkipTest(f'{self.backend.name!r} backend can\'t install files') + testdir = os.path.join(self.unit_test_dir, '123 persp options') - self.init(testdir, extra_args='-Doptimization=1') - compdb = self.get_compdb() - mainsrc = 'toplevel.c' - sub1src = 'sub1.c' - sub2src = 'sub2.c' - self.check_has_flag(compdb, mainsrc, '-O1') - self.check_has_flag(compdb, sub1src, '-O1') - self.check_has_flag(compdb, sub2src, '-O1') + + with self.subTest('init'): + self.init(testdir, extra_args='-Doptimization=1') + compdb = self.get_compdb() + mainsrc = 'toplevel.c' + sub1src = 'sub1.c' + sub2src = 'sub2.c' + self.check_has_flag(compdb, mainsrc, '-O1') + self.check_has_flag(compdb, sub1src, '-O1') + self.check_has_flag(compdb, sub2src, '-O1') # Set subproject option to O2 - self.setconf(['-Dround=2', '-D', 'sub2:optimization=3']) - compdb = self.get_compdb() - self.check_has_flag(compdb, mainsrc, '-O1') - self.check_has_flag(compdb, sub1src, '-O1') - self.check_has_flag(compdb, sub2src, '-O3') + with self.subTest('set subproject option'): + self.setconf(['-Dround=2', '-D', 'sub2:optimization=3']) + compdb = self.get_compdb() + self.check_has_flag(compdb, mainsrc, '-O1') + self.check_has_flag(compdb, sub1src, '-O1') + self.check_has_flag(compdb, sub2src, '-O3') # Change an already set override. - self.setconf(['-Dround=3', '-D', 'sub2:optimization=2']) - compdb = self.get_compdb() - self.check_has_flag(compdb, mainsrc, '-O1') - self.check_has_flag(compdb, sub1src, '-O1') - self.check_has_flag(compdb, sub2src, '-O2') + with self.subTest('change subproject option'): + self.setconf(['-Dround=3', '-D', 'sub2:optimization=2']) + compdb = self.get_compdb() + self.check_has_flag(compdb, mainsrc, '-O1') + self.check_has_flag(compdb, sub1src, '-O1') + self.check_has_flag(compdb, sub2src, '-O2') # Set top level option to O3 - self.setconf(['-Dround=4', '-D:optimization=3']) - compdb = self.get_compdb() - self.check_has_flag(compdb, mainsrc, '-O3') - self.check_has_flag(compdb, sub1src, '-O1') - self.check_has_flag(compdb, sub2src, '-O2') + with self.subTest('change main project option'): + self.setconf(['-Dround=4', '-D:optimization=3']) + compdb = self.get_compdb() + self.check_has_flag(compdb, mainsrc, '-O3') + self.check_has_flag(compdb, sub1src, '-O1') + self.check_has_flag(compdb, sub2src, '-O2') # Unset subproject - self.setconf(['-Dround=5', '-U', 'sub2:optimization']) - compdb = self.get_compdb() - self.check_has_flag(compdb, mainsrc, '-O3') - self.check_has_flag(compdb, sub1src, '-O1') - self.check_has_flag(compdb, sub2src, '-O1') + with self.subTest('unset subproject option'): + self.setconf(['-Dround=5', '-U', 'sub2:optimization']) + compdb = self.get_compdb() + self.check_has_flag(compdb, mainsrc, '-O3') + self.check_has_flag(compdb, sub1src, '-O1') + self.check_has_flag(compdb, sub2src, '-O1') # Set global value - self.setconf(['-Dround=6', '-D', 'optimization=2']) - compdb = self.get_compdb() - self.check_has_flag(compdb, mainsrc, '-O3') - self.check_has_flag(compdb, sub1src, '-O2') - self.check_has_flag(compdb, sub2src, '-O2') + with self.subTest('set global option'): + self.setconf(['-Dround=6', '-D', 'optimization=2']) + compdb = self.get_compdb() + self.check_has_flag(compdb, mainsrc, '-O3') + self.check_has_flag(compdb, sub1src, '-O2') + self.check_has_flag(compdb, sub2src, '-O2') diff --git a/unittests/optiontests.py b/unittests/optiontests.py index 6b8eb4a..3db769d 100644 --- a/unittests/optiontests.py +++ b/unittests/optiontests.py @@ -36,21 +36,23 @@ class OptionTests(unittest.TestCase): self.assertEqual(optstore.get_value_for(k), new_value) def test_parsing(self): - s1 = OptionKey.from_string('sub:optname') - s1_expected = OptionKey('optname', 'sub', MachineChoice.HOST) - self.assertEqual(s1, s1_expected) - self.assertEqual(str(s1), 'sub:optname') - - s2 = OptionKey.from_string('optname') - s2_expected = OptionKey('optname', None, MachineChoice.HOST) - self.assertEqual(s2, s2_expected) - - self.assertEqual(str(s2), 'optname') - - s3 = OptionKey.from_string(':optname') - s3_expected = OptionKey('optname', '', MachineChoice.HOST) - self.assertEqual(s3, s3_expected) - self.assertEqual(str(s3), ':optname') + with self.subTest('subproject'): + s1 = OptionKey.from_string('sub:optname') + s1_expected = OptionKey('optname', 'sub', MachineChoice.HOST) + self.assertEqual(s1, s1_expected) + self.assertEqual(str(s1), 'sub:optname') + + with self.subTest('plain name'): + s2 = OptionKey.from_string('optname') + s2_expected = OptionKey('optname', None, MachineChoice.HOST) + self.assertEqual(s2, s2_expected) + self.assertEqual(str(s2), 'optname') + + with self.subTest('root project'): + s3 = OptionKey.from_string(':optname') + s3_expected = OptionKey('optname', '', MachineChoice.HOST) + self.assertEqual(s3, s3_expected) + self.assertEqual(str(s3), ':optname') def test_subproject_for_system(self): optstore = OptionStore(False) diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index 5707553..cb6a931 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -167,21 +167,25 @@ class PlatformAgnosticTests(BasePlatformTests): self.init(testdir) # no-op change works - self.setconf(f'--backend=ninja') - self.init(testdir, extra_args=['--reconfigure', '--backend=ninja']) + with self.subTest('set the option to the same value'): + self.setconf('--backend=ninja') + self.init(testdir, extra_args=['--reconfigure', '--backend=ninja']) # Change backend option is not allowed - with self.assertRaises(subprocess.CalledProcessError) as cm: - self.setconf('-Dbackend=none') - self.assertIn("ERROR: Tried to modify read only option 'backend'", cm.exception.stdout) + with self.subTest('Changing the backend'): + with self.assertRaises(subprocess.CalledProcessError) as cm: + self.setconf('-Dbackend=none') + self.assertIn("ERROR: Tried to modify read only option 'backend'", cm.exception.stdout) # Check that the new value was not written in the store. - self.assertEqual(self.getconf('backend'), 'ninja') + with self.subTest('option is stored correctly'): + self.assertEqual(self.getconf('backend'), 'ninja') # Wipe with a different backend is allowed - self.init(testdir, extra_args=['--wipe', '--backend=none']) + with self.subTest('Changing the backend with wipe'): + self.init(testdir, extra_args=['--wipe', '--backend=none']) - self.assertEqual(self.getconf('backend'), 'none') + self.assertEqual(self.getconf('backend'), 'none') def test_validate_dirs(self): testdir = os.path.join(self.common_test_dir, '1 trivial') |