[go: up one dir, main page]

File: runtest.py

package info (click to toggle)
raqm 0.10.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,060 kB
  • sloc: ansic: 2,151; python: 61; xml: 57; sh: 26; makefile: 6
file content (74 lines) | stat: -rw-r--r-- 2,125 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import difflib
import os
import subprocess
import sys

# Special exit code that tells automake that a test has been skipped,
# eg. when we needs a newer HarfBuzz version than what is available.
SKIP_EXIT_STATUS = 77

def cmd(command):
    print(command)
    p = subprocess.Popen(command, stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE, universal_newlines=True)
    out, err = p.communicate()
    print(f"Error:\n{err}")
    return out.strip(), p.returncode


def diff(expected, actual):
    expected = expected.splitlines(1)
    actual = actual.splitlines(1)
    diff = difflib.unified_diff(expected, actual)
    return "".join(diff)


srcdir = sys.argv[1]
testtool = sys.argv[2]

fails = 0
skips = 0
for filename in sys.argv[3:]:
    print("Testing %s..." % filename)

    with open(filename, encoding="utf-8") as fp:
        lines = [l.strip("\n") for l in fp.readlines()]
    font = lines[0]
    text = lines[1].replace(r'\r', "\r").replace(r'\n', '\n')
    text = " ".join(f"{b:04X}" for b in text.encode("utf-8"))
    opts = lines[2] and lines[2].split(" ") or []
    expected = "\n".join(lines[3:])
    if "," in font:
        fonts = []
        for f in font.split(","):
            if f.endswith(".ttf"):
                f = os.path.join(srcdir, f)
            fonts.append(f)
        fonts = ",".join(fonts)
        command = [testtool, "--bytes", text] + opts + ["--fonts", fonts]
    else:
        font = os.path.join(srcdir, font)
        command = [testtool, "--bytes", text] + opts + ["--font", font]

    actual, ret = cmd(command)
    expected = expected.strip()
    actual = actual.strip()
    if ret == SKIP_EXIT_STATUS:
        # platform is missing a requirement to run the test, eg. old HarfBuzz
        skips += 1
    elif ret:
        print(f"Error code returned: {ret}")
        fails += 1
    elif actual != expected:
        print(diff(expected, actual))
        fails += 1

if fails:
    print("%d tests failed." % fails)
    sys.exit(1)
elif skips:
    print("%d tests skipped." % skips)
    sys.exit(SKIP_EXIT_STATUS)
else:
    print("All tests passed.")
    sys.exit(0)