aboutsummaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-02-17 00:08:37 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-02-22 06:49:34 +0530
commit3320e13d91d68f0a4898901c168b3981b76dec41 (patch)
tree46770e75260d290a4ae9114a5e9509b742b01016 /run_unittests.py
parentb0061257c93da955397da05fb0783801f67cd54d (diff)
downloadmeson-3320e13d91d68f0a4898901c168b3981b76dec41.zip
meson-3320e13d91d68f0a4898901c168b3981b76dec41.tar.gz
meson-3320e13d91d68f0a4898901c168b3981b76dec41.tar.bz2
unit tests: Add a test for the symbolchecker script
When a source file for a library is changed without adding new extern symbols, only that library should be rebuilt. Nothing that uses it should be relinked. Along the way, also remove trailing `.` in all Ninja rule descriptions. It's very confusing to see messages like: ``` Linking target mylib.dll. ``` It's confusing that the period at the end of that is not part of the filename. Instead of removing that period manually in the tests (which feels wrong!) just don't print it at all.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/run_unittests.py b/run_unittests.py
index 500b5eb..80c7cd0 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1756,6 +1756,33 @@ class BasePlatformTests(unittest.TestCase):
else:
raise RuntimeError('Invalid backend: {!r}'.format(self.backend.name))
+ @staticmethod
+ def get_target_from_filename(filename):
+ base = os.path.splitext(filename)[0]
+ if base.startswith('lib'):
+ return base[3:]
+ return base
+
+ def assertBuildRelinkedOnlyTarget(self, target):
+ ret = self.build()
+ if self.backend is Backend.ninja:
+ linked_targets = []
+ for line in ret.split('\n'):
+ if 'Linking target' in line:
+ fname = line.rsplit('target ')[-1]
+ linked_targets.append(self.get_target_from_filename(fname))
+ self.assertEqual(linked_targets, [target])
+ elif self.backend is Backend.vs:
+ # Ensure that this target was rebuilt
+ linkre = re.compile(r'Link:\n [^\n]*link.exe[^\n]*/OUT:".\\([^"]*)"', flags=re.IGNORECASE)
+ matches = linkre.findall(ret)
+ self.assertEqual(len(matches), 1, msg=matches)
+ self.assertEqual(self.get_target_from_filename(matches[0]), target)
+ elif self.backend is Backend.xcode:
+ raise unittest.SkipTest('Please help us fix this test on the xcode backend')
+ else:
+ raise RuntimeError('Invalid backend: {!r}'.format(self.backend.name))
+
def assertPathExists(self, path):
m = 'Path {!r} should exist'.format(path)
self.assertTrue(os.path.exists(path), msg=m)
@@ -2572,6 +2599,9 @@ class AllPlatformTests(BasePlatformTests):
# Changing mtime of meson.build should not rebuild anything
self.utime(os.path.join(testdir, 'meson.build'))
self.assertReconfiguredBuildIsNoop()
+ # Changing mtime of libefile.c should rebuild the library, but not relink the executable
+ self.utime(os.path.join(testdir, 'libfile.c'))
+ self.assertBuildRelinkedOnlyTarget('mylib')
def test_source_changes_cause_rebuild(self):
'''
@@ -2586,7 +2616,7 @@ class AllPlatformTests(BasePlatformTests):
self.assertBuildIsNoop()
# Changing mtime of header.h should rebuild everything
self.utime(os.path.join(testdir, 'header.h'))
- self.assertRebuiltTarget('prog')
+ self.assertBuildRelinkedOnlyTarget('prog')
def test_custom_target_changes_cause_rebuild(self):
'''
@@ -2602,7 +2632,7 @@ class AllPlatformTests(BasePlatformTests):
# Changing mtime of these should rebuild everything
for f in ('input.def', 'makeheader.py', 'somefile.txt'):
self.utime(os.path.join(testdir, f))
- self.assertRebuiltTarget('prog')
+ self.assertBuildRelinkedOnlyTarget('prog')
def test_source_generator_program_cause_rebuild(self):
'''