Exemplo n.º 1
0
    def tear_up(self):
        super(AdaAPIDriver, self).tear_up()

        if 'main' not in self.test_env:
            raise SetupError('Missing "main" key in test.yaml')
        main = self.test_env['main']

        if 'input_sources' not in self.test_env:
            raise SetupError('Missing "input_sources" key in test.yaml')
        self.input_sources = self.test_env['input_sources']

        self.check_file(main)
        self.check_file_list('"input_sources"', self.input_sources)

        with open(self.working_dir('gen.gpr'), 'w') as f:
            f.write('''
            with "libadalang";

            project Gen is
                for Languages use ("Ada");
                for Source_Dirs use (".");
                for Object_Dir use ".";
                for Main use ("{main_source}");

                package Builder is
                    for Executable ("{main_source}") use "{exec_name}";
                end Builder;

                package Compiler is
                    for Default_Switches ("Ada") use
                      ("-g", "-O0", "-gnata", "-gnatwa");
                end Compiler;
            end Gen;
            '''.format(main_source=main,
                       exec_name=self.test_program))
Exemplo n.º 2
0
    def tear_up(self):
        super(BuildAndRunDriver, self).tear_up()

        project_file = self.test_env.get('project_file', None)
        main = self.test_env.get('main', None)

        if not project_file or not isinstance(project_file, basestring):
            raise SetupError('test.yaml: please define a "project_file" string'
                             ' field')
        if not main or not isinstance(main, basestring):
            raise SetupError('test.yaml: please define a "main" string field')

        self.project_file = project_file
        self.main_program = main
Exemplo n.º 3
0
    def tear_up(self):
        super(CAPIDriver, self).tear_up()

        if 'compile_units' not in self.test_env:
            raise SetupError('Missing "compile_units" key in test.yaml')
        compile_units = self.test_env['compile_units']

        if 'input_sources' not in self.test_env:
            raise SetupError('Missing "input_sources" key in test.yaml')
        input_sources = self.test_env['input_sources']

        self.check_file_list('"compile_units"',
                             compile_units,
                             can_be_empty=False)
        self.check_file_list('"input_sources"', input_sources)

        with open(self.working_dir('p.gpr'), 'w') as f:
            f.write('''
            with "libadalang";

            project P is
                for Languages use ("C");
                for Source_Dirs use (".");
                for Object_Dir use ".";
                for Main use ("{main_source}");

                package Builder is
                    for Executable ("{main_source}") use "{exec_name}";
                end Builder;

                package Compiler is
                    for Default_Switches ("C") use
                      ("-Wall", "-W", "-Werror", "-pedantic",

                       "-Wno-error=unused-variable",
                       "-Wno-error=unused-function",
                       --  Code and data are shared in headers, so we expect
                       --  unused variables there.

                       "-std=c99",
                       --  Use a stable C standard. Different compilers means
                       --  different default standard.

                       "-I{support_include_dir}", "-g");
                end Compiler;
            end P;
            '''.format(main_source=compile_units[0],
                       exec_name=self.test_program,
                       support_include_dir=self.support_include_dir))
Exemplo n.º 4
0
    def run(self):
        # Build the command line for the "parse" process we are going to run
        parse_argv = ['parse']

        try:
            charset = self.test_env['charset']
        except KeyError:
            pass
        else:
            parse_argv += ['-c', charset]

        if self.action == 'pretty-print-file':
            parse_argv += ['-f', self.input_file]
        elif self.action == 'pp-file-with-trivia':
            parse_argv += ['-P', '-f', self.input_file]
        elif self.action == 'pp-file-with-lexical-envs':
            parse_argv += ['-E', '-f', self.input_file]
        else:
            rule_name = self.test_env.get('rule', None)
            if not rule_name:
                raise SetupError('Parsing rule is missing from test.yaml')
            parse_argv += ['-r', rule_name,
                           self.read_file(self.working_dir(self.input_file))]

        for lookup in self.get_lookups():
            parse_argv.append(
                '{}:{}'.format(lookup['line'], lookup['column'])
            )

        self.run_and_check(parse_argv, for_debug=True, memcheck=True)
Exemplo n.º 5
0
    def tear_up(self):
        super(NavigationDriver, self).tear_up()

        try:
            self.input_sources = self.test_env['input_sources']
        except KeyError:
            raise SetupError('Missing "input_sources" key in test.yaml')
        if not isinstance(self.input_sources, list) or not all(
                isinstance(k, str) for k in self.input_sources):
            raise SetupError('"input_sources" must contain a list of strings')

        try:
            self.kinds = self.test_env['kinds']
        except KeyError:
            raise SetupError('Missing "kinds" key in test.yaml')
        if not isinstance(self.kinds, list) or not all(
                isinstance(k, str) for k in self.kinds):
            raise SetupError('"kinds" must contain a list of strings')
Exemplo n.º 6
0
    def tear_up(self):
        super(InlinePlaygroundDriver, self).tear_up()
        self.py_runner = PythonRunner(self)
        self.py_runner.setup_environment()
        self.py_file = os.path.join(self.py_runner.support_dir,
                                    'inline_playground.py')

        self.charset = self.test_env.get('charset', None)
        self.project_file = self.test_env.get('project_file', None)
        if 'input_sources' not in self.test_env:
            raise SetupError('Missing "input_sources" key in test.yaml')
        self.input_sources = self.test_env['input_sources']
