diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-11-29 03:36:35 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-04 00:33:48 +0530 |
commit | 025d699c002ab9e0c1823dce3e526b70c0fc2280 (patch) | |
tree | defbebda7c97d36d261579fd9fe25e44a23c7cee /run_unittests.py | |
parent | cee9638cc43682b6e371cc2becae745876c73bda (diff) | |
download | meson-025d699c002ab9e0c1823dce3e526b70c0fc2280.tar.gz |
unit tests: Use universal_newlines everywhere
This approach is locale-independent and more correct. For instance, this
will work with UTF-16 while the previous approach with binary comparison
would not.
This also removes the need for doing an explicit decode to utf-8 which
is lossy and can fail by yielding no output at all.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/run_unittests.py b/run_unittests.py index b8d23b88a..cc105f297 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -24,9 +24,10 @@ from mesonbuild.dependencies import PkgConfigDependency, Qt5Dependency 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'): + raw_out = subprocess.check_output(['readelf', '-a', fname], + universal_newlines=True) + pattern = re.compile('soname: \[(.*?)\]') + for line in raw_out.split('\n'): m = pattern.search(line) if m is not None: return m.group(1) @@ -105,8 +106,9 @@ class LinuxlikeTests(unittest.TestCase): return cmds def introspect(self, arg): - out = subprocess.check_output(self.mintro_command + [arg, self.builddir]) - return json.loads(out.decode('utf-8')) + out = subprocess.check_output(self.mintro_command + [arg, self.builddir], + universal_newlines=True) + return json.loads(out) def test_basic_soname(self): testdir = os.path.join(self.common_test_dir, '4 shared') @@ -114,7 +116,7 @@ class LinuxlikeTests(unittest.TestCase): self.build() lib1 = os.path.join(self.builddir, 'libmylib.so') soname = get_soname(lib1) - self.assertEqual(soname, b'libmylib.so') + self.assertEqual(soname, 'libmylib.so') def test_custom_soname(self): testdir = os.path.join(self.common_test_dir, '27 library versions') @@ -122,7 +124,7 @@ class LinuxlikeTests(unittest.TestCase): self.build() lib1 = os.path.join(self.builddir, 'prefixsomelib.suffix') soname = get_soname(lib1) - self.assertEqual(soname, b'prefixsomelib.suffix') + self.assertEqual(soname, 'prefixsomelib.suffix') def test_pic(self): testdir = os.path.join(self.common_test_dir, '3 static') @@ -225,8 +227,9 @@ class LinuxlikeTests(unittest.TestCase): self.assertTrue(msg in mesonlog or msg2 in mesonlog) def get_soname(self, fname): - output = subprocess.check_output(['readelf', '-a', fname]) - for line in output.decode('utf-8', errors='ignore').split('\n'): + output = subprocess.check_output(['readelf', '-a', fname], + universal_newlines=True) + for line in output.split('\n'): if 'SONAME' in line: return line.split('[')[1].split(']')[0] raise RuntimeError('Readelf gave no SONAME.') |