def test_multiple_files(self): dist.extra_dist(self.builtin_dict, files=['file1', 'file2']) self.assertEqual(list(self.build.sources()), [ File(Path('build.bfg', Root.srcdir)), File(Path('file1', Root.srcdir)), File(Path('file2', Root.srcdir)), ])
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)), ])
def test_submodule(self): with self.context.push_path(Path('dir/build.bfg', Root.srcdir)): self.context['extra_dist'](files='file') self.assertEqual(list(self.build.sources()), [ File(Path('build.bfg', Root.srcdir)), File(Path('dir/file', Root.srcdir)), ])
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)), ])
def test_multiple_files(self): self.context['extra_dist'](files=['file1', 'file2']) self.assertEqual(list(self.build.sources()), [ File(Path('build.bfg', Root.srcdir)), File(Path('file1', Root.srcdir)), File(Path('file2', Root.srcdir)), ])
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_no_default_exclude(self): self.context['project'](find_exclude=[]) expected = [ SourceFile(srcpath('file.cpp'), 'c++'), File(srcpath('file.cpp~')), File(srcpath('dir/file2.txt')) ] self.assertFound(self.find('**/file*'), expected) self.assertFindDirs({ srcpath('./'), srcpath('dir/'), srcpath('dir2/'), srcpath('dir/sub/') })
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/') })
def test_multiple_patterns(self): expected = [ SourceFile(srcpath('file.cpp'), 'c++'), File(srcpath('dir/file2.txt')) ] self.assertFound(self.find(['*.cpp', 'dir/*.txt']), expected) self.assertFindDirs({srcpath('./'), srcpath('dir/')})
def test_no_cache(self): expected = [ SourceFile(srcpath('file.cpp'), 'c++'), File(srcpath('dir/file2.txt')) ] self.assertFound(self.find('**', cache=False), expected) self.assertFindDirs(set())
def test_path_object(self): expected = [ Directory(srcpath('dir')), File(srcpath('dir/file2.txt')) ] with mock_context(): self.assertFound(self.find(srcpath('dir')), expected)
def test_type_file(self): expected = [ SourceFile(srcpath('file.cpp'), 'c++'), File(srcpath('dir/file2.txt')) ] with mock_context(): self.assertFound(self.find(type='f'), expected)
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)), ])
def test_name(self): expected = [ SourceFile(srcpath('file.cpp'), 'c++'), File(srcpath('dir/file2.txt')) ] with mock.patch('warnings.warn') as m: self.assertFound(self.find(name='file*'), expected) self.assertEqual(m.call_count, 1)
def test_submodule(self): with self.context.push_path(Path('dir/build.bfg', Root.srcdir)), \ mock_context(): # noqa expected = [ Directory(srcpath('dir')), File(srcpath('dir/file2.txt')) ] self.assertFound(self.find('.'), expected)
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/')})
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])
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)
def test_add_project(self): proj = Project(FakeEnv(), 'project') self.sln[Phony('phony')] = proj self.assertTrue(Phony('phony') in self.sln) self.assertTrue(Phony('foobar') not in self.sln) self.assertTrue(File(Path('phony')) not in self.sln) self.assertIs(self.sln[Phony('phony')], proj) self.assertEqual(list(iter(self.sln)), [proj])
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())
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_type_file(self): expected = [ SourceFile(srcpath('file.cpp'), 'c++'), File(srcpath('dir/file2.txt')) ] self.assertFound(self.find('**', type='f'), expected) self.assertFindDirs({ srcpath('./'), srcpath('dir/'), srcpath('dir2/'), srcpath('dir/sub/') })
def test_extra(self): expected = [SourceFile(srcpath('file.cpp'), 'c++')] extra = [File(srcpath('dir/file2.txt'))] self.assertFound(self.find('**/*.cpp', extra='*.txt'), expected, post=extra) self.assertFindDirs({ srcpath('./'), srcpath('dir/'), srcpath('dir2/'), srcpath('dir/sub/') })
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)
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/') })
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/')})
def test_no_dist(self): expected = [ SourceFile(srcpath('file.cpp'), 'c++'), File(srcpath('dir/file2.txt')) ] self.assertFoundResult(self.find('**', dist=False), expected) self.assertEqual(list(self.build.sources()), [self.bfgfile]) self.assertFindDirs({ srcpath('./'), srcpath('dir/'), srcpath('dir2/'), srcpath('dir/sub/') })
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)
def test_rule(self): self.makefile.rule('target', variables={'name': 'value'}, recipe=['cmd']) out = Writer(StringIO()) self.makefile._write_rule(out, self.makefile._rules[0]) self.assertEqual(out.stream.getvalue(), 'target: name := value\n' 'target:\n' '\tcmd\n\n') # Test duplicate targets. self.assertRaises(ValueError, self.makefile.rule, 'target') self.assertRaises(ValueError, self.makefile.rule, ['target', 'target2']) self.assertRaises(ValueError, self.makefile.rule, File(path.Path('target', path.Root.builddir)))
def test_build(self): self.ninjafile.rule('my_rule', ['cmd']) self.ninjafile.build('output', 'my_rule') out = Writer(StringIO()) self.ninjafile._write_build(out, self.ninjafile._builds[0]) self.assertEqual(out.stream.getvalue(), 'build output: my_rule\n') # Test duplicate targets. self.assertRaises(ValueError, self.ninjafile.build, 'output', 'my_rule') self.assertRaises(ValueError, self.ninjafile.build, ['output', 'output2'], 'my_rule') self.assertRaises(ValueError, self.ninjafile.build, File(path.Path('output', path.Root.builddir)), 'my_rule')