Exemplo n.º 1
0
    def test_submodule(self):
        with self.context.push_path(Path('dir/build.bfg', Root.srcdir)):
            expected = SourceFile(srcpath('file.cpp'), 'c++')
            self.assertIs(self.context['auto_file'](expected), expected)
            self.assertEqual(list(self.build.sources()), [self.bfgfile])

            expected = SourceFile(srcpath('dir/file.cpp'), 'c++')
            self.assertSameFile(self.context['auto_file']('file.cpp'),
                                expected)
            self.assertEqual(list(self.build.sources()),
                             [self.bfgfile, expected])
Exemplo n.º 2
0
    def test_case(self):
        prog = file_types.Executable(Path('prog'), None)
        driver = self.context['test_driver'](prog)
        case = self.context['test'](prog, driver=driver)

        self.assertEqual(driver.cmd, [prog])
        self.assertEqual(driver.inputs, [])
        self.assertEqual(driver.env, {})
        self.assertEqual(driver.tests, [case])
        self.assertEqual(driver.wrap_children, False)
        self.assertEqual(self.build['tests'].tests, [driver])
Exemplo n.º 3
0
    def test_submodule(self):
        with self.context.push_path(Path('dir/build.bfg', Root.srcdir)):
            expected = self.type(srcpath(self.filename), *self.args)
            self.assertIs(self.context[self.fn](expected), expected)
            self.assertEqual(list(self.build.sources()), [self.bfgfile])

            expected = self.type(srcpath('dir/' + self.filename), *self.args)
            self.assertSameFile(self.context[self.fn](self.filename),
                                expected)
            self.assertEqual(list(self.build.sources()),
                             [self.bfgfile, expected])
Exemplo n.º 4
0
    def test_default(self):
        with mock.patch('logging.log') as mocklog:
            log.log_stack(log.INFO, 'message')
            tb = traceback.extract_stack()[1:]
            tb[-1].lineno -= 1

            mocklog.assert_called_once_with(
                log.INFO, 'message',
                extra={'full_stack': tb, 'show_stack': True}
            )

        with mock.patch('logging.log') as mocklog:
            log.log_message(log.INFO, 'foo', 1, Path('path'), 'bar')
            tb = traceback.extract_stack()[1:]
            tb[-1].lineno -= 1

            mocklog.assert_called_once_with(
                log.INFO, 'foo 1 ' + repr(Path('path')) + ' bar',
                extra={'full_stack': tb, 'show_stack': True}
            )
Exemplo n.º 5
0
    def test_src_file(self):
        self.env.library_mode = LibraryMode(True, True)
        expected = file_types.StaticLibrary(
            Path('library', Root.srcdir),
            self.env.target_platform.object_format, 'c')
        self.assertSameFile(self.context['library']('library'), expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile, expected])

        self.context['project'](lang='c++')
        expected.lang = 'c++'
        self.assertSameFile(self.context['library']('library'), expected)
Exemplo n.º 6
0
    def test_path(self):
        p1 = Path('foo')
        p2 = Path('foo', Root.srcdir)
        p3 = Path('/foo', Root.absolute)

        self.assertEqual(textify(p1), '$(OutDir)foo')
        self.assertEqual(textify(p1, quoted=True), '"$(OutDir)foo"')
        self.assertEqual(textify(p2), '$(SourceDir)foo')
        self.assertEqual(textify(p2, quoted=True), '"$(SourceDir)foo"')
        self.assertEqual(textify(p3), r'\foo')
        self.assertEqual(textify(p3, quoted=True), r'\foo')

        self.assertEqual(textify(p1, builddir=BuildDir.intermediate),
                         '$(IntDir)foo')
        self.assertEqual(textify(p2, builddir=BuildDir.intermediate),
                         '$(SourceDir)foo')
        self.assertEqual(textify(p1, builddir=BuildDir.solution),
                         '$(SolutionDir)foo')
        self.assertEqual(textify(p2, builddir=BuildDir.solution),
                         '$(SourceDir)foo')
Exemplo n.º 7
0
    def test_no_output(self):
        file = file_types.File(Path('foo.c', Root.srcdir))
        self.compdb.append(file=file, command='cc foo.c')

        self.assertEqual(self._db_to_json(), [
            {
                'directory': self.env.builddir.string(),
                'command': 'cc foo.c',
                'file': file.path.string(self.base_dirs)
            },
        ])
Exemplo n.º 8
0
    def test_dir_sentinel(self):
        makefile = mock.Mock()
        src = self.context['generic_file']('dir/file.txt')

        result = self.context['copy_file'](file=src)
        _copy_file.make_copy_file(result.creator, self.build, makefile,
                                  self.env)
        makefile.rule.assert_called_once_with(
            target=[result], deps=[src], order_only=[Path('dir/.dir')],
            recipe=AlwaysEqual()
        )
