diff options
| author | Sam James <sam@gentoo.org> | 2025-11-22 19:06:22 +0000 |
|---|---|---|
| committer | Jussi Pakkanen <jussi.pakkanen@mailbox.org> | 2025-11-23 17:01:13 +0200 |
| commit | 9104bb616766bd9a05f0b2f280359463d32e227d (patch) | |
| tree | b575d6f9cf74c13848e026a9d42267c973543ed7 /unittests | |
| parent | 06242bc6f47b25c19f91c76897ada39cd425015f (diff) | |
| download | meson-9104bb616766bd9a05f0b2f280359463d32e227d.tar.gz | |
templates: respect parameters
Respect collected sources for `meson init` as well as --executable. This
regressed in 9f0ac314ba0c54cc18c2499845324efc14c1849e (part of
https://github.com/mesonbuild/meson/pull/14086, it's easier to see how with
the whole PR).
Also, add subtests (distinguishing between empty directories and those with some
file(s) within). We already had some of these but they weren't marked
as such.
Test `meson init` with a broken source file in the source directory as
we should fail with that, not ignore the file.
It's easier to test with a broken file than a working one as we can assert
the build should fail, it'll pass with just the 1 example file we generate.
Closes: https://github.com/mesonbuild/meson/issues/15286
Diffstat (limited to 'unittests')
| -rw-r--r-- | unittests/allplatformstests.py | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 385b195ea..acf679541 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -2525,7 +2525,7 @@ class AllPlatformTests(BasePlatformTests): for lang in langs: for target_type in ('executable', 'library'): - with self.subTest(f'Language: {lang}; type: {target_type}'): + with self.subTest(f'Language: {lang}; type: {target_type}; fresh: yes'): 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" @@ -2540,17 +2540,44 @@ class AllPlatformTests(BasePlatformTests): 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}; fresh: no'): + # 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) + + # 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')) def test_compiler_run_command(self): ''' |
