|
47 | 47 | from mesonbuild.compilers.cpp import VisualStudioCPPCompiler, ClangClCPPCompiler |
48 | 48 | from mesonbuild.compilers import ( |
49 | 49 | detect_static_linker, detect_c_compiler, compiler_from_language, |
50 | | - detect_compiler_for |
| 50 | + detect_compiler_for, lang_suffixes |
51 | 51 | ) |
52 | 52 | from mesonbuild.linkers import linkers |
53 | 53 |
|
@@ -2569,43 +2569,35 @@ def _template_test_dirty(lang, target_type): |
2569 | 2569 | self._run(ninja, |
2570 | 2570 | workdir=os.path.join(tmpdir, 'builddir')) |
2571 | 2571 |
|
| 2572 | + # Check for whether we're doing source collection by repeating |
| 2573 | + # with a bogus file we should pick up (and then fail to compile). |
| 2574 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 2575 | + suffix = lang_suffixes[lang][0] |
| 2576 | + # Assume that this is a good enough string to error out |
| 2577 | + # in all languages. |
| 2578 | + with open(os.path.join(tmpdir, 'bar.' + suffix), 'w', encoding='utf-8') as f: |
| 2579 | + f.write('error bar') |
| 2580 | + self._run(self.meson_command + ['init', '--language', lang, '--type', target_type], |
| 2581 | + workdir=tmpdir) |
| 2582 | + self._run(self.setup_command + ['--backend=ninja', 'builddir'], |
| 2583 | + workdir=tmpdir) |
| 2584 | + with self.assertRaises(subprocess.CalledProcessError): |
| 2585 | + self._run(ninja, |
| 2586 | + workdir=os.path.join(tmpdir, 'builddir')) |
| 2587 | + |
2572 | 2588 | # test directory with existing code file |
2573 | 2589 | if lang in {'c', 'cpp', 'd'}: |
2574 | 2590 | with tempfile.TemporaryDirectory() as tmpdir: |
2575 | 2591 | with open(os.path.join(tmpdir, 'foo.' + lang), 'w', encoding='utf-8') as f: |
2576 | 2592 | f.write('int main(void) {}') |
2577 | 2593 | self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) |
2578 | 2594 |
|
2579 | | - # Check for whether we're doing source collection by repeating |
2580 | | - # with a bogus file we should pick up (and then fail to compile). |
2581 | | - with tempfile.TemporaryDirectory() as tmpdir: |
2582 | | - with open(os.path.join(tmpdir, 'bar.' + lang), 'w', encoding='utf-8') as f: |
2583 | | - f.write('#error bar') |
2584 | | - self._run(self.meson_command + ['init'], workdir=tmpdir) |
2585 | | - self._run(self.setup_command + ['--backend=ninja', 'builddir'], |
2586 | | - workdir=tmpdir) |
2587 | | - with self.assertRaises(subprocess.CalledProcessError): |
2588 | | - self._run(ninja, |
2589 | | - workdir=os.path.join(tmpdir, 'builddir')) |
2590 | | - |
2591 | 2595 | elif lang in {'java'}: |
2592 | 2596 | with tempfile.TemporaryDirectory() as tmpdir: |
2593 | 2597 | with open(os.path.join(tmpdir, 'Foo.' + lang), 'w', encoding='utf-8') as f: |
2594 | 2598 | f.write('public class Foo { public static void main() {} }') |
2595 | 2599 | self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) |
2596 | 2600 |
|
2597 | | - # Check for whether we're doing source collection by repeating |
2598 | | - # with a bogus file we should pick up (and then fail to compile). |
2599 | | - with tempfile.TemporaryDirectory() as tmpdir: |
2600 | | - with open(os.path.join(tmpdir, 'Bar.' + lang), 'w', encoding='utf-8') as f: |
2601 | | - f.write('public class Bar { public private static void main() {} }') |
2602 | | - self._run(self.meson_command + ['init'], workdir=tmpdir) |
2603 | | - self._run(self.setup_command + ['--backend=ninja', 'builddir'], |
2604 | | - workdir=tmpdir) |
2605 | | - with self.assertRaises(subprocess.CalledProcessError): |
2606 | | - self._run(ninja, |
2607 | | - workdir=os.path.join(tmpdir, 'builddir')) |
2608 | | - |
2609 | 2601 | for lang, target_type, fresh in itertools.product(langs, ('executable', 'library'), (True, False)): |
2610 | 2602 | with self.subTest(f'Language: {lang}; type: {target_type}; fresh: {fresh}'): |
2611 | 2603 | _template_test_fresh(lang, target_type) if fresh else _template_test_dirty(lang, target_type) |
|
0 commit comments