Exemplo n.º 9
0
    def test_src_file(self):
        expected = file_types.Executable(
            Path('exe', Root.srcdir),
            self.env.target_platform.object_format, 'c'
        )
        self.assertSameFile(self.builtin_dict['executable']('exe'), expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile, expected])

        self.builtin_dict['project'](lang='c++')
        expected.lang = 'c++'
        self.assertSameFile(self.builtin_dict['executable']('exe'), expected)
Exemplo n.º 10
0
 def test_flags_include_dir(self):
     p = Path('/path/to/include')
     self.assertEqual(
         self.compiler.flags(
             opts.option_list(
                 opts.include_dir(file_types.HeaderDirectory(p)))),
         ['/I' + p])
     self.assertEqual(
         self.compiler.flags(opts.option_list(
             opts.include_dir(file_types.HeaderDirectory(p))),
                             mode='pkg-config'), ['-I' + p])
Exemplo n.º 11
0
    def test_src_file(self):
        expected = file_types.SharedLibrary(
            Path('shared', Root.srcdir),
            self.env.target_platform.object_format, 'c'
        )
        self.assertSameFile(self.context['shared_library']('shared'),
                            expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile, expected])

        self.context['project'](lang='c++')
        expected.lang = 'c++'
        self.assertSameFile(self.context['shared_library']('shared'), expected)
Exemplo n.º 12
0
 def test_executable(self):
     self.assertEqual(
         post_install(
             self.env,
             opts.option_list(
                 opts.install_name_change('/lib/libfoo.dylib',
                                          '/lib/libbar.dylib')), self.exe,
             self.install_db),
         [
             self.tool, '-change', '/lib/libfoo.dylib', '/lib/libbar.dylib',
             Path('exe', InstallRoot.bindir, True)
         ])
Exemplo n.º 13
0
    def test_make_simple(self):
        class Context(object):
            langs = ['c++']

        linker = self.env.builder('c++').linker('static_library')

        result = self.builtin_dict['static_library']('static', ['main.cpp'])
        self.assertEqual(result, self.output_file(linker, 'static', Context()))

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        result = self.builtin_dict['static_library']('static', [src])
        self.assertEqual(result, self.output_file(linker, 'static', Context()))
Exemplo n.º 14
0
    def test_src_file(self):
        expected = file_types.PrecompiledHeader(
            Path('header', Root.srcdir), 'c'
        )
        self.assertSameFile(self.context['precompiled_header']('header'),
                            expected)
        self.assertEqual(list(self.build.sources()), [self.bfgfile, expected])

        self.context['project'](lang='c++')
        expected.lang = 'c++'
        self.assertSameFile(self.context['precompiled_header']('header'),
                            expected)
Exemplo n.º 15
0
    def test_buildpath(self):
        src = Path('foo/bar', Root.srcdir)
        build = Path('foo/bar')

        self.assertIs(path.buildpath(self.context, src), src)
        self.assertRaises(ValueError, path.buildpath, self.context, src, True)
        self.assertIs(path.buildpath(self.context, build), build)
        self.assertIs(path.buildpath(self.context, build, True), build)

        self.assertEqual(path.buildpath(self.context, 'foo/bar'), build)
        self.assertEqual(path.buildpath(self.context, 'foo/bar', True), build)

        with self.context.push_path(Path('foo/build.bfg', Root.srcdir)):
            self.assertIs(path.buildpath(self.context, src), src)
            self.assertRaises(ValueError, path.buildpath, self.context, src,
                              True)
            self.assertIs(path.buildpath(self.context, build), build)
            self.assertIs(path.buildpath(self.context, build, True), build)

            self.assertEqual(path.buildpath(self.context, 'bar'), build)
            self.assertEqual(path.buildpath(self.context, 'bar', True), build)
Exemplo n.º 16
0
    def test_output_file(self):
        src = SourceFile(Path('file.tab.c'), 'c')
        hdr = HeaderFile(Path('file.tab.h'), 'c')

        self.assertEqual(self.compiler.output_file('file.tab.c', None), src)
        self.assertEqual(self.compiler.output_file(
            ['file.tab.c', 'file.tab.h'], None
        ), [src, hdr])

        src = SourceFile(Path('file.tab.cpp'), 'c++')
        hdr = HeaderFile(Path('file.tab.hpp'), 'c++')
        context = AttrDict(user_options=opts.option_list(opts.lang('c++')))
        self.assertEqual(self.compiler.output_file('file.tab.cpp', context),
                         src)
        self.assertEqual(self.compiler.output_file(
            ['file.tab.cpp', 'file.tab.hpp'], context
        ), [src, hdr])

        with self.assertRaises(ValueError):
            self.compiler.output_file(['file.tab.c', 'file.tab.h', 'extra'],
                                      None)
