3 from __future__ import print_function
4 import sys, os, subprocess
9 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
11 print (p.stderr.read (), end="") # file=sys.stderr
12 return p.stdout.read ().decode ("utf-8").strip (), p.returncode
16 if not args or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.argv[1]):
17 print ("""First argument does not seem to point to usable hb-shape.""")
19 hb_shape, args = args[0], args[1:]
21 extra_options = "--verify"
26 if len (args) and args[0] == "--reference":
36 print ("Running tests from standard input")
38 print ("Running tests in " + filename)
46 fontfile, options, unicodes, glyphs_expected = line.split (":")
47 cwd = os.path.dirname(filename)
48 fontfile = os.path.normpath (os.path.join (cwd, fontfile))
50 if line.startswith ("#"):
52 print ("# %s %s --unicodes %s" % (hb_shape, fontfile, unicodes))
56 print ("%s %s %s %s --unicodes %s" %
57 (hb_shape, fontfile, extra_options, options, unicodes))
59 glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft",
60 fontfile, extra_options, "--unicodes",
61 unicodes] + (options.split (' ') if options else []))
64 print ("hb-shape --font-funcs=ft failed.") # file=sys.stderr
68 glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot",
69 fontfile, extra_options, "--unicodes",
70 unicodes] + (options.split (' ') if options else []))
73 print ("ERROR: hb-shape --font-funcs=ot failed.") # file=sys.stderr
77 if glyphs1 != glyphs2:
78 print ("FT funcs: " + glyphs1) # file=sys.stderr
79 print ("OT funcs: " + glyphs2) # file=sys.stderr
83 print (":".join ([fontfile, options, unicodes, glyphs1]))
86 if glyphs1.strip() != glyphs_expected.strip():
87 print ("Actual: " + glyphs1) # file=sys.stderr
88 print ("Expected: " + glyphs_expected) # file=sys.stderr
93 print (str (fails) + " tests failed.") # file=sys.stderr
98 print ("All tests passed.")