Beispiel #1
0
 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)),
     ])
Beispiel #2
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)),
     ])
Beispiel #3
0
 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)),
     ])
Beispiel #4
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)),
     ])
Beispiel #5
0
 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)),
     ])
Beispiel #6
0
 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')})
Beispiel #7
0
 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/')
     })
Beispiel #8
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/')
            })
Beispiel #9
0
 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/')})
Beispiel #10
0
 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())
Beispiel #11
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)
Beispiel #12
0
 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)
Beispiel #13
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)),
     ])
Beispiel #14
0
 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)
Beispiel #15
0
 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)
Beispiel #16
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/')})
Beispiel #17
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])
Beispiel #18
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)
Beispiel #19
0
    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])
Beispiel #20
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())
Beispiel #21
0
    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/')
        })
Beispiel #22
0
 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/')
     })
Beispiel #23
0
 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/')
     })
Beispiel #24
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)
Beispiel #25
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/')
     })
Beispiel #26
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/')})
Beispiel #27
0
 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/')
     })
Beispiel #28
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)
Beispiel #29
0
    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)))
Beispiel #30
0
    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')