2020-02-19 11:26:55 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-03-29 08:18:47 +00:00
|
|
|
|
2018-11-23 12:10:05 +00:00
|
|
|
import sys, os, subprocess, hashlib, tempfile, shutil
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
2018-11-01 01:25:05 +00:00
|
|
|
|
|
|
|
reference = False
|
|
|
|
if len (args) and args[0] == "--reference":
|
|
|
|
reference = True
|
|
|
|
args = args[1:]
|
|
|
|
|
|
|
|
if not args or args[0].find('hb-shape') == -1 or not os.path.exists (args[0]):
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("""First argument does not seem to point to usable hb-shape.""")
|
2018-01-09 22:15:54 +00:00
|
|
|
hb_shape, args = args[0], args[1:]
|
2017-12-07 07:52:55 +00:00
|
|
|
|
2020-03-13 07:49:08 +00:00
|
|
|
def cmd(command):
|
|
|
|
process = subprocess.Popen ([hb_shape, '--batch'],
|
2018-10-30 07:51:43 +00:00
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
2020-03-13 07:49:08 +00:00
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
process.stdin.write ((' '.join (command) + '\n').encode ("utf-8"))
|
|
|
|
process.stdin.flush ()
|
|
|
|
ret_stdout = None
|
|
|
|
ret_stderr = None
|
|
|
|
ret_stdout, ret_stderr = process.communicate ()
|
|
|
|
if ret_stdout is not None:
|
|
|
|
ret_stdout = ret_stdout.decode ("utf-8").strip ()
|
|
|
|
if ret_stderr is not None:
|
|
|
|
ret_stderr = ret_stderr.decode ("utf-8").strip ()
|
|
|
|
return (ret_stdout, ret_stderr)
|
2018-10-30 07:51:43 +00:00
|
|
|
|
2018-11-24 20:49:33 +00:00
|
|
|
passes = 0
|
2018-01-01 07:47:51 +00:00
|
|
|
fails = 0
|
2018-11-23 12:10:05 +00:00
|
|
|
skips = 0
|
2018-01-01 07:47:51 +00:00
|
|
|
|
2017-12-07 07:52:55 +00:00
|
|
|
if not len (args):
|
2018-01-09 20:58:57 +00:00
|
|
|
args = ['-']
|
2017-12-07 07:52:55 +00:00
|
|
|
|
2018-01-09 20:58:57 +00:00
|
|
|
for filename in args:
|
2017-12-07 07:52:55 +00:00
|
|
|
if not reference:
|
2018-01-09 20:58:57 +00:00
|
|
|
if filename == '-':
|
2017-12-07 07:52:55 +00:00
|
|
|
print ("Running tests from standard input")
|
|
|
|
else:
|
2018-01-09 20:58:57 +00:00
|
|
|
print ("Running tests in " + filename)
|
|
|
|
|
|
|
|
if filename == '-':
|
|
|
|
f = sys.stdin
|
2017-12-07 07:52:55 +00:00
|
|
|
else:
|
2020-03-14 16:33:14 +00:00
|
|
|
f = open (filename, encoding='utf8')
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
for line in f:
|
2018-11-24 20:37:01 +00:00
|
|
|
comment = False
|
|
|
|
if line.startswith ("#"):
|
|
|
|
comment = True
|
|
|
|
line = line[1:]
|
|
|
|
|
|
|
|
if line.startswith (' '):
|
|
|
|
if not reference:
|
|
|
|
print ("#%s" % line)
|
|
|
|
continue
|
|
|
|
|
|
|
|
line = line.strip ()
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
|
2017-12-07 08:54:12 +00:00
|
|
|
fontfile, options, unicodes, glyphs_expected = line.split (":")
|
2018-11-23 12:10:05 +00:00
|
|
|
if fontfile.startswith ('/') or fontfile.startswith ('"/'):
|
2020-03-14 16:39:00 +00:00
|
|
|
if os.name == 'nt': # Skip on Windows
|
2020-03-14 16:33:14 +00:00
|
|
|
continue
|
|
|
|
|
2018-11-23 12:10:05 +00:00
|
|
|
fontfile, expected_hash = fontfile.split('@')
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open (fontfile, 'rb') as ff:
|
|
|
|
actual_hash = hashlib.sha1 (ff.read()).hexdigest ().strip ()
|
|
|
|
if actual_hash != expected_hash:
|
2018-11-24 20:49:33 +00:00
|
|
|
print ('different version of %s found; Expected hash %s, got %s; skipping.' %
|
2018-11-23 12:10:05 +00:00
|
|
|
(fontfile, expected_hash, actual_hash))
|
2018-11-24 20:49:33 +00:00
|
|
|
skips += 1
|
2018-11-23 12:10:05 +00:00
|
|
|
continue
|
|
|
|
except:
|
2018-11-24 20:49:33 +00:00
|
|
|
print ('%s not found, skip.' % fontfile)
|
|
|
|
skips += 1
|
2018-11-23 12:10:05 +00:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
cwd = os.path.dirname(filename)
|
|
|
|
fontfile = os.path.normpath (os.path.join (cwd, fontfile))
|
2017-12-07 08:54:12 +00:00
|
|
|
|
2018-10-04 14:23:42 +00:00
|
|
|
extra_options = ["--shaper=ot"]
|
2018-10-04 10:13:55 +00:00
|
|
|
if glyphs_expected != '*':
|
|
|
|
extra_options.append("--verify")
|
|
|
|
|
2018-11-24 20:37:01 +00:00
|
|
|
if comment:
|
2017-12-07 08:54:12 +00:00
|
|
|
if not reference:
|
2018-11-25 03:01:06 +00:00
|
|
|
print ('# %s "%s" --unicodes %s' % (hb_shape, fontfile, unicodes))
|
2017-12-07 07:52:55 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
if not reference:
|
2018-11-25 03:01:06 +00:00
|
|
|
print ('%s "%s" %s %s --unicodes %s' %
|
2018-10-04 10:13:55 +00:00
|
|
|
(hb_shape, fontfile, ' '.join(extra_options), options, unicodes))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
2018-11-23 12:10:05 +00:00
|
|
|
# hack to support fonts with space on run-tests.py, after several other tries...
|
|
|
|
if ' ' in fontfile:
|
|
|
|
new_fontfile = os.path.join (tempfile.gettempdir (), 'tmpfile')
|
|
|
|
shutil.copyfile(fontfile, new_fontfile)
|
|
|
|
fontfile = new_fontfile
|
|
|
|
|
2018-10-30 07:51:43 +00:00
|
|
|
glyphs1 = cmd ([hb_shape, "--font-funcs=ft",
|
2018-10-04 10:13:55 +00:00
|
|
|
fontfile] + extra_options + ["--unicodes",
|
2018-01-09 20:58:57 +00:00
|
|
|
unicodes] + (options.split (' ') if options else []))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
2020-03-13 07:49:08 +00:00
|
|
|
if glyphs1[1] is not None or glyphs1[1] != '':
|
|
|
|
check_string = hb_shape[hb_shape.find(os.path.sep) + 1:] + \
|
|
|
|
': Unknown font function implementation `ft\''
|
|
|
|
if glyphs1[1].startswith(check_string):
|
|
|
|
skips += 1
|
|
|
|
print ("Skipping test due to lack of FreeType support")
|
|
|
|
continue
|
|
|
|
|
2018-10-30 07:51:43 +00:00
|
|
|
glyphs2 = cmd ([hb_shape, "--font-funcs=ot",
|
2018-10-04 10:13:55 +00:00
|
|
|
fontfile] + extra_options + ["--unicodes",
|
2018-01-09 20:58:57 +00:00
|
|
|
unicodes] + (options.split (' ') if options else []))
|
2017-12-07 07:52:55 +00:00
|
|
|
|
2020-03-13 07:49:08 +00:00
|
|
|
if glyphs1[0] != glyphs2[0] and glyphs_expected != '*':
|
2020-05-28 19:13:55 +00:00
|
|
|
print ("FT funcs: " + glyphs1[0], file=sys.stderr)
|
|
|
|
print ("OT funcs: " + glyphs2[0], file=sys.stderr)
|
2018-11-24 20:49:33 +00:00
|
|
|
fails += 1
|
|
|
|
else:
|
|
|
|
passes += 1
|
2017-12-07 07:52:55 +00:00
|
|
|
|
|
|
|
if reference:
|
2020-03-13 07:49:08 +00:00
|
|
|
print (":".join ([fontfile, options, unicodes, glyphs1[0]]))
|
2017-12-07 07:52:55 +00:00
|
|
|
continue
|
|
|
|
|
2020-03-13 07:49:08 +00:00
|
|
|
if glyphs1[0].strip() != glyphs_expected and glyphs_expected != '*':
|
2020-05-28 19:13:55 +00:00
|
|
|
print ("Actual: " + glyphs1[0], file=sys.stderr)
|
|
|
|
print ("Expected: " + glyphs_expected, file=sys.stderr)
|
2018-11-24 20:49:33 +00:00
|
|
|
fails += 1
|
|
|
|
else:
|
|
|
|
passes += 1
|
2017-12-07 07:52:55 +00:00
|
|
|
|
2018-11-24 20:49:33 +00:00
|
|
|
if not reference:
|
2020-05-28 19:13:55 +00:00
|
|
|
print ("%d tests passed; %d failed; %d skipped." % (passes, fails, skips), file=sys.stderr)
|
2018-11-24 20:49:33 +00:00
|
|
|
if not (fails + passes):
|
|
|
|
print ("No tests ran.")
|
|
|
|
elif not (fails + skips):
|
2017-12-07 07:52:55 +00:00
|
|
|
print ("All tests passed.")
|
2018-11-24 20:49:33 +00:00
|
|
|
|
|
|
|
if fails:
|
|
|
|
sys.exit (1)
|
|
|
|
elif passes:
|
|
|
|
sys.exit (0)
|
|
|
|
else:
|
|
|
|
sys.exit (77)
|