Example #1
0
    def test_only_find_files_GGG(self):
        self.of = MockOutputFormatter('testdir4')
        # A combination of -G and -f is similar to -g
        self._run_main(
            ['-f', '-G', r'file1', '-G', r'main[12].py', '-G', r'.*2.*'],
            dir=self.testdir4)
        self.assertFoundFiles(self.of, [
            'testdir4/file1.py',
            'testdir4/file1.txt',
            'testdir4/file2.py',
            'testdir4/file2.txt',
            'testdir4/main1.py',
            'testdir4/main2.py',
            'testdir4/main2.txt',
        ])

        self.of = MockOutputFormatter('testdir4')
        self._run_main([
            '-f', '--include-pattern', r'file1', '--include-pattern',
            r'main[12].py', '--include-pattern', r'.*2.*'
        ],
                       dir=self.testdir4)
        self.assertFoundFiles(self.of, [
            'testdir4/file1.py',
            'testdir4/file1.txt',
            'testdir4/file2.py',
            'testdir4/file2.txt',
            'testdir4/main1.py',
            'testdir4/main2.py',
            'testdir4/main2.txt',
        ])
Example #2
0
    def test_ignored_dirs(self):
        rootdir = path_to_testdir('ignored_dirs')

        # no dirs ignored
        of = MockOutputFormatter('ignored_dirs')
        self._run_main(['def', '--xml'], dir=rootdir, output_formatter=of)

        # Comparing as sorted because on different systems the files
        # returned in a different order
        #
        self.assertEqual(
            sorted(of.output),
            sorted(
                self._gen_outputs_in_file('ignored_dirs/file.xml', [('MATCH', (
                    1, [(3, 6)]))]) +
                self._gen_outputs_in_file('ignored_dirs/dir1/file.xml', [(
                    'MATCH', (1, [(3, 6)]))]) +
                self._gen_outputs_in_file('ignored_dirs/dir2/file.xml', [(
                    'MATCH', (1, [(3, 6)]))])))

        # both dir1 and dir2 ignored
        of = MockOutputFormatter('ignored_dirs')
        self._run_main(
            ['def', '--xml', '--ignore-dir=dir1', '--ignore-dir=dir2'],
            dir=rootdir,
            output_formatter=of)

        self.assertEqual(
            of.output,
            self._gen_outputs_in_file('ignored_dirs/file.xml',
                                      [('MATCH', (1, [(3, 6)]))]))

        # both dir1 and dir2 ignored in the same --ignore-dir list
        of = MockOutputFormatter('ignored_dirs')
        self._run_main(['def', '--xml', '--ignore-dir=dir1,dir2'],
                       dir=rootdir,
                       output_formatter=of)

        self.assertEqual(
            of.output,
            self._gen_outputs_in_file('ignored_dirs/file.xml',
                                      [('MATCH', (1, [(3, 6)]))]))

        # dir1 ignored (dir2 also appears in remove_ignored_dirs)
        of = MockOutputFormatter('ignored_dirs')
        self._run_main([
            'def', '--xml', '--ignore-dir=dir1', '--ignore-dir=dir2',
            '--noignore-dir=dir2'
        ],
                       dir=rootdir,
                       output_formatter=of)

        self.assertEqual(
            sorted(of.output),
            sorted(
                self._gen_outputs_in_file('ignored_dirs/file.xml', [('MATCH', (
                    1, [(3, 6)]))]) +
                self._gen_outputs_in_file('ignored_dirs/dir2/file.xml', [(
                    'MATCH', (1, [(3, 6)]))])))
Example #3
0
    def test_only_find_files_g(self):
        self._run_main(['--cc', '-g', r'.*y\.'])
        self.assertFoundFiles(self.of, ['testdir1/subdir1/filey.c'])

        self.of = MockOutputFormatter('testdir1')
        self._run_main(['-g', r'\.qqq'], expected_rc=1)
        self.assertFoundFiles(self.of, [])

        self.of = MockOutputFormatter('testdir1')
        self._run_main(['-a', '-g', r'\.qqq'])
        self.assertFoundFiles(self.of, ['testdir1/subdir1/ppp.qqq'])
