def test_has_main_and_dependency_declarations(self):
        processor = ParseProcessor()
        changes = ProcessorChanges()
        block_holder = mother.get_block_holder(['user/geom/main.cpp'], CPP)
        processor.do_process(block_holder, changes, OutputStream())
        main = block_holder['main.cpp'].cell
        self.assertTrue(main.hasMain, 'Main method not detected by parse processor')
        self.check_dependency_set(main.dependencies, unresolved=['iostream', 'sphere.h'])

        # now remove #include
        load = block_holder['main.cpp'].content.load
        load.replace('#include "sphere.h"', '')
        block_holder['main.cpp'].content.load = load

        processor.do_process(block_holder, changes, OutputStream())
        self.check_dependency_set(main.dependencies, unresolved=['iostream'])
Exemple #2
0
    def test_delete_main(self):
        r1 = SimpleCell('user/block/r1.h', CPP)
        r2 = SimpleCell('user/block/r2.cpp', CPP)
        r3 = SimpleCell('user/block/r3.cpp', CPP)
        r4 = SimpleCell('user/block/' + BIICODE_FILE)

        res = {
            r1.name: Resource(r1, Content(None, Blob(''))),
            r2.name: Resource(r2, Content(None, Blob(''))),
            r3.name: Resource(r3, Content(None,
                                          Blob('int main(char* argv){}'))),
            r4.name: Resource(r4, Content(None, Blob('[mains]\n !r3.cpp')))
        }

        block_holder = BlockHolder(BlockName('user/block'), res)

        process_holder(block_holder, ParseProcessor())
        self.assertTrue(res['user/block/r3.cpp'].cell.hasMain)

        changes, _ = process_holder(block_holder, MainConfigProcessor())
        # Checks
        self.assertFalse(res['user/block/r1.h'].cell.hasMain)
        self.assertFalse(res['user/block/r2.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/r3.cpp'].cell.hasMain)
        self.assertEqual(0, len(changes.upserted))
Exemple #3
0
    def test_has_main(self):
        '''some basic negative tests, from snippets of code'''
        sources = {'user/block/body.cpp': main_body}
        block_holder = self._process_from_contents(sources)

        ParseProcessor().do_process(block_holder, OutputStream())

        self.assertTrue(block_holder._resources['body.cpp'].content.parser.
                        has_main_function())

        sources = {'user/block/body.cpp': no_main_body}
        block_holder = self._process_from_contents(sources)

        ParseProcessor().do_process(block_holder, OutputStream())

        self.assertFalse(block_holder._resources['body.cpp'].content.parser.
                         has_main_function())
Exemple #4
0
    def test_mains_with_filter(self):
        r1 = SimpleCell('user/block/r1.h', CPP)
        r2 = SimpleCell('user/block/r2.cpp', CPP)
        r3 = SimpleCell('user/block/no_mains/r3.cpp', CPP)
        r4 = SimpleCell('user/block/no_mains/r4.cpp', CPP)
        r5 = SimpleCell('user/block/' + BIICODE_FILE)
        r6 = SimpleCell('user/block/new_mains/r6.cpp', CPP)
        r7 = SimpleCell('user/block/new_mains/r7.cpp', CPP)
        r8 = SimpleCell('user/block/exe_file1.hh', CPP)
        r9 = SimpleCell('user/block/exe_file2.hh', CPP)

        res = {
            r1.name:
            Resource(r1, Content(None, Blob(''))),
            r2.name:
            Resource(r2, Content(None, Blob(''))),
            r3.name:
            Resource(r3, Content(None, Blob('int main(char* argv){}'))),
            r4.name:
            Resource(r4, Content(None, Blob('int main(char* argv){}'))),
            r5.name:
            Resource(
                r5,
                Content(None,
                        Blob('[mains]\n!no_mains/*\nnew_mains/*\n*.hh'))),
            r6.name:
            Resource(r6, Content(None, Blob(''))),
            r7.name:
            Resource(r7, Content(None, Blob(''))),
            r8.name:
            Resource(r8, Content(None, Blob(''))),
            r9.name:
            Resource(r9, Content(None, Blob('')))
        }

        block_holder = BlockHolder(BlockName('user/block'), res)

        process_holder(block_holder, ParseProcessor())
        self.assertTrue(res['user/block/no_mains/r3.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/no_mains/r4.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/new_mains/r6.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/new_mains/r7.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/exe_file1.hh'].cell.hasMain)
        self.assertFalse(res['user/block/exe_file2.hh'].cell.hasMain)

        process_holder(block_holder, MainConfigProcessor())

        # Checks
        self.assertFalse(res['user/block/r1.h'].cell.hasMain)
        self.assertFalse(res['user/block/r2.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/no_mains/r3.cpp'].cell.hasMain)
        self.assertFalse(res['user/block/no_mains/r4.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/new_mains/r6.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/new_mains/r7.cpp'].cell.hasMain)
        self.assertTrue(res['user/block/exe_file1.hh'].cell.hasMain)
        self.assertTrue(res['user/block/exe_file2.hh'].cell.hasMain)
Exemple #5
0
    def __init__(self, active_langs):
        self.processors = [ParseProcessor(), VirtualConfigurationProcessor()]

        self.processors.append(DependenciesProcessor())
        self.processors.append(
            CPPImplementationsProcessor())  # The order is important
        self.processors.append(DependenciesConfigurationProcessor())
        if 'arduino' in active_langs:
            self.processors.append(ArduinoEntryPointProcesor())
        # This should be the last one to process mains as it can disable entry points
        self.processors.append(MainConfigProcessor())
Exemple #6
0
    def test_has_main_and_dependency_declarations(self):
        processor = ParseProcessor()
        block_holder = mother.get_block_holder(['user/geom/main.cpp'], CPP)
        processor.do_process(block_holder, OutputStream())
        main = block_holder['main.cpp'].cell
        self.assertTrue(main.hasMain, 'Main method not detected by parse processor')
        self.check_dependency_set(main.dependencies, unresolved=['iostream', 'sphere.h'])

        # now remove #include
        load = block_holder['main.cpp'].content.load.bytes
        load = load.replace('#include "sphere.h"', '')
        block_holder.add_resource(Resource(SimpleCell('user/geom/main.cpp', CPP),
                                           Content('user/geom/main.cpp', Blob(load))))
        processor.do_process(block_holder, OutputStream())
        main = block_holder['main.cpp'].cell
        self.check_dependency_set(main.dependencies, unresolved=['iostream'])