Esempio n. 1
0
    def test_submodule_path_object(self):
        with self.context.push_path(Path('dir/build.bfg', Root.srcdir)):
            expected = [
                SourceFile(srcpath('file.cpp'), 'c++'),
                File(srcpath('dir/file2.txt'))
            ]
            self.assertFound(self.find(srcpath('**')), expected)
            self.assertFindDirs({
                srcpath('./'),
                srcpath('dir/'),
                srcpath('dir2/'),
                srcpath('dir/sub/')
            })

            expected = [
                Directory(srcpath('.')),
                Directory(srcpath('dir')),
                Directory(srcpath('dir2')),
                Directory(srcpath('dir/sub'))
            ]
            self.assertFound(self.find(srcpath('**/')), expected)
            self.assertFindDirs({
                srcpath('./'),
                srcpath('dir/'),
                srcpath('dir2/'),
                srcpath('dir/sub/')
            })
Esempio n. 2
0
 def test_multiple_dirs(self):
     dist.extra_dist(self.builtin_dict, dirs=['dir1', 'dir2'])
     self.assertEqual(list(self.build.sources()), [
         File(Path('build.bfg', Root.srcdir)),
         Directory(Path('dir1', Root.srcdir)),
         Directory(Path('dir2', Root.srcdir)),
     ])
Esempio n. 3
0
 def test_flat(self):
     expected = [
         Directory(srcpath('.')), Directory(srcpath('dir')),
         SourceFile(srcpath('file.cpp'), 'c++')
     ]
     with mock_context():
         self.assertFound(self.find(flat=True), expected)
Esempio n. 4
0
 def test_type_dir(self):
     expected = [
         Directory(srcpath('.')),
         Directory(srcpath('dir'))
     ]
     with mock_context():
         self.assertFound(self.find(type='d'), expected)
Esempio n. 5
0
    def test_filter(self):
        def my_filter(path):
            if path.directory:
                return find.FindResult.not_now
            elif path.ext() == '.cpp':
                return find.FindResult.include
            else:
                return find.FindResult.exclude

        expected = [SourceFile(srcpath('file.cpp'), 'c++')]
        pre = [
            Directory(srcpath('./')),
            Directory(srcpath('dir/')),
            Directory(srcpath('dir2/'))
        ]
        post = [Directory(srcpath('dir/sub/'))]
        self.assertFound(self.find('**', type='*', filter=my_filter),
                         expected,
                         pre=pre,
                         post=post)
        self.assertFindDirs({
            srcpath('./'),
            srcpath('dir/'),
            srcpath('dir2/'),
            srcpath('dir/sub/')
        })
Esempio n. 6
0
    def test_path_pattern(self):
        expected = [File(srcpath('dir/file2.txt'))]
        self.assertFound(self.find(srcpath('dir/**')), expected)
        self.assertFindDirs({srcpath('dir/'), srcpath('dir/sub/')})

        expected = [Directory(srcpath('dir/')), Directory(srcpath('dir/sub'))]
        self.assertFound(self.find(srcpath('dir/**/')), expected)
        self.assertFindDirs({srcpath('dir/'), srcpath('dir/sub/')})
Esempio n. 7
0
 def test_path(self):
     expected = [
         Directory(srcpath('dir')),
         Directory(srcpath('dir/sub')),
         File(srcpath('dir/file2.txt'))
     ]
     with mock.patch('warnings.warn') as m:
         self.assertFound(self.find('dir'), expected)
         self.assertEqual(m.call_count, 1)
Esempio n. 8
0
 def test_dist(self):
     expected = [
         Directory(srcpath('.')),
         Directory(srcpath('dir')),
         SourceFile(srcpath('file.cpp'), 'c++'),
         File(srcpath('dir/file2.txt'))
     ]
     with mock_context():
         self.assertFound(self.find(dist=False), expected, [self.bfgfile])
Esempio n. 9
0
 def test_cache(self):
     expected = [
         Directory(srcpath('.')),
         Directory(srcpath('dir')),
         SourceFile(srcpath('file.cpp'), 'c++'),
         File(srcpath('dir/file2.txt'))
     ]
     with mock_context():
         self.assertFound(self.find(cache=False), expected)
         self.assertEqual(self.build['find_dirs'], set())
Esempio n. 10
0
 def test_submodule_path_object(self):
     with self.context.push_path(Path('dir/build.bfg', Root.srcdir)), \
          mock_context():  # noqa
         expected = [
             Directory(srcpath('.')),
             Directory(srcpath('dir')),
             SourceFile(srcpath('file.cpp'), 'c++'),
             File(srcpath('dir/file2.txt'))
         ]
         self.assertFound(self.find(srcpath('.')), expected)
