summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2025-11-23 20:52:21 +0000
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-12-01 16:55:18 +0200
commitaed2444f75d2089872d37ad8c608321e39b2aa78 (patch)
tree17f3cf7be97f506faa9e629040849e24b0ace2fe /unittests
parent176edafdd6dd5549525223539dbc7f4a1f74ee24 (diff)
downloadmeson-aed2444f75d2089872d37ad8c608321e39b2aa78.tar.gz
templates: fix remaining languages for source file discovery too
I missed this in 9104bb616766bd9a05f0b2f280359463d32e227d as we were only testing whitelisted languages for source file discovery. Tests now handle all of these by using the map we have in compilers, as we need to know the suffix to use for the invalid source files we inject. Note that for tests, we mix explicit --lang in some cases and not others, which we could probably do better with. For these 'must fail' tests, I've stuck with explicit `--lang` to make sure we're testing what we want, but the others are perhaps up for debate. Bug: https://github.com/mesonbuild/meson/issues/15286
Diffstat (limited to 'unittests')
-rw-r--r--unittests/allplatformstests.py61
1 files changed, 24 insertions, 37 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 93fde1824..1304658da 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -47,7 +47,7 @@ from mesonbuild.compilers.c import VisualStudioCCompiler, ClangClCCompiler
from mesonbuild.compilers.cpp import VisualStudioCPPCompiler, ClangClCPPCompiler
from mesonbuild.compilers import (
detect_static_linker, detect_c_compiler, compiler_from_language,
- detect_compiler_for
+ detect_compiler_for, lang_suffixes
)
from mesonbuild.linkers import linkers
@@ -2536,20 +2536,17 @@ class AllPlatformTests(BasePlatformTests):
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'))
+ self._run(self.setup_command + ['--backend=ninja', 'builddir'], workdir=tmpdir)
+ self._run(ninja, workdir=os.path.join(tmpdir, 'builddir'))
# custom executable name
if target_type == 'executable':
with tempfile.TemporaryDirectory() as tmpdir:
self._run(self.meson_command + ['init', '--language', lang, '--type', target_type,
- '--executable', 'foobar'], workdir=tmpdir)
- self._run(self.setup_command + ['--backend=ninja', 'builddir'],
- workdir=tmpdir)
- self._run(ninja,
- workdir=os.path.join(tmpdir, 'builddir'))
+ '--executable', 'foobar'],
+ workdir=tmpdir)
+ self._run(self.setup_command + ['--backend=ninja', 'builddir'], workdir=tmpdir)
+ self._run(ninja, workdir=os.path.join(tmpdir, 'builddir'))
if lang not in {'cs', 'java'}:
exe = os.path.join(tmpdir, 'builddir', 'foobar' + exe_suffix)
@@ -2566,10 +2563,24 @@ class AllPlatformTests(BasePlatformTests):
# test empty directory
with tempfile.TemporaryDirectory() as tmpdir:
self._run(self.meson_command + ['init', '--language', lang, '--type', target_type],
- workdir=tmpdir)
+ workdir=tmpdir)
+ self._run(self.setup_command + ['--backend=ninja', 'builddir'], workdir=tmpdir)
+ self._run(ninja, workdir=os.path.join(tmpdir, 'builddir'))
+
+ # Check for whether we're doing source collection by repeating
+ # with a bogus file we should pick up (and then fail to compile).
+ with tempfile.TemporaryDirectory() as tmpdir:
+ suffix = lang_suffixes[lang][0]
+ # Assume that this is a good enough string to error out
+ # in all languages.
+ with open(os.path.join(tmpdir, 'bar.' + suffix), 'w', encoding='utf-8') as f:
+ f.write('error bar')
+ 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=tmpdir)
+ with self.assertRaises(subprocess.CalledProcessError):
+ self._run(ninja,
workdir=os.path.join(tmpdir, 'builddir'))
# test directory with existing code file
@@ -2579,36 +2590,12 @@ class AllPlatformTests(BasePlatformTests):
f.write('int main(void) {}')
self._run(self.meson_command + ['init', '-b'], workdir=tmpdir)
- # Check for whether we're doing source collection by repeating
- # with a bogus file we should pick up (and then fail to compile).
- with tempfile.TemporaryDirectory() as tmpdir:
- with open(os.path.join(tmpdir, 'bar.' + lang), 'w', encoding='utf-8') as f:
- f.write('#error bar')
- self._run(self.meson_command + ['init'], workdir=tmpdir)
- self._run(self.setup_command + ['--backend=ninja', 'builddir'],
- workdir=tmpdir)
- with self.assertRaises(subprocess.CalledProcessError):
- self._run(ninja,
- workdir=os.path.join(tmpdir, 'builddir'))
-
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)
- # Check for whether we're doing source collection by repeating
- # with a bogus file we should pick up (and then fail to compile).
- with tempfile.TemporaryDirectory() as tmpdir:
- with open(os.path.join(tmpdir, 'Bar.' + lang), 'w', encoding='utf-8') as f:
- f.write('public class Bar { public private static void main() {} }')
- self._run(self.meson_command + ['init'], workdir=tmpdir)
- self._run(self.setup_command + ['--backend=ninja', 'builddir'],
- workdir=tmpdir)
- with self.assertRaises(subprocess.CalledProcessError):
- self._run(ninja,
- workdir=os.path.join(tmpdir, 'builddir'))
-
for lang, target_type, fresh in itertools.product(langs, ('executable', 'library'), (True, False)):
with self.subTest(f'Language: {lang}; type: {target_type}; fresh: {fresh}'):
_template_test_fresh(lang, target_type) if fresh else _template_test_dirty(lang, target_type)