summaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-01-30 02:53:35 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2017-01-30 03:19:31 +0530
commitbb491735a980d9124078ac032a5281e648027de7 (patch)
tree12891bd7f7427089fee1a392c9940a98a54bdfde /run_unittests.py
parent66fbcde96e4dd3782d5289b4faf2479335bdf7b1 (diff)
downloadmeson-bb491735a980d9124078ac032a5281e648027de7.tar.gz
coredata: Use our own implementation of commonpath
os.path.commonpath was added in Python 3.5, so just write our own for now. pathlib was added in Python 3.4, so this should be ok. We need to use that instead of doing str.split() etc because Windows path handling has a lot of exceptions and pathlib handles all that for us. Also adds a unit test for this.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py
index a1d99f392..e8659f40a 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -153,6 +153,23 @@ class InternalTests(unittest.TestCase):
a = ['-Ldir', '-Lbah'] + a
self.assertEqual(a, ['-Ibar', '-Ifoo', '-Ibaz', '-I..', '-I.', '-Ldir', '-Lbah', '-Werror', '-O3', '-O2', '-Wall'])
+ def test_commonpath(self):
+ from os.path import sep
+ commonpath = mesonbuild.mesonlib.commonpath
+ self.assertRaises(ValueError, commonpath, [])
+ self.assertEqual(commonpath(['/usr', '/usr']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr', '/usr/']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr', '/usr/bin']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr/', '/usr/bin']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr/./', '/usr/bin']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr/bin', '/usr/bin']), sep + 'usr' + sep + 'bin')
+ self.assertEqual(commonpath(['/usr//bin', '/usr/bin']), sep + 'usr' + sep + 'bin')
+ self.assertEqual(commonpath(['/usr/./bin', '/usr/bin']), sep + 'usr' + sep + 'bin')
+ self.assertEqual(commonpath(['/usr/local', '/usr/lib']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr', '/bin']), sep)
+ self.assertEqual(commonpath(['/usr', 'bin']), '')
+ self.assertEqual(commonpath(['blam', 'bin']), '')
+
class LinuxlikeTests(unittest.TestCase):
def setUp(self):