def test_identity(self): expected = file_types.ObjectFile(Path('object', Root.srcdir), None) self.assertIs(self.context['object_file'](expected), expected)
def test_install_multiple(self): exe1 = file_types.Executable(Path('exe1', Root.srcdir), None) exe2 = file_types.Executable(Path('exe2', Root.srcdir), None) self.assertEqual(self.builtin_dict['install'](exe1, exe2), (exe1, exe2))
class TestPrecompiledHeader(CompileTest): class MockFile(object): def write(self, data): pass mode = 'pch_compiler' context = { 'pch_source': file_types.SourceFile(Path('main.cpp', Root.srcdir), 'c++') } def test_identity(self): ex = file_types.PrecompiledHeader(Path('header', Root.srcdir), None) self.assertIs(self.builtin_dict['precompiled_header'](ex), ex) def test_src_file(self): expected = file_types.PrecompiledHeader(Path('header', Root.srcdir), 'c') self.assertSameFile(self.builtin_dict['precompiled_header']('header'), expected) def test_make_simple(self): with mock.patch('bfg9000.builtins.file_types.make_immediate_file', return_value=self.MockFile()): pch = self.builtin_dict['precompiled_header'] result = pch(file='main.hpp') self.assertSameFile(result, self.output_file('main.hpp', self.context)) result = pch('object', 'main.hpp') self.assertSameFile(result, self.output_file('object', self.context)) src = self.builtin_dict['header_file']('main.hpp') result = pch('object', src) self.assertSameFile(result, self.output_file('object', self.context)) def test_make_no_lang(self): with mock.patch('bfg9000.builtins.file_types.make_immediate_file', return_value=self.MockFile()): pch = self.builtin_dict['precompiled_header'] result = pch('object', 'main.goofy', lang='c++') self.assertSameFile(result, self.output_file('object', self.context)) self.assertRaises(ValueError, pch, 'object', 'main.goofy') src = self.builtin_dict['header_file']('main.goofy') self.assertRaises(ValueError, pch, 'object', src) def test_make_override_lang(self): with mock.patch('bfg9000.builtins.file_types.make_immediate_file', return_value=self.MockFile()): pch = self.builtin_dict['precompiled_header'] src = self.builtin_dict['header_file']('main.h', 'c') result = pch('object', src, lang='c++') self.assertSameFile(result, self.output_file('object', self.context)) self.assertEqual(result.creator.compiler.lang, 'c++') def test_make_no_name_or_file(self): self.assertRaises(TypeError, self.builtin_dict['precompiled_header']) def test_description(self): result = self.builtin_dict['precompiled_header']( file='main.hpp', description='my description') self.assertEqual(result.creator.description, 'my description')
def test_path(self): self.assertEqual(windows.escape_line(Path('foo')), shell_list([Path('foo')]))
def test_file(self): dist.extra_dist(self.builtin_dict, files='file') self.assertEqual(list(self.build.sources()), [ File(Path('build.bfg', Root.srcdir)), File(Path('file', Root.srcdir)), ])
def test_filled(self): prog = file_types.Executable(Path('prog'), None) self.context['test'](prog) self.assertEqual(bool(self.build['tests']), True)
def test_multiple(self): foo = file_types.Executable(Path('foo'), None) bar = file_types.Executable(Path('bar'), None) self.context['test_deps'](foo, bar) self.assertEqual(self.build['tests'].extra_deps, [foo, bar])
def test_match_extra_exclude(self): f = find._make_filter_from_glob('*', '*.c??', '*.?pp', '*.hpp') self.assertEqual(f(Path('foo.hpp'), 'f'), find.FindResult.exclude) self.assertEqual(f(Path('foo.cpp'), 'f'), find.FindResult.include) self.assertEqual(f(Path('foo.ipp'), 'f'), find.FindResult.not_now)
def test_normal(self): self.assertEqual(self.filter(Path('file.txt'), 'f'), find.FindResult.include)
def test_run_arguments(self): env = self.make_env() src = SourceFile(Path('foo.py'), 'python') self.assertEqual(env.run_arguments([src]), [env.tool('python'), src]) with self.assertRaises(TypeError): env.run_arguments(src, 'nonexist')
def test_exclude(self): f = find._make_filter_from_glob('*', '*.?pp', None, '*.cpp') self.assertEqual(f(Path('foo.hpp'), 'f'), find.FindResult.include) self.assertEqual(f(Path('foo.cpp'), 'f'), find.FindResult.exclude)
def test_supports_destdir(self): env = self.make_env() env.install_dirs = { InstallRoot.prefix: Path('/root/prefix/'), InstallRoot.exec_prefix: Path('', InstallRoot.prefix), InstallRoot.bindir: Path('bin/', InstallRoot.exec_prefix), InstallRoot.libdir: Path('lib/', InstallRoot.exec_prefix), InstallRoot.includedir: Path('include/', InstallRoot.prefix), } self.assertTrue(env.supports_destdir) env = self.make_env() env.install_dirs = { InstallRoot.prefix: Path('C:/root/prefix/'), InstallRoot.exec_prefix: Path('', InstallRoot.prefix), InstallRoot.bindir: Path('bin/', InstallRoot.exec_prefix), InstallRoot.libdir: Path('lib/', InstallRoot.exec_prefix), InstallRoot.includedir: Path('include/', InstallRoot.prefix), } self.assertFalse(env.supports_destdir) env = self.make_env() env.install_dirs = { InstallRoot.prefix: None, InstallRoot.exec_prefix: Path('', InstallRoot.prefix), InstallRoot.bindir: Path('bin/', InstallRoot.exec_prefix), InstallRoot.libdir: Path('lib/', InstallRoot.exec_prefix), InstallRoot.includedir: Path('include/', InstallRoot.prefix), } self.assertFalse(env.supports_destdir)
def make_env(self): env = Environment(Path('bfgdir', Root.srcdir), None, None, Path('/srcdir'), Path('/builddir')) env.install_dirs[InstallRoot.prefix] = Path('/prefix/') env.install_dirs[InstallRoot.exec_prefix] = Path('/exec-prefix/') return env
def test_getitem_string_submodule(self): file_list, files, src_files = self.make_file_list(True, 'dir/') self.assertEqual(file_list['dir/src1'], files[0]) with self.context.push_path(Path('dir/build.bfg', Root.srcdir)): self.assertEqual(file_list['src1'], files[0])
def test_path(self): self.assertEqual(log.format_message(Path('path')), repr(Path('path')))
def srcpath(p): return Path(p, Root.srcdir)
def test_many(self): self.assertEqual(log.format_message('foo', 1, Path('path'), 'bar'), 'foo 1 ' + repr(Path('path')) + ' bar')
def test_listdir(self): with mock_context(): self.assertEqual(find._listdir(Path('.'), path_vars), ( [Path('dir')], [Path('file.cpp')], ))
def test_single(self): prog = file_types.Executable(Path('prog'), None) self.context['test_deps'](prog) self.assertEqual(self.build['tests'].extra_deps, [prog])
def test_not_found(self): def mock_listdir(path): raise OSError() with mock.patch('os.listdir', mock_listdir): self.assertEqual(find._listdir(Path('.'), path_vars), ([], []))
def test_invalid(self): prog = file_types.Executable(Path('prog'), None) driver = self.context['test_driver'](prog) with self.assertRaises(TypeError): self.context['test'](prog, driver=driver, environment={'VAR': 'foo'})
def test_exists(self): with mock_context(): self.assertEqual(list(find._walk_flat(Path('.'), path_vars)), [ (Path('.'), [Path('dir')], [Path('file.cpp')]), ])
def test_dir(self): dist.extra_dist(self.builtin_dict, dirs='dir') self.assertEqual(list(self.build.sources()), [ File(Path('build.bfg', Root.srcdir)), Directory(Path('dir', Root.srcdir)), ])
def test_exists(self): with mock_context(): self.assertEqual(list(find._walk_recursive(Path('.'), path_vars)), [(Path('.'), [Path('dir')], [Path('file.cpp')]), (Path('dir'), [], [Path('dir/file2.txt')])])
def test_install_single(self): exe = file_types.Executable(Path('exe', Root.srcdir), None) self.assertEqual(self.builtin_dict['install'](exe), exe)
def test_not_exists(self): with mock.patch('bfg9000.builtins.find.exists', return_value=False): self.assertEqual(list(find._walk_recursive(Path('.'), path_vars)), [])
def test_invalid(self): phony = file_types.Phony('name') self.assertRaises(TypeError, self.builtin_dict['install'], phony) exe = file_types.Executable(Path('/path/to/exe', Root.absolute), None) self.assertRaises(ValueError, self.builtin_dict['install'], exe)
def test_file(self): f = find._make_filter_from_glob('f', '*', None, None) self.assertEqual(f(Path('foo'), 'f'), find.FindResult.include) self.assertEqual(f(Path('foo'), 'd'), find.FindResult.exclude)
def test_identity(self): ex = file_types.PrecompiledHeader(Path('header', Root.srcdir), None) self.assertIs(self.builtin_dict['precompiled_header'](ex), ex)
def output_file(self, name, pch_source='main.cpp', *args, **kwargs): pch_source_path = Path(name).parent().append(pch_source) step = {'pch_source': file_types.SourceFile(pch_source_path, 'c++')} return super().output_file(name, step, *args, **kwargs)