3 from __future__ import print_function, division, absolute_import
5 import sys, os, subprocess
10 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
12 print (p.stderr.read (), end="") # file=sys.stderr
13 return p.stdout.read ().decode ("utf-8").strip (), p.returncode
17 if not args or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.argv[1]):
18 print ("""First argument does not seem to point to usable hb-shape.""")
20 hb_shape, args = args[0], args[1:]
22 extra_options = "--verify"
27 if len (args) and args[0] == "--reference":
37 print ("Running tests from standard input")
39 print ("Running tests in " + filename)
47 fontfile, options, unicodes, glyphs_expected = line.split (":")
48 cwd = os.path.dirname(filename)
49 fontfile = os.path.normpath (os.path.join (cwd, fontfile))
51 if line.startswith ("#"):
53 print ("# %s %s --unicodes %s" % (hb_shape, fontfile, unicodes))
57 print ("%s %s %s %s --unicodes %s" %
58 (hb_shape, fontfile, extra_options, options, unicodes))
60 glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft",
61 fontfile, extra_options, "--unicodes",
62 unicodes] + (options.split (' ') if options else []))
65 print ("hb-shape --font-funcs=ft failed.") # file=sys.stderr
69 glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot",
70 fontfile, extra_options, "--unicodes",
71 unicodes] + (options.split (' ') if options else []))
74 print ("ERROR: hb-shape --font-funcs=ot failed.") # file=sys.stderr
78 if glyphs1 != glyphs2:
79 print ("FT funcs: " + glyphs1) # file=sys.stderr
80 print ("OT funcs: " + glyphs2) # file=sys.stderr
84 print (":".join ([fontfile, options, unicodes, glyphs1]))
87 if glyphs1.strip() != glyphs_expected.strip():
88 print ("Actual: " + glyphs1) # file=sys.stderr
89 print ("Expected: " + glyphs_expected) # file=sys.stderr
94 print (str (fails) + " tests failed.") # file=sys.stderr
99 print ("All tests passed.")