Beispiel #1
0
 def test_identity(self):
     expected = file_types.ObjectFile(Path('object', Root.srcdir), None)
     self.assertIs(self.context['object_file'](expected), expected)
Beispiel #2
0
 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))
Beispiel #3
0
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')
Beispiel #4
0
 def test_path(self):
     self.assertEqual(windows.escape_line(Path('foo')),
                      shell_list([Path('foo')]))
Beispiel #5
0
 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)),
     ])
Beispiel #6
0
 def test_filled(self):
     prog = file_types.Executable(Path('prog'), None)
     self.context['test'](prog)
     self.assertEqual(bool(self.build['tests']), True)
Beispiel #7
0
 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])
Beispiel #8
0
 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)
Beispiel #9
0
 def test_normal(self):
     self.assertEqual(self.filter(Path('file.txt'), 'f'),
                      find.FindResult.include)
Beispiel #10
0
 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')
Beispiel #11
0
 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)
Beispiel #12
0
    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)
Beispiel #13
0
 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
Beispiel #14
0
 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])
Beispiel #15
0
 def test_path(self):
     self.assertEqual(log.format_message(Path('path')),
                      repr(Path('path')))
Beispiel #16
0
def srcpath(p):
    return Path(p, Root.srcdir)
Beispiel #17
0
 def test_many(self):
     self.assertEqual(log.format_message('foo', 1, Path('path'), 'bar'),
                      'foo 1 ' + repr(Path('path')) + ' bar')
Beispiel #18
0
 def test_listdir(self):
     with mock_context():
         self.assertEqual(find._listdir(Path('.'), path_vars), (
             [Path('dir')],
             [Path('file.cpp')],
         ))
Beispiel #19
0
 def test_single(self):
     prog = file_types.Executable(Path('prog'), None)
     self.context['test_deps'](prog)
     self.assertEqual(self.build['tests'].extra_deps, [prog])
Beispiel #20
0
    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), ([], []))
Beispiel #21
0
 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'})
Beispiel #22
0
 def test_exists(self):
     with mock_context():
         self.assertEqual(list(find._walk_flat(Path('.'), path_vars)), [
             (Path('.'), [Path('dir')], [Path('file.cpp')]),
         ])
Beispiel #23
0
 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)),
     ])
Beispiel #24
0
 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')])])
Beispiel #25
0
 def test_install_single(self):
     exe = file_types.Executable(Path('exe', Root.srcdir), None)
     self.assertEqual(self.builtin_dict['install'](exe), exe)
Beispiel #26
0
 def test_not_exists(self):
     with mock.patch('bfg9000.builtins.find.exists', return_value=False):
         self.assertEqual(list(find._walk_recursive(Path('.'), path_vars)),
                          [])
Beispiel #27
0
    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)
Beispiel #28
0
 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)
Beispiel #29
0
 def test_identity(self):
     ex = file_types.PrecompiledHeader(Path('header', Root.srcdir), None)
     self.assertIs(self.builtin_dict['precompiled_header'](ex), ex)
Beispiel #30
0
 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)