diff options
Diffstat (limited to 'unittests/allplatformstests.py')
| -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): ''' |
