def test_reorganize_headers_for_a_different_tier_module(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/Plugins', 4)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = []
        services.files_lists['Source/Module1/Plugins'] = [
            'File1.cpp', 'File1.h', 'File2.h'
        ]
        services.files_lists['build/include/T4'] = []
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/Plugins']
        services.folders_lists['Source/Module1/Plugins'] = []

        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertEquals(2, len(services.linked_files))
        self.assertEquals(
            'build/include/T4',
            services.linked_files['Source/Module1/Plugins/File1.h'])
        self.assertEquals(
            'build/include/T4',
            services.linked_files['Source/Module1/Plugins/File2.h'])
Beispiel #2
0
    def test_resolve_include_path_for_module_with_third_party_headers(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/Module1', 3)
        layout.addTierForModulesLike('CoreLib', 3, 'CoreLib')

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = [
            'Source/Module1/File1.cpp', 'Source/Module1/File1.h',
            'Source/Module1/File2.h'
        ]
        services.files_lists['Source/Module1/private'] = [
            'Source/Module1/private/File1.cpp',
            'Source/Module1/private/File1.h', 'Source/Module1/private/File2.h'
        ]
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/private']
        services.folders_lists['Source/Module1/private'] = []

        path_resolver = IncludePath(layout, services)
        self.assertEqual([
            'CoreLib', 'build/include/T1', 'build/include/T2',
            'build/include/T3'
        ], path_resolver.resolveIncludePaths('Source/Module1'))
    def test_headers_which_are_out_of_date_at_the_target_are_shifted(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/Plugins', 4)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = []
        services.files_lists['Source/Module1/Plugins'] = [
            'File1.cpp', 'File1.h', 'File2.h'
        ]
        services.files_lists['build/include/T4'] = ['File1.h', 'File2.h']
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/Plugins']
        services.folders_lists['Source/Module1/Plugins'] = []
        services.file_dates['Source/Module1/Plugins/File1.h'] = 'uptodate'
        services.file_dates['Source/Module1/Plugins/File2.h'] = 'uptodate'
        services.file_dates['build/include/T4/File1.h'] = 'notuptodate'
        services.file_dates['build/include/T4/File2.h'] = 'notuptodate'
        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertEquals(2, len(services.linked_files))
        self.assertEquals(
            'build/include/T4',
            services.linked_files['Source/Module1/Plugins/File1.h'])
        self.assertEquals(
            'build/include/T4',
            services.linked_files['Source/Module1/Plugins/File2.h'])
        self.assertEquals(2, len(services.removed_files))
        self.assertTrue('build/include/T4/File1.h' in services.removed_files)
        self.assertTrue('build/include/T4/File2.h' in services.removed_files)
    def test_headers_which_are_no_longer_in_the_sources_are_removed_from_the_destinations(
            self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/Plugins', 4)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = []
        services.files_lists['Source/Module1/Plugins'] = [
            'File1.cpp', 'File1.h'
        ]
        services.files_lists['build/include/T4'] = ['File2.h']
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/Plugins']
        services.folders_lists['Source/Module1/Plugins'] = []
        services.folders_lists['build/include/T4'] = []

        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertEquals(1, len(services.linked_files))
        self.assertEquals(
            'build/include/T4',
            services.linked_files['Source/Module1/Plugins/File1.h'])
        self.assertEquals(1, len(services.removed_files))
        self.assertTrue('build/include/T4/File2.h' in services.removed_files)
    def test_private_headers_are_reorganized_if_a_module_is_prescient(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/private', -1)
        layout.addTierForModulesLike('**/TestCases', 5, None, True)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = []
        services.files_lists['Source/Module1/private'] = [
            'File1.cpp', 'File1.h', 'File2.h'
        ]
        services.files_lists['build/include/T0'] = []
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/private']
        services.folders_lists['Source/Module1/private'] = []

        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertEquals(2, len(services.linked_files))
        self.assertEquals(
            'build/include/T0',
            services.linked_files['Source/Module1/private/File1.h'])
        self.assertEquals(
            'build/include/T0',
            services.linked_files['Source/Module1/private/File2.h'])
Beispiel #6
0
 def test_multiple_source_folders_can_be_added(self):
     project = ProjectLayout()
     project.addSourceFolder('Source/Feature1')
     project.addSourceFolder('Source/Feature2')
     project.addSourceFolder('Source/Feature3')
     self.assertListEqual(
         ['Source/Feature1', 'Source/Feature2', 'Source/Feature3'],
         project.getSourceFolders())
    def test_headers_which_are_no_longer_in_the_sources_are_removed_from_the_destinations_even_if_their_tier_folder_is_unused(
            self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/Plugins', 4)
        layout.addTierForModulesLike('**/Plugins/File9.h', 8)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = []
        services.files_lists['Source/Module1/Plugins'] = [
            'File1.cpp', 'File1.h', 'File9.h'
        ]
        services.files_lists['build/include/T8'] = ['File2.h', 'File9.h']
        services.files_lists['build/include/T7'] = ['File2.h', 'File9.h']
        services.files_lists['build/include/T6'] = ['File2.h', 'File9.h']
        services.files_lists['build/include/T5'] = ['File2.h', 'File9.h']
        services.files_lists['build/include/T4'] = ['File2.h', 'File9.h']
        services.files_lists['build/include/T3'] = ['File2.h']
        services.files_lists['build/include/T2'] = ['File2.h']
        services.files_lists['build/include/T1'] = ['File2.h']
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/Plugins']
        services.folders_lists['Source/Module1/Plugins'] = []
        services.folders_lists['build/include/T8'] = []
        services.folders_lists['build/include/T7'] = []
        services.folders_lists['build/include/T6'] = []
        services.folders_lists['build/include/T5'] = []
        services.folders_lists['build/include/T4'] = []
        services.folders_lists['build/include/T3'] = []
        services.folders_lists['build/include/T2'] = []
        services.folders_lists['build/include/T1'] = []

        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertEquals(2, len(services.linked_files))
        self.assertEquals(
            'build/include/T4',
            services.linked_files['Source/Module1/Plugins/File1.h'])
        self.assertEquals(
            'build/include/T8',
            services.linked_files['Source/Module1/Plugins/File9.h'])
        self.assertEquals(12, len(services.removed_files))
        self.assertTrue('build/include/T8/File2.h' in services.removed_files)
        self.assertTrue('build/include/T7/File2.h' in services.removed_files)
        self.assertTrue('build/include/T6/File2.h' in services.removed_files)
        self.assertTrue('build/include/T5/File2.h' in services.removed_files)
        self.assertTrue('build/include/T4/File2.h' in services.removed_files)
        self.assertTrue('build/include/T1/File2.h' in services.removed_files)
        self.assertTrue('build/include/T2/File2.h' in services.removed_files)
        self.assertTrue('build/include/T3/File2.h' in services.removed_files)
        self.assertTrue('build/include/T7/File9.h' in services.removed_files)
        self.assertTrue('build/include/T6/File9.h' in services.removed_files)
        self.assertTrue('build/include/T5/File9.h' in services.removed_files)
        self.assertTrue('build/include/T4/File9.h' in services.removed_files)
Beispiel #8
0
    def test_reorganize_headers_for_single_module(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = [
            'Source/Module1/File1.cpp', 'Source/Module1/File1.h',
            'Source/Module1/File2.h'
        ]
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = []

        path_resolver = IncludePath(layout, services)
        self.assertEqual(['build/include/T1'],
                         path_resolver.resolveIncludePaths('Source/Module1'))
Beispiel #9
0
    def test_reorganize_headers_for_a_higher_tier_module(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/Module2', 3)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module2'] = [
            'Source/Module2/File1.cpp', 'Source/Module2/File1.h',
            'Source/Module2/File2.h'
        ]
        services.folders_lists['Source'] = ['Source/Module2']
        services.folders_lists['Source/Module2'] = []

        path_resolver = IncludePath(layout, services)
        self.assertEqual(
            ['build/include/T1', 'build/include/T2', 'build/include/T3'],
            path_resolver.resolveIncludePaths('Source/Module2'))
    def test_private_headers_are_not_reorganized(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/private', -1)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = []
        services.files_lists['Source/Module1/private'] = [
            'File1.cpp', 'File1.h', 'File2.h'
        ]
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/private']
        services.folders_lists['Source/Module1/private'] = []

        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertEquals(0, len(services.linked_files))
    def test_reorganize_headers_when_a_target_folder_is_missing(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = [
            'File1.cpp', 'File1.h', 'File2.h'
        ]
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = []

        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertTrue('build/include/T1' in services.files_lists)
        self.assertEquals(2, len(services.linked_files))
        self.assertEquals('build/include/T1',
                          services.linked_files['Source/Module1/File1.h'])
        self.assertEquals('build/include/T1',
                          services.linked_files['Source/Module1/File2.h'])
    def test_public_headers_in_a_private_module_are_reorganized(self):
        layout = ProjectLayout()
        layout.addSourceFolder('Source')
        layout.addTierForModulesLike('**/private', 0)
        layout.addTierForModulesLike('**/private/Public*.h', 4)

        services = StubProjectServices()
        services.files_lists['Source'] = []
        services.files_lists['Source/Module1'] = []
        services.files_lists['Source/Module1/private'] = [
            'PublicFile1.cpp', 'PublicFile1.h', 'PublicFile2.h'
        ]
        services.folders_lists['Source'] = ['Source/Module1']
        services.folders_lists['Source/Module1'] = ['Source/Module1/private']
        services.folders_lists['Source/Module1/private'] = []

        reorganizer = HeaderReorganization(layout, services)

        reorganizer.reorganizeHeaders()
        self.assertEquals(2, len(services.linked_files))
        self.assertTrue(
            'Source/Module1/private/PublicFile1.h' in services.linked_files)
        self.assertTrue(
            'Source/Module1/private/PublicFile2.h' in services.linked_files)
Beispiel #13
0
 def test_a_source_folder_can_be_added(self):
     project = ProjectLayout()
     project.addSourceFolder('Source/Feature1')
     self.assertListEqual(['Source/Feature1'], project.getSourceFolders())