diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-10-09 23:28:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-09 23:28:18 +0300 |
commit | 933ad618dc30c6ebdafe1abe457ba32c70ebfd99 (patch) | |
tree | f5c3b67cc9551308b46208fe445a76169a58e7dd /run_unittests.py | |
parent | 6c50253645dad81afbfd2e1bca2c5d9e08f42e05 (diff) | |
parent | f90bfa5245ee84315657c0b8898a6046ea05b4f1 (diff) | |
download | meson-933ad618dc30c6ebdafe1abe457ba32c70ebfd99.zip meson-933ad618dc30c6ebdafe1abe457ba32c70ebfd99.tar.gz meson-933ad618dc30c6ebdafe1abe457ba32c70ebfd99.tar.bz2 |
Merge pull request #795 from mesonbuild/unittest
Create a framework for unit tests.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py new file mode 100755 index 0000000..644a31a --- /dev/null +++ b/run_unittests.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# Copyright 2016 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest, os, sys, shutil +import subprocess +import re +import tempfile +from mesonbuild.environment import detect_ninja + +def get_soname(fname): + # HACK, fix to not use shell. + raw_out = subprocess.check_output(['readelf', '-a', fname]) + pattern = re.compile(b'soname: \[(.*?)\]') + for line in raw_out.split(b'\n'): + m = pattern.search(line) + if m is not None: + return m.group(1) + +class LinuxlikeTests(unittest.TestCase): + + def setUp(self): + super().setUp() + src_root = os.path.dirname(__file__) + self.builddir = tempfile.mkdtemp() + self.meson_command = [sys.executable, os.path.join(src_root, 'meson.py')] + self.ninja_command = [detect_ninja(), '-C', self.builddir] + self.common_test_dir = os.path.join(src_root, 'test cases/common') + self.output = b'' + + def tearDown(self): + shutil.rmtree(self.builddir) + super().tearDown() + + def init(self, srcdir): + self.output += subprocess.check_output(self.meson_command + [srcdir, self.builddir]) + + def build(self): + self.output += subprocess.check_output(self.ninja_command) + + def test_basic_soname(self): + testdir = os.path.join(self.common_test_dir, '4 shared') + self.init(testdir) + self.build() + lib1 = os.path.join(self.builddir, 'libmylib.so') + soname = get_soname(lib1) + self.assertEqual(soname, b'libmylib.so') + + def test_custom_soname(self): + testdir = os.path.join(self.common_test_dir, '27 library versions') + self.init(testdir) + self.build() + lib1 = os.path.join(self.builddir, 'prefixsomelib.suffix') + soname = get_soname(lib1) + self.assertEqual(soname, b'prefixsomelib.suffix') + +if __name__ == '__main__': + unittest.main() |