Example #4
0
    def test_include_types(self):
        rootdir = path_to_testdir('test_types')
        def outputs(filename):
            return self._gen_outputs_in_file(
                        filename,
                        [('MATCH', (1, [(0, 3)]))])

        # include only js and java
        of = MockOutputFormatter('test_types')
        self._run_main(
            ['abc', '--js', '--java'],
            output_formatter=of,
            dir=rootdir)

        self.assertEqual(sorted(of.output), sorted(
                outputs('test_types/a.java') +
                outputs('test_types/a.js')))

        # include js and scons
        of = MockOutputFormatter('test_types')
        self._run_main(
            ['abc', '--js', '--scons'],
            output_formatter=of,
            dir=rootdir)

        self.assertEqual(sorted(of.output), sorted(
                outputs('test_types/a.js') +
                outputs('test_types/a.scons')))

        # empty include_types - so include all known types
        of = MockOutputFormatter('test_types')
        self._run_main(
            ['abc'],
            output_formatter=of,
            dir=rootdir)

        self.assertEqual(sorted(of.output), sorted(
                outputs('test_types/a.java') +
                outputs('test_types/a.scons') +
                outputs('test_types/a.js') +
                outputs('test_types/a.lua') +
                outputs('test_types/a.cmd') +
                outputs('test_types/a.bat')))

        # empty include_types, but some are excluded
        of = MockOutputFormatter('test_types')
        self._run_main(
            ['abc', '--nojs', '--nojava', '--nobatch', '--noscons'],
            output_formatter=of,
            dir=rootdir)

        self.assertEqual(sorted(of.output), sorted(
                outputs('test_types/a.lua')))
Example #5
0
    def test_whole_words(self):
        # without whole word matching
        of = MockOutputFormatter('testdir1')
        self._run_main(['xaxo', '--ada'], output_formatter=of)
        self.assertEqual(
            of.output,
            self._gen_outputs_in_file('testdir1/subdir1/wholewords.adb',
                                      [('MATCH', (1, [(5, 9)])),
                                       ('MATCH', (2, [(4, 8)]))]))

        # now with whole word matching
        of = MockOutputFormatter('testdir1')
        self._run_main(['xaxo', '--ada', '-w'], output_formatter=of)
        self.assertEqual(
            of.output,
            self._gen_outputs_in_file('testdir1/subdir1/wholewords.adb',
                                      [('MATCH', (1, [(5, 9)]))]))
Example #6
0
    def test_only_find_files_G(self):
        # A combination of -G and -f is similar to -g
        self._run_main(['--cc', '-f', '-G', r'.*y\.'])
        self.assertFoundFiles(self.of, ['testdir1/subdir1/filey.c'])

        self.of = MockOutputFormatter('testdir1')
        self._run_main(['--cc', '-f', '--include-pattern', r'.*y\.'])
        self.assertFoundFiles(self.of, ['testdir1/subdir1/filey.c'])
Example #7
0
 def test_only_find_files_gg(self):
     self.of = MockOutputFormatter('testdir4')
     self._run_main(['-g', r'file1', '-g', r'main\d.py'], dir=self.testdir4)
     self.assertFoundFiles(self.of, [
         'testdir4/file1.py',
         'testdir4/file1.txt',
         'testdir4/main1.py',
         'testdir4/main2.py',
         'testdir4/main3.py',
     ])
Example #8
0
 def test_only_find_files_exclude_pattern_thrice(self):
     self.of = MockOutputFormatter('testdir4')
     self._run_main([
         '-f', '--exclude-pattern', 'file1', '--exclude-pattern',
         r'file\d.txt', '--exclude-pattern', 'main.*.txt'
     ],
                    dir=self.testdir4)
     self.assertFoundFiles(self.of, [
         'testdir4/file2.py', 'testdir4/file3.py', 'testdir4/main1.py',
         'testdir4/main2.py', 'testdir4/main3.py'
     ])
Example #9
0
 def test_universal_newlines(self):
     of = MockOutputFormatter('testdir3')
     self._run_main(['-U', '--match=test$'],
                    dir=path_to_testdir('testdir3'),
                    output_formatter=of)
     self.assertEqual(
         sorted(of.output),
         sorted(
             self._gen_outputs_in_file('testdir3/lfnewlines.txt', [(
                 'MATCH', (1, [(10, 14)]))]) +
             self._gen_outputs_in_file('testdir3/crlfnewlines.txt', [(
                 'MATCH', (1, [(10, 14)]))]) +
             self._gen_outputs_in_file('testdir3/crnewlines.txt', [(
                 'MATCH', (1, [(10, 14)]))])))
