3 from __future__ import print_function, division, absolute_import
5 import sys, os, subprocess, hashlib, tempfile, shutil
9 process.stdin.write ((' '.join (command) + '\n').encode ("utf-8"))
10 process.stdin.flush ()
11 return process.stdout.readline().decode ("utf-8").strip ()
16 if len (args) and args[0] == "--reference":
20 if not args or args[0].find('hb-shape') == -1 or not os.path.exists (args[0]):
21 print ("""First argument does not seem to point to usable hb-shape.""")
23 hb_shape, args = args[0], args[1:]
25 process = subprocess.Popen ([hb_shape, '--batch'],
26 stdin=subprocess.PIPE,
27 stdout=subprocess.PIPE,
40 print ("Running tests from standard input")
42 print ("Running tests in " + filename)
51 if line.startswith ("#"):
55 if line.startswith (' '):
64 fontfile, options, unicodes, glyphs_expected = line.split (":")
65 if fontfile.startswith ('/') or fontfile.startswith ('"/'):
66 fontfile, expected_hash = fontfile.split('@')
69 with open (fontfile, 'rb') as ff:
70 actual_hash = hashlib.sha1 (ff.read()).hexdigest ().strip ()
71 if actual_hash != expected_hash:
72 print ('different version of %s found; Expected hash %s, got %s; skipping.' %
73 (fontfile, expected_hash, actual_hash))
77 print ('%s not found, skip.' % fontfile)
81 cwd = os.path.dirname(filename)
82 fontfile = os.path.normpath (os.path.join (cwd, fontfile))
84 extra_options = ["--shaper=ot"]
85 if glyphs_expected != '*':
86 extra_options.append("--verify")
90 print ('# %s "%s" --unicodes %s' % (hb_shape, fontfile, unicodes))
94 print ('%s "%s" %s %s --unicodes %s' %
95 (hb_shape, fontfile, ' '.join(extra_options), options, unicodes))
97 # hack to support fonts with space on run-tests.py, after several other tries...
99 new_fontfile = os.path.join (tempfile.gettempdir (), 'tmpfile')
100 shutil.copyfile(fontfile, new_fontfile)
101 fontfile = new_fontfile
103 glyphs1 = cmd ([hb_shape, "--font-funcs=ft",
104 fontfile] + extra_options + ["--unicodes",
105 unicodes] + (options.split (' ') if options else []))
107 glyphs2 = cmd ([hb_shape, "--font-funcs=ot",
108 fontfile] + extra_options + ["--unicodes",
109 unicodes] + (options.split (' ') if options else []))
111 if glyphs1 != glyphs2 and glyphs_expected != '*':
112 print ("FT funcs: " + glyphs1) # file=sys.stderr
113 print ("OT funcs: " + glyphs2) # file=sys.stderr
119 print (":".join ([fontfile, options, unicodes, glyphs1]))
122 if glyphs1.strip() != glyphs_expected and glyphs_expected != '*':
123 print ("Actual: " + glyphs1) # file=sys.stderr
124 print ("Expected: " + glyphs_expected) # file=sys.stderr
130 print ("%d tests passed; %d failed; %d skipped." % (passes, fails, skips)) # file=sys.stderr
131 if not (fails + passes):
132 print ("No tests ran.")
133 elif not (fails + skips):
134 print ("All tests passed.")