Exemplo n.º 17
0
    def test_creator(self):
        prog = file_types.Executable(Path('prog'), None)
        prog.creator = 'creator'
        driver = self.builtin_dict['test_driver'](prog)
        case = self.builtin_dict['test'](prog, driver=driver)

        self.assertEqual(driver.cmd, [prog])
        self.assertEqual(driver.inputs, [prog])
        self.assertEqual(driver.env, {})
        self.assertEqual(driver.tests, [case])
        self.assertEqual(driver.wrap_children, False)
        self.assertEqual(self.build['tests'].tests, [driver])
Exemplo n.º 18
0
    def test_submodule(self):
        with self.context.push_path(Path('dir/build.bfg', Root.srcdir)):
            expected = [File(srcpath('dir/file2.txt'))]
            self.assertFound(self.find('**'), expected)
            self.assertFindDirs({srcpath('dir/'), srcpath('dir/sub/')})

            expected = [
                Directory(srcpath('dir/')),
                Directory(srcpath('dir/sub'))
            ]
            self.assertFound(self.find('**/'), expected)
            self.assertFindDirs({srcpath('dir/'), srcpath('dir/sub/')})
Exemplo n.º 19
0
    def test_default_name(self):
        src = SourceFile(Path('file.l', Root.srcdir), 'yacc')
        self.assertEqual(self.compiler.default_name(src, None),
                         ['file.tab.c', 'file.tab.h'])
        self.assertEqual(self.compiler.default_name(src, AttrDict(
            user_options=opts.option_list(opts.lang('c++'))
        )), ['file.tab.cpp', 'file.tab.hpp'])

        with self.assertRaises(ValueError):
            self.compiler.default_name(src, AttrDict(
                user_options=opts.option_list(opts.lang('java'))
            ))
Exemplo n.º 20
0
    def test_make_simple(self):
        compiler = self.env.builder('c++').compiler

        result = self.builtin_dict['object_file'](file='main.cpp')
        self.assertEqual(result, self.output_file(compiler, 'main', None))

        result = self.builtin_dict['object_file']('object', 'main.cpp')
        self.assertEqual(result, self.output_file(compiler, 'object', None))

        src = file_types.SourceFile(Path('main.cpp', Root.srcdir))
        result = self.builtin_dict['object_file']('object', src)
        self.assertEqual(result, self.output_file(compiler, 'object', None))
Exemplo n.º 21
0
    def test_path_exists(self):
        def mock_exists(p, variables=None):
            return p.suffix == 'exists.txt'

        with mock.patch('bfg9000.path.exists', mock_exists):
            self.assertTrue(self.context['path_exists']('exists.txt'))
            self.assertFalse(self.context['path_exists']('nonexist.txt'))

            with self.context.push_path(Path('foo/build.bfg', Root.srcdir)):
                self.assertTrue(self.context['path_exists']('../exists.txt'))
                self.assertFalse(self.context['path_exists']('exists.txt'))
                self.assertFalse(self.context['path_exists']('nonexist.txt'))
Exemplo n.º 22
0
    def test_includes(self):
        object_file = self.builtin_dict['object_file']

        result = object_file(file='main.cpp', includes='include')
        self.assertEqual(
            result.creator.includes,
            [file_types.HeaderDirectory(Path('include', Root.srcdir))])
        self.assertEqual(result.creator.include_deps, [])

        hdr = self.builtin_dict['header_file']('include/main.hpp')
        result = object_file(file='main.cpp', includes=hdr)
        self.assertEqual(
            result.creator.includes,
            [file_types.HeaderDirectory(Path('include', Root.srcdir))])
        self.assertEqual(result.creator.include_deps, [hdr])

        inc = self.builtin_dict['header_directory']('include')
        inc.creator = 'foo'
        result = object_file(file='main.cpp', includes=inc)
        self.assertEqual(result.creator.includes, [inc])
        self.assertEqual(result.creator.include_deps, [inc])
