aboutsummaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/run_unittests.py b/run_unittests.py
index 5eba222..a90e46b 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -19,6 +19,7 @@ import subprocess
import re, json
import tempfile
from glob import glob
+import mesonbuild.compilers
import mesonbuild.environment
import mesonbuild.mesonlib
from mesonbuild.environment import detect_ninja, Environment
@@ -95,6 +96,62 @@ class InternalTests(unittest.TestCase):
stat.S_IRWXU | stat.S_ISUID |
stat.S_IRGRP | stat.S_IXGRP)
+ def test_compiler_args_class(self):
+ cargsfunc = mesonbuild.compilers.CompilerArgs
+ c = mesonbuild.environment.CCompiler([], 'fake', False)
+ # Test that bad initialization fails
+ self.assertRaises(TypeError, cargsfunc, [])
+ self.assertRaises(TypeError, cargsfunc, [], [])
+ self.assertRaises(TypeError, cargsfunc, c, [], [])
+ # Test that empty initialization works
+ a = cargsfunc(c)
+ self.assertEqual(a, [])
+ # Test that list initialization works
+ a = cargsfunc(['-I.', '-I..'], c)
+ self.assertEqual(a, ['-I.', '-I..'])
+ # Test that there is no de-dup on initialization
+ self.assertEqual(cargsfunc(['-I.', '-I.'], c), ['-I.', '-I.'])
+
+ ## Test that appending works
+ a.append('-I..')
+ self.assertEqual(a, ['-I..', '-I.'])
+ a.append('-O3')
+ self.assertEqual(a, ['-I..', '-I.', '-O3'])
+
+ ## Test that in-place addition works
+ a += ['-O2', '-O2']
+ self.assertEqual(a, ['-I..', '-I.', '-O3', '-O2', '-O2'])
+ # Test that removal works
+ a.remove('-O2')
+ self.assertEqual(a, ['-I..', '-I.', '-O3', '-O2'])
+ # Test that de-dup happens on addition
+ a += ['-Ifoo', '-Ifoo']
+ self.assertEqual(a, ['-Ifoo', '-I..', '-I.', '-O3', '-O2'])
+
+ # .extend() is just +=, so we don't test it
+
+ ## Test that addition works
+ # Test that adding a list with just one old arg works and yields the same array
+ a = a + ['-Ifoo']
+ self.assertEqual(a, ['-Ifoo', '-I..', '-I.', '-O3', '-O2'])
+ # Test that adding a list with one arg new and one old works
+ a = a + ['-Ifoo', '-Ibaz']
+ self.assertEqual(a, ['-Ifoo', '-Ibaz', '-I..', '-I.', '-O3', '-O2'])
+ # Test that adding args that must be prepended and appended works
+ a = a + ['-Ibar', '-Wall']
+ self.assertEqual(a, ['-Ibar', '-Ifoo', '-Ibaz', '-I..', '-I.', '-O3', '-O2', '-Wall'])
+
+ ## Test that reflected addition works
+ # Test that adding to a list with just one old arg works and DOES NOT yield the same array
+ a = ['-Ifoo'] + a
+ self.assertEqual(a, ['-Ibar', '-Ifoo', '-Ibaz', '-I..', '-I.', '-O3', '-O2', '-Wall'])
+ # Test that adding to a list with just one new arg that is not pre-pended works
+ a = ['-Werror'] + a
+ self.assertEqual(a, ['-Ibar', '-Ifoo', '-Ibaz', '-I..', '-I.', '-Werror', '-O3', '-O2', '-Wall'])
+ # Test that adding to a list with two new args preserves the order
+ a = ['-Ldir', '-Lbah'] + a
+ self.assertEqual(a, ['-Ibar', '-Ifoo', '-Ibaz', '-I..', '-I.', '-Ldir', '-Lbah', '-Werror', '-O3', '-O2', '-Wall'])
+
class LinuxlikeTests(unittest.TestCase):
def setUp(self):
@@ -416,7 +473,7 @@ class LinuxlikeTests(unittest.TestCase):
cmd = cmd[1:]
# Verify that -I flags from the `args` kwarg are first
# This is set in the '43 has function' test case
- self.assertEqual(cmd[2], '-I/tmp')
+ self.assertEqual(cmd[1], '-I/tmp')
# Verify that -O3 set via the environment is overriden by -O0
Oargs = [arg for arg in cmd if arg.startswith('-O')]
self.assertEqual(Oargs, [Oflag, '-O0'])