3 import sys, os, subprocess, hashlib, tempfile, shutil
9 if len (args) and args[0] == "--reference":
13 if not args or args[0].find('hb-shape') == -1 or not os.path.exists (args[0]):
14 sys.exit ("""First argument does not seem to point to usable hb-shape.""")
15 hb_shape, args = args[0], args[1:]
18 process = subprocess.Popen ([hb_shape, '--batch'],
19 stdin=subprocess.PIPE,
20 stdout=subprocess.PIPE,
21 stderr=subprocess.PIPE)
22 process.stdin.write ((' '.join (command) + '\n').encode ("utf-8"))
23 process.stdin.flush ()
26 ret_stdout, ret_stderr = process.communicate ()
27 if ret_stdout is not None:
28 ret_stdout = ret_stdout.decode ("utf-8").strip ()
29 if ret_stderr is not None:
30 ret_stderr = ret_stderr.decode ("utf-8").strip ()
31 return (ret_stdout, ret_stderr)
43 print ("Running tests from standard input")
45 print ("Running tests in " + filename)
50 f = open (filename, encoding='utf8')
54 if line.startswith ("#"):
58 if line.startswith (' '):
67 fontfile, options, unicodes, glyphs_expected = line.split (":")
68 if fontfile.startswith ('/') or fontfile.startswith ('"/'):
69 if os.name == 'nt': # Skip on Windows
72 fontfile, expected_hash = fontfile.split('@')
75 with open (fontfile, 'rb') as ff:
76 actual_hash = hashlib.sha1 (ff.read()).hexdigest ().strip ()
77 if actual_hash != expected_hash:
78 print ('different version of %s found; Expected hash %s, got %s; skipping.' %
79 (fontfile, expected_hash, actual_hash))
83 print ('%s not found, skip.' % fontfile)
87 cwd = os.path.dirname(filename)
88 fontfile = os.path.normpath (os.path.join (cwd, fontfile))
90 extra_options = ["--shaper=ot"]
91 if glyphs_expected != '*':
92 extra_options.append("--verify")
96 print ('# %s "%s" --unicodes %s' % (hb_shape, fontfile, unicodes))
100 print ('%s "%s" %s %s --unicodes %s' %
101 (hb_shape, fontfile, ' '.join(extra_options), options, unicodes))
103 # hack to support fonts with space on run-tests.py, after several other tries...
105 new_fontfile = os.path.join (tempfile.gettempdir (), 'tmpfile')
106 shutil.copyfile(fontfile, new_fontfile)
107 fontfile = new_fontfile
109 glyphs1 = cmd ([hb_shape, "--font-funcs=ft",
110 fontfile] + extra_options + ["--unicodes",
111 unicodes] + (options.split (' ') if options else []))
113 if glyphs1[1] is not None or glyphs1[1] != '':
114 check_string = hb_shape[hb_shape.find(os.path.sep) + 1:] + \
115 ': Unknown font function implementation `ft\''
116 if glyphs1[1].startswith(check_string):
118 print ("Skipping test due to lack of FreeType support")
121 glyphs2 = cmd ([hb_shape, "--font-funcs=ot",
122 fontfile] + extra_options + ["--unicodes",
123 unicodes] + (options.split (' ') if options else []))
125 if glyphs1[0] != glyphs2[0] and glyphs_expected != '*':
126 print ("FT funcs: " + glyphs1[0], file=sys.stderr)
127 print ("OT funcs: " + glyphs2[0], file=sys.stderr)
133 print (":".join ([fontfile, options, unicodes, glyphs1[0]]))
136 if glyphs1[0].strip() != glyphs_expected and glyphs_expected != '*':
137 print ("Actual: " + glyphs1[0], file=sys.stderr)
138 print ("Expected: " + glyphs_expected, file=sys.stderr)
144 print ("%d tests passed; %d failed; %d skipped." % (passes, fails, skips), file=sys.stderr)
145 if not (fails + passes):
146 print ("No tests ran.")
147 elif not (fails + skips):
148 print ("All tests passed.")