Example #10
0
 def setUp(self):
     self.of = MockOutputFormatter('testdir1')
Example #11
0
    def test_only_find_files_f(self):
        self._run_main(['--cc', '-f'])
        self.assertFoundFiles(self.of, [
            'testdir1/filea.c', 'testdir1/filea.h', 'testdir1/subdir1/filey.c',
            'testdir1/subdir1/filez.c'
        ])

        self.of = MockOutputFormatter('testdir1')
        self._run_main(['--make', '-f'])
        self.assertFoundFiles(self.of, [
            'testdir1/Makefile', 'testdir1/subdir1/Makefile',
            'testdir1/zappos.mk'
        ])

        self.of = MockOutputFormatter('testdir1')
        self._run_main(['--cmake', '-f'])
        self.assertFoundFiles(self.of, [
            'testdir1/CMakeLists.txt', 'testdir1/subdir1/CMakeFuncs.txt',
            'testdir1/subdir1/joe.cmake', 'testdir1/subdir1/joe2.cmake'
        ])

        self.of = MockOutputFormatter('testdir2')
        self._run_main(['--txt', '-f'], dir=self.testdir2)
        self.assertFoundFiles(
            self.of, ['testdir2/sometext.txt', 'testdir2/othertext.txt'])

        self.of = MockOutputFormatter('testdir2')
        self._run_main(['--withoutext', '-f'], dir=self.testdir2)
        self.assertFoundFiles(self.of, ['testdir2/somescript'])

        # try some option mix-n-matching

        # just a pattern type
        self.of = MockOutputFormatter('test_types')
        self._run_main(['--scons', '-f'], dir=self.test_types)
        self.assertFoundFiles(self.of,
                              ['test_types/a.scons', 'test_types/SConstruct'])

        # pattern type + extension type
        self.of = MockOutputFormatter('test_types')
        self._run_main(['--scons', '--lua', '-f'], dir=self.test_types)
        self.assertFoundFiles(self.of, [
            'test_types/a.scons', 'test_types/SConstruct', 'test_types/a.lua'
        ])

        # as before, with include filter
        self.of = MockOutputFormatter('test_types')
        self._run_main(['--scons', '--lua', '-g', 'lua'], dir=self.test_types)
        self.assertFoundFiles(self.of, ['test_types/a.lua'])

        # all known types
        self.of = MockOutputFormatter('test_types')
        self._run_main(['-f'], dir=self.test_types)
        self.assertFoundFiles(self.of, [
            'test_types/a.scons',
            'test_types/SConstruct',
            'test_types/a.lua',
            'test_types/a.js',
            'test_types/a.java',
            'test_types/a.bat',
            'test_types/a.cmd',
        ])

        # all known types with extension type exclusion
        self.of = MockOutputFormatter('test_types')
        self._run_main(['-f', '--nobatch', '--nojava'], dir=self.test_types)
        self.assertFoundFiles(self.of, [
            'test_types/a.scons',
            'test_types/SConstruct',
            'test_types/a.lua',
            'test_types/a.js',
        ])

        # all known types with pattern type exclusion
        self.of = MockOutputFormatter('test_types')
        self._run_main(['-f', '--noscons'], dir=self.test_types)
        self.assertFoundFiles(self.of, [
            'test_types/a.java',
            'test_types/a.lua',
            'test_types/a.bat',
            'test_types/a.cmd',
            'test_types/a.js',
        ])

        # all known types with pattern type exclusion and filter inclusion
        self.of = MockOutputFormatter('test_types')
        self._run_main(['-g', '(lua|java)', '--noscons'], dir=self.test_types)
        self.assertFoundFiles(self.of, [
            'test_types/a.java',
            'test_types/a.lua',
        ])

        # all known types with extension and pattern type exclusion
        self.of = MockOutputFormatter('test_types')
        self._run_main(['-f', '--noscons', '--nojs'], dir=self.test_types)
        self.assertFoundFiles(self.of, [
            'test_types/a.java',
            'test_types/a.lua',
            'test_types/a.bat',
            'test_types/a.cmd',
        ])
Example #12
0
 def setUp(self):
     self.of1 = MockOutputFormatter('testdir1')
     self.of4 = MockOutputFormatter('testdir4')