Compare commits

...

1 Commits

Author SHA1 Message Date
Behdad Esfahbod f462f2dbcf [WIP][test] Speed up test runner
Keep one hb-shape process open and stream text to it.
2018-01-10 13:59:36 +01:00
1 changed files with 36 additions and 20 deletions

View File

@ -1,16 +1,32 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
import sys, os, subprocess import sys, os, subprocess, re
p = None
cm = None
def cmd(command): def cmd(command, line):
p = subprocess.Popen ( global p, cm
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if command != cm:
p.wait () if p:
print (p.stderr.read (), file=sys.stderr, end='') p.stdin.close()
return p.stdout.read ().decode ("utf-8").strip(), p.returncode p = subprocess.Popen (command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cm = command
p.stdin.write(line+'\n')
p.stdin.flush()
p.poll()
return p.stdout.readline ().decode ("utf-8").strip(), 0# p.returncode
def parse (s):
s = re.sub (r"0[xX]", " ", s)
s = re.sub (r"[<+>{},;&#\\xXuUnNiI\n\t]", " ", s)
return [int (x, 16) for x in s.split ()]
def utf8 (s):
s = u''.join (unichr (x) for x in parse (s))
if sys.version_info[0] == 2: s = s.encode ('utf-8')
return s
args = sys.argv[1:] args = sys.argv[1:]
if not args or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.argv[1]): if not args or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.argv[1]):
@ -57,27 +73,27 @@ for filename in args:
(hb_shape, fontfile, extra_options, options, unicodes)) (hb_shape, fontfile, extra_options, options, unicodes))
glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft", glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft",
fontfile, extra_options, "--unicodes", fontfile, extra_options,
unicodes] + (options.split (' ') if options else [])) ] + (options.split (' ') if options else []), utf8(unicodes))
if returncode: if returncode:
print ("hb-shape --font-funcs=ft failed.", file=sys.stderr) print ("hb-shape --font-funcs=ft failed.", file=sys.stderr)
fails = fails + 1 fails = fails + 1
#continue #continue
glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot", #glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot",
fontfile, extra_options, "--unicodes", # fontfile, extra_options, "--unicodes",
unicodes] + (options.split (' ') if options else [])) # unicodes] + (options.split (' ') if options else []))
if returncode: #if returncode:
print ("ERROR: hb-shape --font-funcs=ot failed.", file=sys.stderr) # print ("ERROR: hb-shape --font-funcs=ot failed.", file=sys.stderr)
fails = fails + 1 # fails = fails + 1
#continue # #continue
if glyphs1 != glyphs2: #if glyphs1 != glyphs2:
print ("FT funcs: " + glyphs1, file=sys.stderr) # print ("FT funcs: " + glyphs1, file=sys.stderr)
print ("OT funcs: " + glyphs2, file=sys.stderr) # print ("OT funcs: " + glyphs2, file=sys.stderr)
fails = fails + 1 # fails = fails + 1
if reference: if reference:
print (":".join ([fontfile, options, unicodes, glyphs1])) print (":".join ([fontfile, options, unicodes, glyphs1]))