def test_flags_include_dir(self): p = self.Path('/path/to/include') self.assertEqual(self.compiler.flags(opts.option_list( opts.include_dir(HeaderDirectory(p)) )), ['/I' + p, '/MD']) self.assertEqual(self.compiler.flags(opts.option_list( opts.include_dir(HeaderDirectory(p)) ), mode='pkg-config'), ['-I' + p])
def test_file_types(self): expected = [ HeaderDirectory(srcpath('.')), HeaderDirectory(srcpath('dir')), File(srcpath('file.cpp')), File(srcpath('dir/file2.txt')) ] f = self.builtin_dict['generic_file'] d = self.builtin_dict['header_directory'] with mock_context(): self.assertFound(self.find(file_type=f, dir_type=d), expected) self.assertEqual(self.build['find_dirs'], {srcpath('.'), srcpath('dir')})
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')))))
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')))))
def test_compile_options(self): compiler = AttrDict(flavor='gcc') with mock.patch('bfg9000.shell.execute', mock_execute): pkg = PkgConfigPackage(self.tool, 'foo', format='elf') header_dir = HeaderDirectory(Path('/usr/include')) self.assertEqual( pkg.compile_options(compiler), opts.option_list('-DMACRO', opts.include_dir(header_dir)))
def test_flags_include_dir(self): p = self.Path('/path/to/include') self.assertEqual( self.compiler.flags( opts.option_list(opts.include_dir(HeaderDirectory(p)))), ['-I' + p]) self.assertEqual( self.compiler.flags( opts.option_list( opts.include_dir(HeaderDirectory(p, system=True)))), ['-isystem', p]) if self.env.target_platform.genus == 'linux': p = self.Path('/usr/include') self.assertEqual( self.compiler.flags( opts.option_list( opts.include_dir(HeaderDirectory(p, system=True)))), ['-I' + p])
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) ))
def test_file_types(self): f = self.context['generic_file'] d = self.context['header_directory'] expected = [File(srcpath('file.cpp')), File(srcpath('dir/file2.txt'))] self.assertFound(self.find('**', file_type=f), expected) self.assertFindDirs({ srcpath('./'), srcpath('dir/'), srcpath('dir2/'), srcpath('dir/sub/') }) expected = [ HeaderDirectory(srcpath('.')), HeaderDirectory(srcpath('dir')), HeaderDirectory(srcpath('dir2')), HeaderDirectory(srcpath('dir/sub')) ] self.assertFound(self.find('**/', dir_type=d), expected) self.assertFindDirs({ srcpath('./'), srcpath('dir/'), srcpath('dir2/'), srcpath('dir/sub/') }) expected = [ HeaderDirectory(srcpath('.')), HeaderDirectory(srcpath('dir')), HeaderDirectory(srcpath('dir2')), File(srcpath('file.cpp')), HeaderDirectory(srcpath('dir/sub')), File(srcpath('dir/file2.txt')) ] self.assertFound(self.find('**', type='*', file_type=f, dir_type=d), expected) self.assertFindDirs({ srcpath('./'), srcpath('dir/'), srcpath('dir2/'), srcpath('dir/sub/') })
def test_boost_version_cant_parse(self): data = 'foobar\n' with mock.patch(mock_open_name, mock_open(read_data=data)): hdr = HeaderDirectory(abspath('path')) with self.assertRaises(PackageVersionError): packages._boost_version(hdr, SpecifierSet(''))
def test_boost_version_too_old(self): data = '#define BOOST_LIB_VERSION "1_23_4"\n' with mock.patch(mock_open_name, mock_open(read_data=data)): hdr = HeaderDirectory(abspath('path')) with self.assertRaises(PackageVersionError): packages._boost_version(hdr, SpecifierSet('>=1.30'))
def test_boost_version(self): data = '#define BOOST_LIB_VERSION "1_23_4"\n' with mock.patch(mock_open_name, mock_open(read_data=data)): hdr = HeaderDirectory(abspath('path')) self.assertEqual(packages._boost_version(hdr, SpecifierSet('')), Version('1.23.4'))