Esempio n. 11
0
 def test_default(self):
     expected = [
         Directory(srcpath('.')),
         Directory(srcpath('dir')),
         Directory(srcpath('dir2')),
         SourceFile(srcpath('file.cpp'), 'c++'),
         Directory(srcpath('dir/sub')),
         File(srcpath('dir/file2.txt'))
     ]
     with mock.patch('warnings.warn') as m:
         self.assertFound(self.find(), expected)
         self.assertEqual(m.call_count, 1)
Esempio n. 12
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/')})
Esempio n. 13
0
 def test_type_dir(self):
     expected = [
         Directory(srcpath('.')),
         Directory(srcpath('dir')),
         Directory(srcpath('dir2')),
         Directory(srcpath('dir/sub'))
     ]
     self.assertFound(self.find('**', type='d'), expected)
     self.assertFindDirs({
         srcpath('./'),
         srcpath('dir/'),
         srcpath('dir2/'),
         srcpath('dir/sub/')
     })
Esempio n. 14
0
 def test_type_all(self):
     expected = [
         Directory(srcpath('.')),
         Directory(srcpath('dir')),
         Directory(srcpath('dir2')),
         SourceFile(srcpath('file.cpp'), 'c++'),
         Directory(srcpath('dir/sub')),
         File(srcpath('dir/file2.txt'))
     ]
     self.assertFound(self.find('**', type='*'), expected)
     self.assertFindDirs({
         srcpath('./'),
         srcpath('dir/'),
         srcpath('dir2/'),
         srcpath('dir/sub/')
     })
Esempio n. 15
0
 def test_both(self):
     self.context['extra_dist']('file', 'dir')
     self.assertEqual(list(self.build.sources()), [
         File(Path('build.bfg', Root.srcdir)),
         File(Path('file', Root.srcdir)),
         Directory(Path('dir', Root.srcdir)),
     ])
Esempio n. 16
0
 def test_path_object(self):
     expected = [
         Directory(srcpath('dir')),
         File(srcpath('dir/file2.txt'))
     ]
     with mock_context():
         self.assertFound(self.find(srcpath('dir')), expected)
Esempio n. 17
0
 def test_both(self):
     dist.extra_dist(self.builtin_dict, 'file', 'dir')
     self.assertEqual(list(self.build.sources()), [
         File(Path('build.bfg', Root.srcdir)),
         File(Path('file', Root.srcdir)),
         Directory(Path('dir', Root.srcdir)),
     ])
Esempio n. 18
0
    def test_windows_default_location(self):
        env = make_env('winnt', clear_variables=True)
        boost_incdir = r'C:\Boost\include\boost-1.23'

        def mock_walk(top):
            yield (top, ) + ([('boost-1.23', ntpath.join(top, 'boost-1.23'))
                              ], [])

        def mock_execute(*args, **kwargs):
            if args[0][1] == '/?':
                return 'cl.exe'
            raise ValueError()

        def mock_exists(x):
            if re.search(r'[/\\]boost[/\\]version.hpp$', x):
                return True
            return False

        with mock.patch('bfg9000.builtins.find._walk_flat', mock_walk), \
             mock.patch('bfg9000.builtins.packages._boost_version',
                        return_value=Version('1.23')), \
             mock.patch('bfg9000.shell.which', return_value=['command']), \
             mock.patch('bfg9000.shell.execute', mock_execute), \
             mock.patch('os.path.exists', mock_exists):  # noqa
            pkg = packages.boost_package(env, 'thread')
            self.assertEqual(pkg.name, 'boost(thread)')
            self.assertEqual(pkg.version, Version('1.23'))
            self.assertEqual(
                pkg._compile_options,
                opts.option_list(
                    opts.include_dir(HeaderDirectory(abspath(boost_incdir)))))
            self.assertEqual(
                pkg._link_options,
                opts.option_list(
                    opts.lib_dir(Directory(abspath(r'C:\Boost\lib')))))
Esempio n. 19
0
    def test_windows_default_location(self):
        env = make_env('winnt', clear_variables=True)
        context = self._make_context(env)
        boost_incdir = r'C:\Boost\include\boost-1.23'

        def mock_walk(top, variables=None):
            yield top, [top.append('boost-1.23/')], []

        def mock_execute(*args, **kwargs):
            if args[0][1] == '/?':
                return 'cl.exe'
            raise ValueError()

        def mock_exists(x):
            return bool(re.search(r'[/\\]boost[/\\]version.hpp$', x.string()))

        with mock.patch('bfg9000.builtins.find.walk', mock_walk), \
             mock.patch('bfg9000.builtins.packages._boost_version',
                        return_value=Version('1.23')), \
             mock.patch('bfg9000.shell.which', return_value=['command']), \
             mock.patch('bfg9000.shell.execute', mock_execute), \
             mock.patch('bfg9000.tools.msvc.exists', mock_exists):  # noqa
            pkg = context['boost_package']('thread')
            self.assertEqual(pkg.name, 'boost(thread)')
            self.assertEqual(pkg.version, Version('1.23'))
            self.assertEqual(
                pkg._compile_options,
                opts.option_list(
                    opts.include_dir(HeaderDirectory(abspath(boost_incdir)))))
            self.assertEqual(
                pkg._link_options,
                opts.option_list(
                    opts.lib_dir(Directory(abspath(r'C:\Boost\lib')))))
