diff options
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/allplatformstests.py | 127 | ||||
-rw-r--r-- | unittests/darwintests.py | 5 | ||||
-rw-r--r-- | unittests/internaltests.py | 4 | ||||
-rw-r--r-- | unittests/linuxliketests.py | 10 | ||||
-rw-r--r-- | unittests/machinefiletests.py | 4 | ||||
-rw-r--r-- | unittests/platformagnostictests.py | 4 | ||||
-rw-r--r-- | unittests/windowstests.py | 3 |
7 files changed, 109 insertions, 48 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 438e4fe..5a6e88b 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -59,6 +59,7 @@ from mesonbuild.linkers import linkers from mesonbuild.dependencies.pkgconfig import PkgConfigDependency from mesonbuild.build import Target, ConfigurationData, Executable, SharedLibrary, StaticLibrary +from mesonbuild import mtest import mesonbuild.modules.pkgconfig from mesonbuild.scripts import destdir_join @@ -398,6 +399,56 @@ class AllPlatformTests(BasePlatformTests): self.assertTrue(compdb[3]['file'].endswith("libfile4.c")) # FIXME: We don't have access to the linker command + def test_replace_unencodable_xml_chars(self): + ''' + Test that unencodable xml chars are replaced with their + printable representation + https://github.com/mesonbuild/meson/issues/9894 + ''' + # Create base string(\nHello Meson\n) to see valid chars are not replaced + base_string_invalid = '\n\x48\x65\x6c\x6c\x6f\x20\x4d\x65\x73\x6f\x6e\n' + base_string_valid = '\nHello Meson\n' + # Create invalid input from all known unencodable chars + invalid_string = ( + '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11' + '\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f' + '\x80\x81\x82\x83\x84\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f' + '\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e' + '\x9f\ufdd0\ufdd1\ufdd2\ufdd3\ufdd4\ufdd5\ufdd6\ufdd7\ufdd8' + '\ufdd9\ufdda\ufddb\ufddc\ufddd\ufdde\ufddf\ufde0\ufde1' + '\ufde2\ufde3\ufde4\ufde5\ufde6\ufde7\ufde8\ufde9\ufdea' + '\ufdeb\ufdec\ufded\ufdee\ufdef\ufffe\uffff') + if sys.maxunicode >= 0x10000: + invalid_string = invalid_string + ( + '\U0001fffe\U0001ffff\U0002fffe\U0002ffff' + '\U0003fffe\U0003ffff\U0004fffe\U0004ffff' + '\U0005fffe\U0005ffff\U0006fffe\U0006ffff' + '\U0007fffe\U0007ffff\U0008fffe\U0008ffff' + '\U0009fffe\U0009ffff\U000afffe\U000affff' + '\U000bfffe\U000bffff\U000cfffe\U000cffff' + '\U000dfffe\U000dffff\U000efffe\U000effff' + '\U000ffffe\U000fffff\U0010fffe\U0010ffff') + + valid_string = base_string_valid + repr(invalid_string)[1:-1] + base_string_valid + invalid_string = base_string_invalid + invalid_string + base_string_invalid + broken_xml_stream = invalid_string.encode() + decoded_broken_stream = mtest.decode(broken_xml_stream) + self.assertEqual(decoded_broken_stream, valid_string) + + def test_replace_unencodable_xml_chars_unit(self): + ''' + Test that unencodable xml chars are replaced with their + printable representation + https://github.com/mesonbuild/meson/issues/9894 + ''' + if not shutil.which('xmllint'): + raise SkipTest('xmllint not installed') + testdir = os.path.join(self.unit_test_dir, '110 replace unencodable xml chars') + self.init(testdir) + self.run_tests() + junit_xml_logs = Path(self.logdir, 'testlog.junit.xml') + subprocess.run(['xmllint', junit_xml_logs], check=True) + def test_run_target_files_path(self): ''' Test that run_targets are run from the correct directory @@ -2164,7 +2215,7 @@ class AllPlatformTests(BasePlatformTests): langs = ['c'] env = get_fake_env() - for l in ['cpp', 'cs', 'd', 'java', 'cuda', 'fortran', 'objc', 'objcpp', 'rust']: + for l in ['cpp', 'cs', 'd', 'java', 'cuda', 'fortran', 'objc', 'objcpp', 'rust', 'vala']: try: comp = detect_compiler_for(env, l, MachineChoice.HOST, True) with tempfile.TemporaryDirectory() as d: @@ -2180,31 +2231,32 @@ class AllPlatformTests(BasePlatformTests): for lang in langs: for target_type in ('executable', 'library'): - if is_windows() and lang == 'fortran' and target_type == 'library': - # non-Gfortran Windows Fortran compilers do not do shared libraries in a Fortran standard way - # see "test cases/fortran/6 dynamic" - fc = detect_compiler_for(env, 'fortran', MachineChoice.HOST, True) - if fc.get_id() in {'intel-cl', 'pgi'}: - continue - # test empty directory - with tempfile.TemporaryDirectory() as tmpdir: - self._run(self.meson_command + ['init', '--language', lang, '--type', target_type], - workdir=tmpdir) - self._run(self.setup_command + ['--backend=ninja', 'builddir'], - workdir=tmpdir) - self._run(ninja, - workdir=os.path.join(tmpdir, 'builddir')) - # test directory with existing code file - if lang in {'c', 'cpp', 'd'}: - with tempfile.TemporaryDirectory() as tmpdir: - with open(os.path.join(tmpdir, 'foo.' + lang), 'w', encoding='utf-8') as f: - f.write('int main(void) {}') - self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) - elif lang in {'java'}: - with tempfile.TemporaryDirectory() as tmpdir: - with open(os.path.join(tmpdir, 'Foo.' + lang), 'w', encoding='utf-8') as f: - f.write('public class Foo { public static void main() {} }') - self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) + with self.subTest(f'Language: {lang}; type: {target_type}'): + if is_windows() and lang == 'fortran' and target_type == 'library': + # non-Gfortran Windows Fortran compilers do not do shared libraries in a Fortran standard way + # see "test cases/fortran/6 dynamic" + fc = detect_compiler_for(env, 'fortran', MachineChoice.HOST, True) + if fc.get_id() in {'intel-cl', 'pgi'}: + continue + # test empty directory + with tempfile.TemporaryDirectory() as tmpdir: + self._run(self.meson_command + ['init', '--language', lang, '--type', target_type], + workdir=tmpdir) + self._run(self.setup_command + ['--backend=ninja', 'builddir'], + workdir=tmpdir) + self._run(ninja, + workdir=os.path.join(tmpdir, 'builddir')) + # test directory with existing code file + if lang in {'c', 'cpp', 'd'}: + with tempfile.TemporaryDirectory() as tmpdir: + with open(os.path.join(tmpdir, 'foo.' + lang), 'w', encoding='utf-8') as f: + f.write('int main(void) {}') + self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) + elif lang in {'java'}: + with tempfile.TemporaryDirectory() as tmpdir: + with open(os.path.join(tmpdir, 'Foo.' + lang), 'w', encoding='utf-8') as f: + f.write('public class Foo { public static void main() {} }') + self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) def test_compiler_run_command(self): ''' @@ -2667,7 +2719,7 @@ class AllPlatformTests(BasePlatformTests): def test_native_dep_pkgconfig(self): testdir = os.path.join(self.unit_test_dir, '45 native dep pkgconfig var') - with tempfile.NamedTemporaryFile(mode='w', delete=False) as crossfile: + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as crossfile: crossfile.write(textwrap.dedent( '''[binaries] pkgconfig = '{}' @@ -2694,7 +2746,7 @@ class AllPlatformTests(BasePlatformTests): def test_pkg_config_libdir(self): testdir = os.path.join(self.unit_test_dir, '45 native dep pkgconfig var') - with tempfile.NamedTemporaryFile(mode='w', delete=False) as crossfile: + with tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as crossfile: crossfile.write(textwrap.dedent( '''[binaries] pkgconfig = 'pkg-config' @@ -4078,7 +4130,8 @@ class AllPlatformTests(BasePlatformTests): ] bar_expected = [ 'bar', - 'share/foo/bar.dat', + 'share/bar', + 'share/bar/bar.dat', 'include/bar.h', 'bin/bar' + exe_suffix, 'bar/barfile' @@ -4145,7 +4198,7 @@ class AllPlatformTests(BasePlatformTests): cmd = self.meson_command + ['devenv', '-C', self.builddir, '--dump', fname] o = self._run(cmd) self.assertEqual(o, '') - o = Path(fname).read_text() + o = Path(fname).read_text(encoding='utf-8') expected = os.pathsep.join(['/prefix', '$TEST_C', '/suffix']) self.assertIn(f'TEST_C="{expected}"', o) self.assertIn('export TEST_C', o) @@ -4358,9 +4411,9 @@ class AllPlatformTests(BasePlatformTests): Path(installpath, 'usr/share/foo2.h'), Path(installpath, 'usr/share/out1.txt'), Path(installpath, 'usr/share/out2.txt'), - Path(installpath, 'usr/share/install tag'), - Path(installpath, 'usr/share/install tag/aaa.txt'), - Path(installpath, 'usr/share/install tag/bbb.txt'), + Path(installpath, 'usr/share/subproject'), + Path(installpath, 'usr/share/subproject/aaa.txt'), + Path(installpath, 'usr/share/subproject/bbb.txt'), } def do_install(tags, expected_files, expected_scripts): @@ -4561,12 +4614,12 @@ class AllPlatformTests(BasePlatformTests): 'subproject': None, }, f'{testdir}/subprojects/subproject/aaa.txt': { - 'destination': '{datadir}/install tag/aaa.txt', + 'destination': '{datadir}/subproject/aaa.txt', 'tag': None, 'subproject': 'subproject', }, f'{testdir}/subprojects/subproject/bbb.txt': { - 'destination': '{datadir}/install tag/bbb.txt', + 'destination': '{datadir}/subproject/bbb.txt', 'tag': 'data', 'subproject': 'subproject', }, @@ -4646,7 +4699,7 @@ class AllPlatformTests(BasePlatformTests): testdir = os.path.join(self.unit_test_dir, '102 rlib linkage') gen_file = os.path.join(testdir, 'lib.rs') - with open(gen_file, 'w') as f: + with open(gen_file, 'w', encoding='utf-8') as f: f.write(template.format(0)) self.addCleanup(windows_proof_rm, gen_file) @@ -4654,7 +4707,7 @@ class AllPlatformTests(BasePlatformTests): self.build() self.run_tests() - with open(gen_file, 'w') as f: + with open(gen_file, 'w', encoding='utf-8') as f: f.write(template.format(39)) self.build() diff --git a/unittests/darwintests.py b/unittests/darwintests.py index 254b3d0..1f17760 100644 --- a/unittests/darwintests.py +++ b/unittests/darwintests.py @@ -148,3 +148,8 @@ class DarwinTests(BasePlatformTests): testdir = os.path.join(self.objcpp_test_dir, '1 simple') self.init(testdir) self.assertIn('-std=c++14', self.get_compdb()[0]['command']) + + def test_darwin_get_object_archs(self): + from mesonbuild.mesonlib import darwin_get_object_archs + archs = darwin_get_object_archs('/System/Library/CoreServices/Encodings/libSymbolConverter.dylib') + self.assertEqual(archs, ['x86_64', 'aarch64']) diff --git a/unittests/internaltests.py b/unittests/internaltests.py index f22adb2..672a5a0 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -453,7 +453,7 @@ class InternalTests(unittest.TestCase): # Can not be used as context manager because we need to # open it a second time and this is not possible on # Windows. - configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False) + configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False, encoding='utf-8') configfilename = configfile.name config.write(configfile) configfile.flush() @@ -469,7 +469,7 @@ class InternalTests(unittest.TestCase): 'needs_exe_wrapper': 'true' if desired_value else 'false' } - configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False) + configfile = tempfile.NamedTemporaryFile(mode='w+', delete=False, encoding='utf-8') configfilename = configfile.name config.write(configfile) configfile.close() diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index 7c4c6ca..7ebb575 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -1039,7 +1039,7 @@ class LinuxlikeTests(BasePlatformTests): def test_cross_find_program(self): testdir = os.path.join(self.unit_test_dir, '11 cross prog') - crossfile = tempfile.NamedTemporaryFile(mode='w') + crossfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8') print(os.path.join(testdir, 'some_cross_tool.py')) tool_path = os.path.join(testdir, 'some_cross_tool.py') @@ -1532,14 +1532,14 @@ class LinuxlikeTests(BasePlatformTests): def test_identity_cross(self): testdir = os.path.join(self.unit_test_dir, '60 identity cross') - constantsfile = tempfile.NamedTemporaryFile(mode='w') + constantsfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8') constantsfile.write(textwrap.dedent('''\ [constants] py_ext = '.py' ''')) constantsfile.flush() - nativefile = tempfile.NamedTemporaryFile(mode='w') + nativefile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8') nativefile.write(textwrap.dedent('''\ [binaries] c = ['{}' + py_ext] @@ -1547,7 +1547,7 @@ class LinuxlikeTests(BasePlatformTests): nativefile.flush() self.meson_native_files = [constantsfile.name, nativefile.name] - crossfile = tempfile.NamedTemporaryFile(mode='w') + crossfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8') crossfile.write(textwrap.dedent('''\ [binaries] c = ['{}' + py_ext] @@ -1564,7 +1564,7 @@ class LinuxlikeTests(BasePlatformTests): 'CC_FOR_BUILD': '"' + os.path.join(testdir, 'build_wrapper.py') + '"', 'CC': '"' + os.path.join(testdir, 'host_wrapper.py') + '"', } - crossfile = tempfile.NamedTemporaryFile(mode='w') + crossfile = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8') crossfile.write('') crossfile.flush() self.meson_cross_files = [crossfile.name] diff --git a/unittests/machinefiletests.py b/unittests/machinefiletests.py index 3807c88..9e71810 100644 --- a/unittests/machinefiletests.py +++ b/unittests/machinefiletests.py @@ -754,7 +754,7 @@ class CrossFileTests(BasePlatformTests): with tempfile.TemporaryDirectory() as d: dir_ = os.path.join(d, 'meson', 'cross') os.makedirs(dir_) - with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f: + with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False, encoding='utf-8') as f: f.write(cross_content) name = os.path.basename(f.name) @@ -770,7 +770,7 @@ class CrossFileTests(BasePlatformTests): with tempfile.TemporaryDirectory() as d: dir_ = os.path.join(d, '.local', 'share', 'meson', 'cross') os.makedirs(dir_) - with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f: + with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False, encoding='utf-8') as f: f.write(cross_content) name = os.path.basename(f.name) diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index a88a514..fd01293 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -246,10 +246,10 @@ class PlatformAgnosticTests(BasePlatformTests): self.init(testdir) self._run(self.meson_command + ['--internal', 'regenerate', '--profile-self', testdir, self.builddir]) - with open(os.path.join(self.builddir, 'meson-logs', 'profile-startup-modules.json')) as f: + with open(os.path.join(self.builddir, 'meson-logs', 'profile-startup-modules.json'), encoding='utf-8') as f: data = json.load(f)['meson'] - with open(os.path.join(testdir, 'expected_mods.json')) as f: + with open(os.path.join(testdir, 'expected_mods.json'), encoding='utf-8') as f: expected = json.load(f)['meson']['modules'] self.assertEqual(data['modules'], expected) diff --git a/unittests/windowstests.py b/unittests/windowstests.py index 37e9299..c201953 100644 --- a/unittests/windowstests.py +++ b/unittests/windowstests.py @@ -462,6 +462,9 @@ class WindowsTests(BasePlatformTests): @unittest.skipIf(is_cygwin(), "Needs visual studio") def test_vsenv_option(self): + if mesonbuild.environment.detect_msys2_arch(): + # https://github.com/msys2-contrib/cpython-mingw/issues/141 + raise SkipTest('mingw python fails with /bin being removed from PATH') if self.backend is not Backend.ninja: raise SkipTest('Only ninja backend is valid for test') env = os.environ.copy() |