Exemplo n.º 7
0
    def tear_up(self):
        super(ParserDriver, self).tear_up()

        # What should we do for this test?
        self.action = self.test_env.get('action', 'pretty-print')
        if self.action not in self.ACTIONS:
            raise SetupError('Invalid action: {}'.format(self.action))

        # Pass a relative filename to "parse" so that its output does not
        # depend on the location of the working directory. This helps making
        # the test output stable across runs.
        self.input_file = self.test_env.get('input_file', 'input')

        self.check_file(self.input_file)
Exemplo n.º 8
0
    def get_lookups(self):
        try:
            lookups = self.test_env['lookups']
        except KeyError:
            # Lookups are not required: we just test them if they are present
            return []

        # Check that lookups are sane
        for lookup in lookups:
            if (not isinstance(lookup, dict) or len(lookup) != 2
                    or not isinstance(lookup.get('line'), int)
                    or not isinstance(lookup.get('column'), int)):
                raise SetupError(
                    'Invalid lookup in test.yaml: {}'.format(lookup))

        return lookups
Exemplo n.º 9
0
    def tear_up(self):
        super(NameResolutionDriver, self).tear_up()

        self.py_runner = PythonRunner(self)
        self.py_file = os.path.join(self.py_runner.support_dir, 'nameres.py')

        if 'input_sources' not in self.test_env:
            raise SetupError('Missing "input_sources" key in test.yaml')
        self.input_sources = self.test_env['input_sources']

        self.charset = self.test_env.get('charset', None)
        self.with_default_project = self.test_env.get('with_default_project',
                                                      False)

        if self.run_python:
            self.py_runner.setup_environment()
Exemplo n.º 10
0
    def tear_up(self):
        super(PythonDriver, self).tear_up()

        self.runner = PythonRunner(self)

        if not self.runner.is_python_api_available:
            self.result.set_status(
                'DEAD', 'Cannot test the Python API without shared libraries')
        if self.disable_python:
            self.result.set_status('DEAD', 'Python API testing disabled')

        if 'input_sources' not in self.test_env:
            raise SetupError('Missing "input_sources" key in test.yaml')
        self.input_sources = self.test_env['input_sources']

        self.check_file(self.py_file)
        self.check_file_list('"input_sources"', self.input_sources)

        self.runner.setup_environment()
Exemplo n.º 11
0
    def tear_up(self):
        super(NameResolutionDriver, self).tear_up()

        self.py_runner = PythonRunner(self)
        self.py_file = os.path.join(self.py_runner.support_dir, 'nameres.py')

        if 'input_sources' not in self.test_env:
            raise SetupError('Missing "input_sources" key in test.yaml')
        self.input_sources = self.test_env['input_sources']

        self.charset = self.test_env.get('charset', None)
        self.project_file = self.test_env.get('project_file', None)

        self.auto_provider_dirs = self.test_env.get('auto_provider_dirs', None)

        self.imprecise_fallback = self.test_env.get('imprecise_fallback',
                                                    False)

        if self.run_python:
            self.py_runner.setup_environment()
Exemplo n.º 12
0
    def run(self):
        # Build the command line for the "parse" process we are going to run
        base_argv = ['parse']
        misc_argv = []

        try:
            charset = self.test_env['charset']
        except KeyError:
            pass
        else:
            base_argv += ['-c', charset]

        rule_name = self.test_env.get('rule', None)
        if rule_name:
            base_argv += ['-r', rule_name]

        if self.action == 'pretty-print-file':
            input_argv = ['-f', self.input_file]
        elif self.action == 'pp-file-with-trivia':
            input_argv = ['-f', self.input_file]
            misc_argv += ['-P']
        elif self.action == 'pp-file-with-lexical-envs':
            input_argv = ['-f', self.input_file]
            misc_argv += ['-E']
        else:
            if not rule_name:
                raise SetupError('Parsing rule is missing from test.yaml')
            input_argv = [self.read_file(self.working_dir(self.input_file))]

        for lookup in self.get_lookups():
            misc_argv.append('{}:{}'.format(lookup['line'], lookup['column']))

        # Run a first time, to run the testcase according to "self.action"
        self.run_and_check(base_argv + input_argv + misc_argv,
                           for_debug=True,
                           memcheck=True)

        # If specifically asked not to test unparsing, stop now
        if not self.test_env.get('test-unparsing', True):
            return

        # Then run several other times to:
        #
        # 1. Get a sloc-less tree dump for the base input.
        # 2. Unparse  the base input.
        # 3. Get a sloc-less tree dump for the unparsed output.
        # 4. Check that both tree dumps are the same (i.e. that unparsing
        #    preserved the source).
        # For each step, save the result in a file to ease testsuite failure
        # investigation.
        outputs = {}
        for name, filename, argv in [
            ('base-tree-dump', self.base_tree_dump_file,
             base_argv + input_argv + ['--hide-slocs']),
            ('unparsed', self.unparsed_file,
             base_argv + input_argv + ['-s', '--unparse']),
            ('unparsed-tree-dump', self.unparsed_tree_dump_file,
             base_argv + ['-f', self.unparsed_file, '--hide-slocs']),
        ]:
            outputs[name] = self.run_and_check(argv,
                                               memcheck=True,
                                               append_output=False)
            with open(self.working_dir(filename), 'w') as f:
                f.write(outputs[name])

        # Do the comparison itself, report any difference
        diff = self.diff(self.working_dir(self.base_tree_dump_file),
                         self.working_dir(self.unparsed_tree_dump_file))
        if diff:
            self.result.actual_output += ('Difference between base tree dump'
                                          ' and unparsed tree dump:\n')
            self.result.actual_output += diff
            self.set_failure('unparsed diff')