Esempio n. 1
0
def create_namespace(options):
    if options.strip_prefix:
        print("""g-ir-scanner: warning: Option --strip-prefix has been deprecated;
see --identifier-prefix and --symbol-prefix.""")
        options.identifier_prefixes.append(options.strip_prefix)

    # We do this dance because the empty list has different semantics from
    # None; if the user didn't specify the options, we want to use None so
    # the Namespace constructor picks the defaults.
    if options.identifier_prefixes:
        identifier_prefixes = options.identifier_prefixes
    else:
        identifier_prefixes = None
    if options.symbol_prefixes:
        for prefix in options.symbol_prefixes:
            # See Transformer._split_c_string_for_namespace_matches() for
            # why this check is needed
            if prefix.lower() != prefix:
                _error("Values for --symbol-prefix must be entirely lowercase")
        symbol_prefixes = options.symbol_prefixes
    else:
        symbol_prefixes = None

    return Namespace(options.namespace_name,
                     options.namespace_version,
                     identifier_prefixes=identifier_prefixes,
                     symbol_prefixes=symbol_prefixes)
Esempio n. 2
0
def check(args):
    filename = args[0]

    output = ChunkedIO()
    namespace = Namespace('Test', '1.0')
    logger = MessageLogger.get(namespace=namespace, output=output)
    logger.enable_warnings(True)

    transformer = Transformer(namespace)
    transformer.set_include_paths([
        os.path.join(top_srcdir, 'gir'),
        top_builddir,
        os.path.join(top_builddir, 'gir'),
    ])
    transformer.register_include(Include.from_string('GObject-2.0'))

    ss = SourceScanner()

    options = Options()
    exit_code = process_packages(options, ['gobject-2.0'])
    if exit_code:
        sys.exit(exit_code)
    ss.set_cpp_options(options.cpp_includes, options.cpp_defines,
                       options.cpp_undefines)
    ss.parse_files([filename])
    ss.parse_macros([filename])
    transformer.parse(ss.get_symbols())

    cbp = GtkDocCommentBlockParser()
    blocks = cbp.parse_comment_blocks(ss.get_comments())

    main = MainTransformer(transformer, blocks)
    main.transform()

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    emitted_warnings = [w[w.find(':') + 1:] for w in output.getvalue()]

    expected_warnings = _extract_expected(filename)

    sortkey = lambda x: int(x.split(':')[0])
    expected_warnings.sort(key=sortkey)
    emitted_warnings.sort(key=sortkey)

    if len(expected_warnings) != len(emitted_warnings):
        raise SystemExit("ERROR in '%s': %d warnings were emitted, "
                         "expected %d:\n%s" %
                         (os.path.basename(filename), len(emitted_warnings),
                          len(expected_warnings),
                          _diff(expected_warnings, emitted_warnings)))

    for emitted_warning, expected_warning in zip(emitted_warnings,
                                                 expected_warnings):
        if expected_warning != emitted_warning:
            raise SystemExit(
                "ERROR in '%s': expected warning does not match emitted "
                "warning:\n%s" %
                (filename, _diff([expected_warning], [emitted_warning])))
Esempio n. 3
0
def check(args):
    filename = args[0]

    output = StringIO()
    namespace = Namespace("Test", "1.0")
    logger = MessageLogger.get(namespace=namespace, output=output)
    logger.enable_warnings(True)
    transformer = Transformer(namespace)
    transformer.set_include_paths(
        [os.path.join(top_srcdir, 'gir'), top_builddir])
    transformer.register_include(Include.from_string("GObject-2.0"))

    ss = SourceScanner()

    options = Options()
    exit_code = process_packages(options, ['gobject-2.0'])
    if exit_code:
        sys.exit(exit_code)
    ss.set_cpp_options(options.cpp_includes, options.cpp_defines,
                       options.cpp_undefines)
    ss.parse_files([filename])
    ss.parse_macros([filename])
    transformer.parse(ss.get_symbols())

    ap = AnnotationParser()
    blocks = ap.parse(ss.get_comments())

    main = MainTransformer(transformer, blocks)
    main.transform()

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    raw = output.getvalue()
    if raw.endswith('\n'):
        raw = raw[:-1]
    warnings = raw.split('\n')

    failed_tests = 0
    expected_warnings = _extract_expected(filename)
    if '' in warnings:
        warnings.remove('')
    if len(expected_warnings) != len(warnings):
        raise SystemExit(
            "ERROR in %r: expected %d warnings, but got %d:\n"
            "----\nexpected:\n%s\n----\ngot:\n%s\n----" %
            (os.path.basename(filename), len(expected_warnings), len(warnings),
             '\n'.join([w[1] for w in expected_warnings]), '\n'.join(
                 [w.split(':', 2)[2][1:] for w in warnings])))
    for warning, (sort_key, expected) in zip(warnings, expected_warnings):
        actual = warning.split(":", 1)[1]
        if _diff(expected, actual, filename):
            raise SystemExit("ERROR: tests %r failed" % (filename, ))
def load_tests(loader, tests, pattern):
    suite = unittest.TestSuite()
    # add standard tests from module
    suite.addTests(tests)

    # Initialize message logger
    namespace = Namespace('Test', '1.0')
    logger = MessageLogger.get(namespace=namespace)
    logger.enable_warnings((WARNING, ERROR, FATAL))

    # Load test cases from disc
    tests_dir = os.path.dirname(os.path.abspath(__file__))

    for name, test_case in _all_tests.iteritems():
        tests = loader.loadTestsFromTestCase(test_case)
        suite.addTests(tests)
    return suite
def create_test_cases():
    # Initialize message logger
    namespace = Namespace('Test', '1.0')
    logger = MessageLogger.get(namespace=namespace)
    logger.enable_warnings((WARNING, ERROR, FATAL))
    test_cases = {}

    # Load test cases from disc
    tests_dir = os.path.dirname(os.path.abspath(__file__))

    for dirpath, dirnames, filenames in os.walk(tests_dir):
        for filename in filenames:
            tests_file = os.path.join(dirpath, filename)
            if os.path.basename(tests_file).endswith('.xml'):
                validate(tests_file)
                test_case = create_test_case(logger, tests_dir, tests_file)
                test_cases[test_case.__name__] = test_case

    return test_cases
Esempio n. 6
0
                                        n=max(len(expected_tree), len(parsed_tree)),
                                        lineterm='')
            for line in diff:
                msg += '%s\n' % (line, )

            # Compare parsed with expected DocBlock tree
            self.assertEqual(parsed_tree, expected_tree, msg)

        return do_test


if __name__ == '__main__':
    # Initialize message logger
    # TODO: at some point it might be a good idea to test warnings emitted
    # by annotationparser here, instead of having them in tests/warn/annotationparser.h?
    namespace = Namespace('Test', '1.0')
    logger = MessageLogger.get(namespace=namespace)
    logger.enable_warnings(False)

    # Load test cases from disc
    tests_dir = os.path.dirname(os.path.abspath(__file__))

    for dirpath, dirnames, filenames in os.walk(tests_dir):
        for filename in filenames:
            tests_file = os.path.join(dirpath, filename)
            if os.path.basename(tests_file).endswith('.xml'):
                create_tests(tests_dir, tests_file)

    # Run test suite
    unittest.main()