2017-12-07 07:52:55 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
import sys, os, subprocess
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
input = raw_input
|
|
|
|
except NameError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def cmd(command):
|
|
|
|
p = subprocess.Popen (
|
|
|
|
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
p.wait ()
|
2018-01-09 20:58:57 +00:00
|
|
|
print (p.stderr.read (), file=sys.stderr, end='')
|
2017-12-07 07:52:55 +00:00
|
|
|
return p.stdout.read ().decode ("utf-8"), p.returncode
|
|
|
|
|
|
|
|
|
|
|
|
builddir = os.environ.get ("builddir", ".")
|
|
|
|
top_builddir = os.environ.get ("top_builddir",
|
2018-01-09 22:11:00 +00:00
|
|
|
os.path.normpath (os.path.join (builddir, "..", "..")))
|
2017-12-29 19:43:29 +00:00
|
|
|
utildir = os.environ.get ("utildir", "util")
|
2017-12-07 07:52:55 +00:00
|
|
|
EXEEXT = os.environ.get ("EXEEXT", "")
|
|
|
|
|
|
|
|
extra_options = "--verify"
|
2017-12-29 19:43:29 +00:00
|
|
|
hb_shape = os.path.join (top_builddir, utildir, "hb-shape" + EXEEXT)
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
|
2018-01-01 07:47:51 +00:00
|
|
|
if not os.path.exists (hb_shape):
|
2018-01-09 22:11:00 +00:00
|
|
|
if len (sys.argv) == 1 or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.argv[1]):
|
2018-01-02 20:22:12 +00:00
|
|
|
print ("""Failed to find hb-shape binary automatically,
|
|
|
|
please provide it as the first argument to the tool""")
|
|
|
|
sys.exit (1)
|
|
|
|
|
2018-01-01 07:47:51 +00:00
|
|
|
hb_shape = args[0]
|
|
|
|
args = args[1:]
|
|
|
|
|
|
|
|
fails = 0
|
|
|
|
|
2017-12-07 07:52:55 +00:00
|
|
|
reference = False
|
|
|
|
if len (args) and args[0] == "--reference":
|
|
|
|
reference = True
|
|
|
|
args = args[1:]
|
|
|
|
|
2018-01-01 07:47:51 +00:00
|
|
|
if not reference:
|
|
|
|
print ('hb_shape:', hb_shape)
|
|
|
|
|
2017-12-07 07:52:55 +00:00
|
|
|
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
|
|
|
|
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" %
|
|
|
|
(hb_shape, fontfile, extra_options, options, unicodes))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft",
|
2018-01-09 20:58:57 +00:00
|
|
|
fontfile, extra_options, "--unicodes",
|
|
|
|
unicodes] + (options.split (' ') if options else []))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
if returncode:
|
|
|
|
print ("hb-shape --font-funcs=ft failed.", file=sys.stderr)
|
|
|
|
fails = fails + 1
|
|
|
|
#continue
|
|
|
|
|
|
|
|
glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot",
|
2018-01-09 20:58:57 +00:00
|
|
|
fontfile, extra_options, "--unicodes",
|
|
|
|
unicodes] + (options.split (' ') if options else []))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
if returncode:
|
2018-01-09 20:58:57 +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
|
|
|
|
|
|
|
|
if glyphs1 != glyphs2:
|
|
|
|
print ("FT funcs: " + glyphs1, file=sys.stderr)
|
|
|
|
print ("OT funcs: " + glyphs2, file=sys.stderr)
|
|
|
|
fails = fails + 1
|
|
|
|
|
|
|
|
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.")
|