Exemplo n.º 23
0
    def test_auto_generate_source(self):
        result = self.context['object_file'](file='main.qrc')
        intermediate = result.creator.file
        self.assertSameFile(result, self.output_file('main'))
        self.assertSameFile(intermediate, file_types.SourceFile(
            Path('main.cpp'), lang='c++'
        ))
        self.assertSameFile(intermediate.creator.file, file_types.SourceFile(
            Path('main.qrc', Root.srcdir), lang='qrc'
        ))

        src = self.context['auto_file']('main.hpp', lang='qtmoc')
        result = self.context['object_file'](file=src)
        intermediate = result.creator.file
        self.assertSameFile(result, self.output_file('moc_main'))
        self.assertSameFile(intermediate, file_types.SourceFile(
            Path('moc_main.cpp', Root.builddir), lang='c++'
        ))
        self.assertSameFile(intermediate.creator.file, file_types.HeaderFile(
            Path('main.hpp', Root.srcdir), lang='qtmoc'
        ))

        result = self.context['object_file'](file='main.qrc', directory='dir')
        intermediate = result.creator.file
        self.assertSameFile(result, self.output_file('dir/main'))
        self.assertSameFile(intermediate, file_types.SourceFile(
            Path('dir/main.cpp'), lang='c++'
        ))
        self.assertSameFile(intermediate.creator.file, file_types.SourceFile(
            Path('main.qrc', Root.srcdir), lang='qrc'
        ))
Exemplo n.º 24
0
    def test_installify_header(self):
        self._check(HeaderFile,
                    Path('foo/bar.hpp', Root.srcdir),
                    Path('bar.hpp', InstallRoot.includedir, True),
                    lang='c++')
        self._check(HeaderFile,
                    Path('foo/bar.hpp', Root.builddir),
                    Path('foo/bar.hpp', InstallRoot.includedir, True),
                    lang='c++')

        self._check(HeaderDirectory, Path('foo/bar', Root.srcdir),
                    Path('', InstallRoot.includedir, True))
        self._check(HeaderDirectory, Path('foo/bar', Root.builddir),
                    Path('', InstallRoot.includedir, True))
Exemplo n.º 25
0
 def test_clone_recursive(self):
     self.assertClone(DllBinary(Path('a.dll', Root.srcdir), 'elf', 'c',
                                Path('a.lib', Root.srcdir),
                                Path('a.exp', Root.srcdir)),
                      DllBinary(Path('a.dll'), 'elf', 'c', Path('a.lib'),
                                Path('a.exp')),
                      recursive=True)
Exemplo n.º 26
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')]) ]
         )
Exemplo n.º 27
0
    def test_flags_include_dir(self):
        p = Path('/path/to/include')
        self.assertEqual(
            self.compiler.flags(
                opts.option_list(
                    opts.include_dir(file_types.HeaderDirectory(p)))),
            ['-I' + p])

        self.assertEqual(
            self.compiler.flags(
                opts.option_list(
                    opts.include_dir(file_types.HeaderDirectory(
                        p, system=True)))), ['-isystem', p])

        if self.env.target_platform.name == 'linux':
            p = Path('/usr/include')
            self.assertEqual(
                self.compiler.flags(
                    opts.option_list(
                        opts.include_dir(
                            file_types.HeaderDirectory(p, system=True)))),
                ['-I' + p])
Exemplo n.º 28
0
    def test_dir_sentinel(self):
        makefile = make.Makefile(None)
        src = self.context['source_file']('dir/main.cpp')
        result = self.context['object_file'](file=src)

        with mock.patch.object(make.Makefile, 'rule') as mrule, \
             mock.patch('logging.log'):
            compile.make_compile(result.creator, self.build, makefile,
                                 self.env)
            mrule.assert_called_once_with(
                result, [src], [Path('dir/.dir')], AlwaysEqual(),
                AlwaysEqual(), None,
            )
Exemplo n.º 29
0
    def test_make_directory(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', directory='dir')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            src = self.builtin_dict['header_file']('main.hpp')
            result = pch(file=src, directory='dir')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='main.hpp', directory='dir/')
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='main.hpp', directory=Path('dir'))
            self.assertSameFile(result,
                                self.output_file('dir/main.hpp', self.context))

            result = pch(file='dir1/main.hpp', directory='dir2')
            context = {
                'pch_source':
                file_types.SourceFile(Path('dir1/main.cpp', Root.srcdir),
                                      'c++')
            }
            self.assertSameFile(
                result, self.output_file('dir2/dir1/main.hpp', context))

            result = pch('object', 'main.hpp', directory='dir')
            self.assertSameFile(result,
                                self.output_file('object', self.context))

            self.assertRaises(ValueError,
                              pch,
                              file='main.hpp',
                              directory=Path('dir', Root.srcdir))
Exemplo n.º 30
0
    def test_file(self):
        class MockCreator(object):
            def __init__(self, msbuild_output=False):
                self.msbuild_output = msbuild_output

        src = SourceFile(Path('foo'), 'c++')
        self.assertEqual(textify(src), r'$(SolutionDir)\foo')

        src.creator = MockCreator()
        self.assertEqual(textify(src), r'$(IntDir)\foo')

        src.creator = MockCreator(True)
        self.assertEqual(textify(src), r'$(OutDir)\foo')