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()) 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()) 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)
if COMMENT_BLOCK_END_RE.match(line): # We are at a line that closes a GTK-Doc comment block in_comment = False # Store the GTK-Doc comment block chunks.append([ ''.join(lines[chunk_start:line_index + 1]), relpath, chunk_start + 1 ]) # Data chunk after the GTK-Doc comment block starts at the next line chunk_start = line_index + 1 # Store where the GTK-Doc comment block ends chunk_end = line_index outputfile = os.path.join(gi_tests, '%s.xml.in' % relpath) print('Writing "%s"' % outputfile) with io.open(outputfile, 'w', newline='', encoding='utf-8') as f: f.write(HEADER) for chunk in chunks: docblock = parser.parse_comment_block( chunk[0].rstrip(), chunk[1], chunk[2]) if docblock: f.write( TEST % { 'docblock': chunk[0].rstrip(), 'tree': parsed2tree(docblock), 'serialized': writer.write(docblock).rstrip() }) f.write(FOOTER)
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 # Store where this GTK-Doc comment block starts chunk_start = line_index else: if COMMENT_BLOCK_END_RE.match(line): # We are at a line that closes a GTK-Doc comment block in_comment = False # Store the GTK-Doc comment block chunks.append([''.join(lines[chunk_start:line_index + 1]), relpath, chunk_start + 1]) # Data chunk after the GTK-Doc comment block starts at the next line chunk_start = line_index + 1 # Store where the GTK-Doc comment block ends chunk_end = line_index outputfile = os.path.join(gi_tests, '%s.xml.in' % relpath) print('Writing "%s"' % outputfile) with io.open(outputfile, 'w', newline='', encoding='utf-8') as f: f.write(HEADER) for chunk in chunks: docblock = parser.parse_comment_block(chunk[0].rstrip(), chunk[1], chunk[2]) if docblock: f.write(TEST % {'docblock': chunk[0].rstrip(), 'tree': parsed2tree(docblock), 'serialized': writer.write(docblock).rstrip()}) f.write(FOOTER)