3 import sys, os, subprocess, hashlib
5 def shape_cmd(command):
6 global hb_shape, process
7 print (hb_shape + ' ' + " ".join(command))
8 process.stdin.write ((';'.join (command) + '\n').encode ("utf-8"))
10 return process.stdout.readline().decode ("utf-8").strip ()
14 have_freetype = bool(int(os.getenv ('HAVE_FREETYPE', '1')))
16 if not args or args[0].find('hb-shape') == -1 or not os.path.exists (args[0]):
17 sys.exit ("""First argument does not seem to point to usable hb-shape.""")
18 hb_shape, args = args[0], args[1:]
20 process = subprocess.Popen ([hb_shape, '--batch'],
21 stdin=subprocess.PIPE,
22 stdout=subprocess.PIPE,
34 print ("Running tests from standard input")
36 print ("Running tests in " + filename)
41 f = open (filename, encoding='utf8')
45 if line.startswith ("#"):
49 if line.startswith (' '):
57 fontfile, options, unicodes, glyphs_expected = line.split (';')
58 options = options.split ()
59 if fontfile.startswith ('/') or fontfile.startswith ('"/'):
60 if os.name == 'nt': # Skip on Windows
63 fontfile, expected_hash = (fontfile.split('@') + [''])[:2]
66 with open (fontfile, 'rb') as ff:
68 actual_hash = hashlib.sha1 (ff.read()).hexdigest ().strip ()
69 if actual_hash != expected_hash:
70 print ('different version of %s found; Expected hash %s, got %s; skipping.' %
71 (fontfile, expected_hash, actual_hash))
75 print ('%s not found, skip.' % fontfile)
79 cwd = os.path.dirname(filename)
80 fontfile = os.path.normpath (os.path.join (cwd, fontfile))
82 extra_options = ["--shaper=ot"]
83 if glyphs_expected != '*':
84 extra_options.append("--verify")
87 print ('# %s "%s" --unicodes %s' % (hb_shape, fontfile, unicodes))
90 if "--font-funcs=ft" in options and not have_freetype:
94 if "--font-funcs=ot" in options or not have_freetype:
95 glyphs1 = shape_cmd ([fontfile, "--font-funcs=ot"] + extra_options + ["--unicodes", unicodes] + options)
97 glyphs1 = shape_cmd ([fontfile, "--font-funcs=ft"] + extra_options + ["--unicodes", unicodes] + options)
98 glyphs2 = shape_cmd ([fontfile, "--font-funcs=ot"] + extra_options + ["--unicodes", unicodes] + options)
100 if glyphs1 != glyphs2 and glyphs_expected != '*':
101 print ("FT funcs: " + glyphs1, file=sys.stderr)
102 print ("OT funcs: " + glyphs2, file=sys.stderr)
107 if glyphs1.strip() != glyphs_expected and glyphs_expected != '*':
108 print ("Actual: " + glyphs1, file=sys.stderr)
109 print ("Expected: " + glyphs_expected, file=sys.stderr)
114 print ("%d tests passed; %d failed; %d skipped." % (passes, fails, skips), file=sys.stderr)
115 if not (fails + passes):
116 print ("No tests ran.")
117 elif not (fails + skips):
118 print ("All tests passed.")