2017-12-07 07:52:55 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-03-29 08:18:47 +00:00
|
|
|
from __future__ import print_function, division, absolute_import
|
|
|
|
|
2018-10-06 08:49:33 +00:00
|
|
|
import sys, os, subprocess, tempfile
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def cmd(command):
|
2018-10-06 08:49:33 +00:00
|
|
|
# https://stackoverflow.com/a/4408409
|
|
|
|
with tempfile.TemporaryFile() as tempf:
|
|
|
|
p = subprocess.Popen (command, stdout=tempf, stderr=sys.stdout)
|
|
|
|
p.wait ()
|
|
|
|
tempf.seek(0)
|
|
|
|
return tempf.read().decode ("utf-8").strip (), p.returncode
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
args = sys.argv[1:]
|
2018-01-09 22:15:54 +00: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 07:52:55 +00:00
|
|
|
|
2018-01-01 07:47:51 +00:00
|
|
|
fails = 0
|
|
|
|
|
2017-12-07 07:52:55 +00:00
|
|
|
reference = False
|
|
|
|
if len (args) and args[0] == "--reference":
|
|
|
|
reference = True
|
|
|
|
args = args[1:]
|
|
|
|
|
|
|
|
if not len (args):
|
2018-01-09 20:58:57 +00:00
|
|
|
args = ['-']
|
2017-12-07 07:52:55 +00:00
|
|
|
|
2018-01-09 20:58:57 +00:00
|
|
|
for filename in args:
|
2017-12-07 07:52:55 +00:00
|
|
|
if not reference:
|
2018-01-09 20:58:57 +00:00
|
|
|
if filename == '-':
|
2017-12-07 07:52:55 +00:00
|
|
|
print ("Running tests from standard input")
|
|
|
|
else:
|
2018-01-09 20:58:57 +00:00
|
|
|
print ("Running tests in " + filename)
|
|
|
|
|
|
|
|
if filename == '-':
|
|
|
|
f = sys.stdin
|
2017-12-07 07:52:55 +00:00
|
|
|
else:
|
2018-01-09 20:58:57 +00:00
|
|
|
f = open (filename)
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
for line in f:
|
2017-12-07 08:54:12 +00:00
|
|
|
fontfile, options, unicodes, glyphs_expected = line.split (":")
|
2018-01-09 20:58:57 +00:00
|
|
|
cwd = os.path.dirname(filename)
|
|
|
|
fontfile = os.path.normpath (os.path.join (cwd, fontfile))
|
2017-12-07 08:54:12 +00:00
|
|
|
|
2018-10-04 14:23:42 +00:00
|
|
|
extra_options = ["--shaper=ot"]
|
2018-10-04 10:13:55 +00:00
|
|
|
glyphs_expected = glyphs_expected.strip()
|
|
|
|
if glyphs_expected != '*':
|
|
|
|
extra_options.append("--verify")
|
|
|
|
|
2017-12-07 07:52:55 +00:00
|
|
|
if line.startswith ("#"):
|
2017-12-07 08:54:12 +00:00
|
|
|
if not reference:
|
2018-01-09 20:58:57 +00:00
|
|
|
print ("# %s %s --unicodes %s" % (hb_shape, fontfile, unicodes))
|
2017-12-07 07:52:55 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
if not reference:
|
2018-01-09 20:58:57 +00:00
|
|
|
print ("%s %s %s %s --unicodes %s" %
|
2018-10-04 10:13:55 +00:00
|
|
|
(hb_shape, fontfile, ' '.join(extra_options), options, unicodes))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft",
|
2018-10-04 10:13:55 +00:00
|
|
|
fontfile] + extra_options + ["--unicodes",
|
2018-01-09 20:58:57 +00:00
|
|
|
unicodes] + (options.split (' ') if options else []))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
if returncode:
|
2018-10-04 14:36:42 +00:00
|
|
|
print ("ERROR: hb-shape --font-funcs=ft failed.") # file=sys.stderr
|
2017-12-07 07:52:55 +00:00
|
|
|
fails = fails + 1
|
|
|
|
#continue
|
|
|
|
|
|
|
|
glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot",
|
2018-10-04 10:13:55 +00:00
|
|
|
fontfile] + extra_options + ["--unicodes",
|
2018-01-09 20:58:57 +00:00
|
|
|
unicodes] + (options.split (' ') if options else []))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
if returncode:
|
2018-01-11 05:18:22 +00:00
|
|
|
print ("ERROR: hb-shape --font-funcs=ot failed.") # file=sys.stderr
|
2017-12-07 07:52:55 +00:00
|
|
|
fails = fails + 1
|
|
|
|
#continue
|
|
|
|
|
2018-10-04 14:36:42 +00:00
|
|
|
if glyphs1 != glyphs2 and glyphs_expected != '*':
|
2018-01-11 05:18:22 +00:00
|
|
|
print ("FT funcs: " + glyphs1) # file=sys.stderr
|
|
|
|
print ("OT funcs: " + glyphs2) # file=sys.stderr
|
2017-12-07 07:52:55 +00:00
|
|
|
fails = fails + 1
|
|
|
|
|
|
|
|
if reference:
|
|
|
|
print (":".join ([fontfile, options, unicodes, glyphs1]))
|
|
|
|
continue
|
|
|
|
|
2018-10-04 10:13:55 +00:00
|
|
|
if glyphs1.strip() != glyphs_expected and glyphs_expected != '*':
|
2018-01-11 05:18:22 +00:00
|
|
|
print ("Actual: " + glyphs1) # file=sys.stderr
|
|
|
|
print ("Expected: " + glyphs_expected) # file=sys.stderr
|
2017-12-07 07:52:55 +00:00
|
|
|
fails = fails + 1
|
|
|
|
|
|
|
|
if fails != 0:
|
|
|
|
if not reference:
|
2018-01-11 05:18:22 +00:00
|
|
|
print (str (fails) + " tests failed.") # file=sys.stderr
|
2017-12-07 07:52:55 +00:00
|
|
|
sys.exit (1)
|
|
|
|
|
|
|
|
else:
|
|
|
|
if not reference:
|
|
|
|
print ("All tests passed.")
|