Esempio n. 20
0
    def test_link_options_coff(self):
        linker = AttrDict(flavor='gcc', builder=AttrDict(object_format='coff'))
        with mock.patch('bfg9000.shell.execute', mock_execute):
            pkg = PkgConfigPackage(self.tool, 'foo', format='elf')

            self.assertEqual(
                pkg.link_options(linker),
                opts.option_list('-pthread',
                                 opts.lib_dir(Directory(Path('/usr/lib'))),
                                 opts.lib_literal('-lfoo')))
Esempio n. 21
0
 def check_package(self, pkg):
     self.assertEqual(pkg.name, 'foo')
     self.assertEqual(pkg.compile_options(self.compiler), option_list(
         '/DMACRO', opts.include_dir(HeaderDirectory(Path('/path')))
     ))
     self.assertEqual(pkg.link_options(self.linker), option_list(
         '/DEBUG', opts.lib_dir(Directory(Path('/path'))),
         opts.lib_literal('foo.lib'),
         (opts.rpath_dir(Path('/path')) if self.platform_name == 'linux'
          else None)
     ))
Esempio n. 22
0
 def test_multiple_extra(self):
     expected = [SourceFile(srcpath('file.cpp'), 'c++')]
     extra = [Directory(srcpath('dir/sub')), File(srcpath('dir/file2.txt'))]
     self.assertFound(self.find('**/*.cpp', extra=['*.txt', 'su?/']),
                      expected,
                      post=extra)
     self.assertFindDirs({
         srcpath('./'),
         srcpath('dir/'),
         srcpath('dir2/'),
         srcpath('dir/sub/')
     })
Esempio n. 23
0
 def test_link_options_static(self):
     linker = AttrDict(flavor='gcc')
     with mock.patch('bfg9000.shell.execute', mock_execute):
         pkg = PkgConfigPackage(self.tool,
                                'foo',
                                format='elf',
                                kind=PackageKind.static)
         self.assertEqual(pkg.static, True)
         self.assertEqual(
             pkg.link_options(linker),
             opts.option_list('-pthread',
                              opts.lib_dir(Directory(Path('/usr/lib'))),
                              opts.lib_literal('-lfoo'),
                              opts.lib_literal('-lstatic')))
Esempio n. 24
0
    def test_link_options_macho_uninst(self):
        linker = AttrDict(flavor='gcc',
                          builder=AttrDict(object_format='mach-o'))
        with mock.patch('bfg9000.shell.execute', mock_execute_uninst):
            pkg = PkgConfigPackage(self.tool, 'foo', format='elf')

            self.assertEqual(
                pkg.link_options(linker),
                opts.option_list(
                    '-pthread',
                    opts.lib_dir(Directory(Path('/path/to/build/foo'))),
                    opts.lib_literal('-lfoo'),
                    opts.install_name_change('/path/to/build/foo/libfoo.dylib',
                                             '/usr/lib/libfoo.dylib')))
Esempio n. 25
0
    def test_non_glob(self):
        with mock.patch('warnings.warn') as m:
            self.assertFound(self.find('dir', 'file2.txt', flat=True),
                             [File(srcpath('dir/file2.txt'))])
            self.assertEqual(m.call_count, 1)

        with mock.patch('warnings.warn') as m:
            self.assertFound(self.find('dir', 'file3.txt', flat=True), [])
            self.assertEqual(m.call_count, 1)

        with mock.patch('warnings.warn') as m:
            self.assertFound(self.find('dir', 'sub', flat=True),
                             [Directory(srcpath('dir/sub'))])
            self.assertEqual(m.call_count, 1)
Esempio n. 26
0
    def test_filter(self):
        def my_filter(path, type):
            if path.basename() == 'dir':
                return find.FindResult.not_now
            elif path.ext() == '.cpp':
                return find.FindResult.include
            else:
                return find.FindResult.exclude

        expected = [SourceFile(srcpath('file.cpp'), 'c++')]
        with mock_context():
            self.assertFound(
                self.find(filter=my_filter), expected,
                [self.bfgfile, Directory(srcpath('dir'))] + expected)