2017-12-07 08:52:55 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2018-01-10 13:59:36 +01:00
|
|
|
import sys, os, subprocess, re
|
|
|
|
|
|
|
|
p = None
|
|
|
|
cm = None
|
|
|
|
|
|
|
|
def cmd(command, line):
|
|
|
|
global p, cm
|
|
|
|
if command != cm:
|
|
|
|
if p:
|
|
|
|
p.stdin.close()
|
|
|
|
p = subprocess.Popen (command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
cm = command
|
|
|
|
p.stdin.write(line+'\n')
|
|
|
|
p.stdin.flush()
|
|
|
|
p.poll()
|
|
|
|
return p.stdout.readline ().decode ("utf-8").strip(), 0# p.returncode
|
|
|
|
|
|
|
|
def parse (s):
|
|
|
|
s = re.sub (r"0[xX]", " ", s)
|
|
|
|
s = re.sub (r"[<+>{},;&#\\xXuUnNiI\n\t]", " ", s)
|
|
|
|
return [int (x, 16) for x in s.split ()]
|
|
|
|
|
|
|
|
def utf8 (s):
|
|
|
|
s = u''.join (unichr (x) for x in parse (s))
|
|
|
|
if sys.version_info[0] == 2: s = s.encode ('utf-8')
|
|
|
|
return s
|
2017-12-07 08:52:55 +01:00
|
|
|
|
|
|
|
args = sys.argv[1:]
|
2018-01-09 23:15:54 +01:00
|
|
|
if not args or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.argv[1]):
|
|
|
|
print ("""First argument does not seem to point to usable hb-shape.""")
|
|
|
|
sys.exit (1)
|
|
|
|
hb_shape, args = args[0], args[1:]
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2018-01-09 23:15:54 +01:00
|
|
|
extra_options = "--verify"
|
2018-01-01 08:47:51 +01:00
|
|
|
|
|
|
|
fails = 0
|
|
|
|
|
2017-12-07 08:52:55 +01:00
|
|
|
reference = False
|
|
|
|
if len (args) and args[0] == "--reference":
|
|
|
|
reference = True
|
|
|
|
args = args[1:]
|
|
|
|
|
|
|
|
if not len (args):
|
2018-01-09 21:58:57 +01:00
|
|
|
args = ['-']
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2018-01-09 21:58:57 +01:00
|
|
|
for filename in args:
|
2017-12-07 08:52:55 +01:00
|
|
|
if not reference:
|
2018-01-09 21:58:57 +01:00
|
|
|
if filename == '-':
|
2017-12-07 08:52:55 +01:00
|
|
|
print ("Running tests from standard input")
|
|
|
|
else:
|
2018-01-09 21:58:57 +01:00
|
|
|
print ("Running tests in " + filename)
|
|
|
|
|
|
|
|
if filename == '-':
|
|
|
|
f = sys.stdin
|
2017-12-07 08:52:55 +01:00
|
|
|
else:
|
2018-01-09 21:58:57 +01:00
|
|
|
f = open (filename)
|
2017-12-07 08:52:55 +01:00
|
|
|
|
|
|
|
for line in f:
|
2017-12-07 09:54:12 +01:00
|
|
|
fontfile, options, unicodes, glyphs_expected = line.split (":")
|
2018-01-09 21:58:57 +01:00
|
|
|
cwd = os.path.dirname(filename)
|
|
|
|
fontfile = os.path.normpath (os.path.join (cwd, fontfile))
|
2017-12-07 09:54:12 +01:00
|
|
|
|
2017-12-07 08:52:55 +01:00
|
|
|
if line.startswith ("#"):
|
2017-12-07 09:54:12 +01:00
|
|
|
if not reference:
|
2018-01-09 21:58:57 +01:00
|
|
|
print ("# %s %s --unicodes %s" % (hb_shape, fontfile, unicodes))
|
2017-12-07 08:52:55 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
if not reference:
|
2018-01-09 21:58:57 +01:00
|
|
|
print ("%s %s %s %s --unicodes %s" %
|
|
|
|
(hb_shape, fontfile, extra_options, options, unicodes))
|
2017-12-07 08:52:55 +01:00
|
|
|
|
|
|
|
glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft",
|
2018-01-10 13:59:36 +01:00
|
|
|
fontfile, extra_options,
|
|
|
|
] + (options.split (' ') if options else []), utf8(unicodes))
|
2017-12-07 08:52:55 +01:00
|
|
|
|
|
|
|
if returncode:
|
|
|
|
print ("hb-shape --font-funcs=ft failed.", file=sys.stderr)
|
|
|
|
fails = fails + 1
|
|
|
|
#continue
|
|
|
|
|
2018-01-10 13:59:36 +01:00
|
|
|
#glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot",
|
|
|
|
# fontfile, extra_options, "--unicodes",
|
|
|
|
# unicodes] + (options.split (' ') if options else []))
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2018-01-10 13:59:36 +01:00
|
|
|
#if returncode:
|
|
|
|
# print ("ERROR: hb-shape --font-funcs=ot failed.", file=sys.stderr)
|
|
|
|
# fails = fails + 1
|
|
|
|
# #continue
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2018-01-10 13:59:36 +01:00
|
|
|
#if glyphs1 != glyphs2:
|
|
|
|
# print ("FT funcs: " + glyphs1, file=sys.stderr)
|
|
|
|
# print ("OT funcs: " + glyphs2, file=sys.stderr)
|
|
|
|
# fails = fails + 1
|
2017-12-07 08:52:55 +01:00
|
|
|
|
|
|
|
if reference:
|
|
|
|
print (":".join ([fontfile, options, unicodes, glyphs1]))
|
|
|
|
continue
|
|
|
|
|
|
|
|
if glyphs1.strip() != glyphs_expected.strip():
|
|
|
|
print ("Actual: " + glyphs1, file=sys.stderr)
|
|
|
|
print ("Expected: " + glyphs_expected, file=sys.stderr)
|
|
|
|
fails = fails + 1
|
|
|
|
|
|
|
|
if fails != 0:
|
|
|
|
if not reference:
|
|
|
|
print (str (fails) + " tests failed.")
|
|
|
|
sys.exit (1)
|
|
|
|
|
|
|
|
else:
|
|
|
|
if not reference:
|
|
|
|
print ("All tests passed.")
|