def annotation_main(args): parser = optparse.OptionParser('%prog [options] sources') group = optparse.OptionGroup(parser, "Tool modes, one is required") group.add_option("-e", "--extract", action="store_true", dest="extract", help="Extract annotations from the input files") parser.add_option_group(group) group = get_preprocessor_option_group(parser) group.add_option("-L", "--library-path", action="append", dest="library_paths", default=[], help="directories to search for libraries") group.add_option("", "--pkg", action="append", dest="packages", default=[], help="pkg-config packages to get cflags from") parser.add_option_group(group) options, args = parser.parse_args(args) if not options.extract: raise SystemExit("ERROR: Nothing to do") if options.packages: process_packages(options, options.packages) logger = message.MessageLogger.get(namespace=None) ss = create_source_scanner(options, args) if options.extract: parser = GtkDocCommentBlockParser() writer = GtkDocCommentBlockWriter(indent=False) blocks = parser.parse_comment_blocks(ss.get_comments()) with encode_stdout('utf-8'): print('/' + ('*' * 60) + '/') print('/* THIS FILE IS GENERATED DO NOT EDIT */') print('/' + ('*' * 60) + '/') print('') for block in sorted(blocks.values()): print(writer.write(block)) print('') print('') print('/' + ('*' * 60) + '/') print('/* THIS FILE IS GENERATED DO NOT EDIT */') print('/' + ('*' * 60) + '/') return 0
def annotation_main(args): parser = optparse.OptionParser('%prog [options] sources') group = optparse.OptionGroup(parser, "Tool modes, one is required") group.add_option("-e", "--extract", action="store_true", dest="extract", help="Extract annotations from the input files") parser.add_option_group(group) group = get_preprocessor_option_group(parser) group.add_option("-L", "--library-path", action="append", dest="library_paths", default=[], help="directories to search for libraries") group.add_option("", "--pkg", action="append", dest="packages", default=[], help="pkg-config packages to get cflags from") parser.add_option_group(group) options, args = parser.parse_args(args) if not options.extract: raise SystemExit("ERROR: Nothing to do") if options.packages: process_packages(options, options.packages) logger = message.MessageLogger.get(namespace=None) ss = create_source_scanner(options, args) if options.extract: parser = GtkDocCommentBlockParser() writer = GtkDocCommentBlockWriter(indent=False) blocks = parser.parse_comment_blocks(ss.get_comments()) with encode_stdout('utf-8'): print('/' + ('*' * 60) + '/') print('/* THIS FILE IS GENERATED DO NOT EDIT */') print('/' + ('*' * 60) + '/') print('') for block in sorted(blocks.values()): print(writer.write(block)) print('') print('') print('/' + ('*' * 60) + '/') print('/* THIS FILE IS GENERATED DO NOT EDIT */') print('/' + ('*' * 60) + '/') return 0
def do_test(self): output = ChunkedIO() logger._output = output # Parse GTK-Doc comment block commentblock = testcase.find(ns('{}input')).text parsed_docblock = GtkDocCommentBlockParser().parse_comment_block(commentblock, 'test.c', 1) parsed_tree = self.parsed2tree(parsed_docblock).split('\n') emitted_messages = [w[w.find(':') + 1:].strip() for w in output.getvalue()] # Get expected parser output expected_docblock = testcase.find(ns('{}parser/{}docblock')) expected_tree = self.expected2tree(expected_docblock).split('\n') expected_messages = [] for w in testcase.findall(ns('{}parser/{}messages/{}message')): expected_messages.append(w.text.strip()) # Compare parsed with expected GtkDocCommentBlock msg = 'Parsed GtkDocCommentBlock object tree does not match expected output:\n\n' msg += '%s\n\n' % (commentblock, ) diff = difflib.unified_diff(expected_tree, parsed_tree, 'Expected GtkDocCommentBlock', 'Parsed GtkDocCommentBlock', n=max(len(expected_tree), len(parsed_tree)), lineterm='') for line in diff: msg += '%s\n' % (line, ) self.assertTrue(parsed_tree == expected_tree, msg) # Compare emitted with expected messages msg = 'Emitted messages do not match expected messages:\n\n' msg += '%s\n\n' % (commentblock, ) msg += self._diff_messages(expected_messages, emitted_messages) self.assertTrue(len(expected_messages) == len(emitted_messages), msg) for emitted_message, expected_message in zip(emitted_messages, expected_messages): msg = 'Emitted message does not match expected message:\n\n' msg += '%s\n\n' % (commentblock, ) msg += self._diff_messages([expected_message], [emitted_message]) self.assertTrue(expected_message == emitted_message, msg) # Compare serialized with expected comment block expected_serialized = testcase.find(ns('{}output')) indent = True if expected_serialized is None: expected_serialized = '' else: if 'indent' in expected_serialized.attrib: indent = expected_serialized.attrib['indent'] if indent.lower() in ('false', '0'): indent = False elif indent.lower() in ('true', '1'): indent = True else: self.assert_(False, 'Unknown value for "indent" attribute: %s' % (indent)) expected_serialized = expected_serialized.text + '\n' or None commentblockwriter = GtkDocCommentBlockWriter(indent=indent) serialized = commentblockwriter.write(parsed_docblock) msg = 'Serialized comment block does not match expected output:\n\n' msg += self._diff_messages(expected_serialized.split('\n'), serialized.split('\n')) self.assertTrue(expected_serialized == serialized, msg)
def do_test(self): output = ChunkedIO() logger._output = output # Parse GTK-Doc comment block commentblock = testcase.find(ns('{}input')).text parsed_docblock = GtkDocCommentBlockParser().parse_comment_block( commentblock, 'test.c', 1) parsed_tree = self.parsed2tree(parsed_docblock).split('\n') emitted_messages = [ w[w.find(':') + 1:].strip() for w in output.getvalue() ] # Get expected parser output expected_docblock = testcase.find(ns('{}parser/{}docblock')) expected_tree = self.expected2tree(expected_docblock).split('\n') expected_messages = [] for w in testcase.findall(ns('{}parser/{}messages/{}message')): expected_messages.append(w.text.strip()) # Compare parsed with expected GtkDocCommentBlock msg = 'Parsed GtkDocCommentBlock object tree does not match expected output:\n\n' msg += '%s\n\n' % (commentblock, ) diff = difflib.unified_diff(expected_tree, parsed_tree, 'Expected GtkDocCommentBlock', 'Parsed GtkDocCommentBlock', n=max(len(expected_tree), len(parsed_tree)), lineterm='') for line in diff: msg += '%s\n' % (line, ) self.assertTrue(parsed_tree == expected_tree, msg) # Compare emitted with expected messages msg = 'Emitted messages do not match expected messages:\n\n' msg += '%s\n\n' % (commentblock, ) msg += self._diff_messages(expected_messages, emitted_messages) self.assertTrue( len(expected_messages) == len(emitted_messages), msg) for emitted_message, expected_message in zip( emitted_messages, expected_messages): msg = 'Emitted message does not match expected message:\n\n' msg += '%s\n\n' % (commentblock, ) msg += self._diff_messages([expected_message], [emitted_message]) self.assertTrue(expected_message == emitted_message, msg) # Compare serialized with expected comment block expected_serialized = testcase.find(ns('{}output')) indent = True if expected_serialized is None: expected_serialized = '' else: if 'indent' in expected_serialized.attrib: indent = expected_serialized.attrib['indent'] if indent.lower() in ('false', '0'): indent = False elif indent.lower() in ('true', '1'): indent = True else: self.assert_( False, 'Unknown value for "indent" attribute: %s' % (indent)) expected_serialized = expected_serialized.text + '\n' or None commentblockwriter = GtkDocCommentBlockWriter(indent=indent) serialized = commentblockwriter.write(parsed_docblock) msg = 'Serialized comment block does not match expected output:\n\n' msg += self._diff_messages(expected_serialized.split('\n'), serialized.split('\n')) self.assertTrue(expected_serialized == serialized, msg)
else: print('Using GTK-Doc source directory "%s"' % gtkdoc_tests) for root, dirs, files in os.walk(gtkdoc_tests): for inputfile in files: ext = os.path.splitext(inputfile)[-1].lower() if 'src' in root and ext in ['.c', '.h']: path = os.path.join(root, inputfile) print('Reading "%s"' % path) relpath = os.path.relpath(path, gtkdoc_tests).split(os.sep) relpath = os.path.join(relpath[0], relpath[len(relpath) - 1]) logger = MessageLogger.get(namespace=None) parser = GtkDocCommentBlockParser() writer = GtkDocCommentBlockWriter(indent=True) logger.enable_warnings(True) with io.open(path, 'r') as f: lines = f.readlines() chunks = [] in_comment = False chunk_start = 0 chunk_end = 0 for line_index, line in enumerate(lines): if not in_comment: if COMMENT_BLOCK_START_RE.match(line): # We are at a line that starts a GTK-Doc comment block in_comment = True
else: print('Using GTK-Doc source directory "%s"' % gtkdoc_tests) for root, dirs, files in os.walk(gtkdoc_tests): for inputfile in files: ext = os.path.splitext(inputfile)[-1].lower() if 'src' in root and ext in ['.c', '.h']: path = os.path.join(root, inputfile) print('Reading "%s"' % path) relpath = os.path.relpath(path, gtkdoc_tests).split(os.sep) relpath = os.path.join(relpath[0], relpath[len(relpath) - 1]) logger = MessageLogger.get(namespace=None) parser = GtkDocCommentBlockParser() writer = GtkDocCommentBlockWriter(indent=True) logger.enable_warnings((ERROR, FATAL)) with io.open(path, 'rU') as f: lines = f.readlines() chunks = [] in_comment = False chunk_start = 0 chunk_end = 0 for line_index, line in enumerate(lines): if not in_comment: if COMMENT_BLOCK_START_RE.match(line): # We are at a line that starts a GTK-Doc comment block in_comment = True