File: roundtrip_tests.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (50 lines) | stat: -rw-r--r-- 2,199 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import re
import sys
from spec_tests import get_tests, do_test
from cmark import CMark
import argparse

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Run cmark roundtrip tests.')
    parser.add_argument('-p', '--program', dest='program', nargs='?', default=None,
            help='program to test')
    parser.add_argument('-s', '--spec', dest='spec', nargs='?', default='spec.txt',
            help='path to spec')
    parser.add_argument('-P', '--pattern', dest='pattern', nargs='?',
            default=None, help='limit to sections matching regex pattern')
    parser.add_argument('--library-dir', dest='library_dir', nargs='?',
            default=None, help='directory containing dynamic library')
    parser.add_argument('--extensions', dest='extensions', nargs='?',
            default=None, help='space separated list of extensions to enable')
    parser.add_argument('--no-normalize', dest='normalize',
            action='store_const', const=False, default=True,
            help='do not normalize HTML')
    parser.add_argument('-n', '--number', type=int, default=None,
            help='only consider the test with the given number')
    args = parser.parse_args(sys.argv[1:])

spec = sys.argv[1]

def converter(md, exts):
  cmark = CMark(prog=args.program, library_dir=args.library_dir, extensions=args.extensions)
  [ec, result, err] = cmark.to_commonmark(md, exts)
  if ec == 0:
    [ec, html, err] = cmark.to_html(result, exts)
    if ec == 0:
        # In the commonmark writer we insert dummy HTML
        # comments between lists, and between lists and code
        # blocks.  Strip these out, since the spec uses
        # two blank lines instead:
        return [ec, re.sub('<!-- end list -->\n', '', html), '']
    else:
        return [ec, html, err]
  else:
    return [ec, result, err]

tests = get_tests(args.spec)
result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': 0}
for test in tests:
    do_test(converter, test, args.normalize, result_counts)

sys.stdout.buffer.write("{pass} passed, {fail} failed, {error} errored, {skip} skipped\n".format(**result_counts).encode('utf-8'))
exit(result_counts['fail'] + result_counts['error'])