2020-02-19 12:26:55 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-03-29 10:18:47 +02:00
|
|
|
|
2020-04-05 20:21:58 +02:00
|
|
|
import sys, os, subprocess, hashlib
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2021-08-10 19:05:40 +02:00
|
|
|
def shape_cmd(command):
|
|
|
|
global hb_shape, process
|
|
|
|
print (hb_shape + ' ' + " ".join(command))
|
|
|
|
process.stdin.write ((';'.join (command) + '\n').encode ("utf-8"))
|
2020-07-02 15:37:01 +02:00
|
|
|
process.stdin.flush ()
|
|
|
|
return process.stdout.readline().decode ("utf-8").strip ()
|
2017-12-07 08:52:55 +01:00
|
|
|
|
|
|
|
args = sys.argv[1:]
|
2018-11-01 02:25:05 +01:00
|
|
|
|
2020-07-06 09:27:45 +02:00
|
|
|
have_freetype = bool(int(os.getenv ('HAVE_FREETYPE', '1')))
|
2020-07-02 15:04:24 +02:00
|
|
|
|
2018-11-01 02:25:05 +01:00
|
|
|
if not args or args[0].find('hb-shape') == -1 or not os.path.exists (args[0]):
|
2020-05-28 20:21:29 +02:00
|
|
|
sys.exit ("""First argument does not seem to point to usable hb-shape.""")
|
2018-01-09 23:15:54 +01:00
|
|
|
hb_shape, args = args[0], args[1:]
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2020-07-02 15:37:01 +02:00
|
|
|
process = subprocess.Popen ([hb_shape, '--batch'],
|
2018-10-30 08:51:43 +01:00
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
2020-07-02 15:37:01 +02:00
|
|
|
stderr=sys.stdout)
|
2018-10-30 08:51:43 +01:00
|
|
|
|
2018-11-24 21:49:33 +01:00
|
|
|
passes = 0
|
2018-01-01 08:47:51 +01:00
|
|
|
fails = 0
|
2018-11-23 13:10:05 +01:00
|
|
|
skips = 0
|
2018-01-01 08:47:51 +01:00
|
|
|
|
2017-12-07 08:52:55 +01:00
|
|
|
if not len (args):
|
2018-01-09 21:58:57 +01:00
|
|
|
args = ['-']
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2018-01-09 21:58:57 +01:00
|
|
|
for filename in args:
|
2021-08-01 19:38:39 +02:00
|
|
|
if filename == '-':
|
|
|
|
print ("Running tests from standard input")
|
|
|
|
else:
|
|
|
|
print ("Running tests in " + filename)
|
2018-01-09 21:58:57 +01:00
|
|
|
|
|
|
|
if filename == '-':
|
|
|
|
f = sys.stdin
|
2017-12-07 08:52:55 +01:00
|
|
|
else:
|
2020-03-14 17:33:14 +01:00
|
|
|
f = open (filename, encoding='utf8')
|
2017-12-07 08:52:55 +01:00
|
|
|
|
|
|
|
for line in f:
|
2018-11-24 21:37:01 +01:00
|
|
|
comment = False
|
|
|
|
if line.startswith ("#"):
|
|
|
|
comment = True
|
|
|
|
line = line[1:]
|
|
|
|
|
|
|
|
if line.startswith (' '):
|
2021-08-01 19:38:39 +02:00
|
|
|
print ("#%s" % line)
|
2018-11-24 21:37:01 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
line = line.strip ()
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
|
2021-08-10 19:05:40 +02:00
|
|
|
fontfile, options, unicodes, glyphs_expected = line.split (';')
|
2020-07-02 15:04:24 +02:00
|
|
|
options = options.split ()
|
2018-11-23 13:10:05 +01:00
|
|
|
if fontfile.startswith ('/') or fontfile.startswith ('"/'):
|
2020-03-14 17:39:00 +01:00
|
|
|
if os.name == 'nt': # Skip on Windows
|
2020-03-14 17:33:14 +01:00
|
|
|
continue
|
|
|
|
|
2021-02-18 20:07:46 +01:00
|
|
|
fontfile, expected_hash = (fontfile.split('@') + [''])[:2]
|
2018-11-23 13:10:05 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
with open (fontfile, 'rb') as ff:
|
2021-02-18 20:07:46 +01:00
|
|
|
if expected_hash:
|
|
|
|
actual_hash = hashlib.sha1 (ff.read()).hexdigest ().strip ()
|
|
|
|
if actual_hash != expected_hash:
|
|
|
|
print ('different version of %s found; Expected hash %s, got %s; skipping.' %
|
|
|
|
(fontfile, expected_hash, actual_hash))
|
|
|
|
skips += 1
|
|
|
|
continue
|
|
|
|
except IOError:
|
2018-11-24 21:49:33 +01:00
|
|
|
print ('%s not found, skip.' % fontfile)
|
|
|
|
skips += 1
|
2018-11-23 13:10:05 +01:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
cwd = os.path.dirname(filename)
|
|
|
|
fontfile = os.path.normpath (os.path.join (cwd, fontfile))
|
2017-12-07 09:54:12 +01:00
|
|
|
|
2018-10-04 16:23:42 +02:00
|
|
|
extra_options = ["--shaper=ot"]
|
2018-10-04 12:13:55 +02:00
|
|
|
if glyphs_expected != '*':
|
|
|
|
extra_options.append("--verify")
|
|
|
|
|
2018-11-24 21:37:01 +01:00
|
|
|
if comment:
|
2021-08-01 19:38:39 +02:00
|
|
|
print ('# %s "%s" --unicodes %s' % (hb_shape, fontfile, unicodes))
|
2017-12-07 08:52:55 +01:00
|
|
|
continue
|
|
|
|
|
2020-07-06 09:27:45 +02:00
|
|
|
if "--font-funcs=ft" in options and not have_freetype:
|
2020-07-02 15:04:24 +02:00
|
|
|
skips += 1
|
|
|
|
continue
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2020-07-06 09:27:45 +02:00
|
|
|
if "--font-funcs=ot" in options or not have_freetype:
|
2021-08-10 19:05:40 +02:00
|
|
|
glyphs1 = shape_cmd ([fontfile, "--font-funcs=ot"] + extra_options + ["--unicodes", unicodes] + options)
|
2018-11-24 21:49:33 +01:00
|
|
|
else:
|
2021-08-10 19:05:40 +02:00
|
|
|
glyphs1 = shape_cmd ([fontfile, "--font-funcs=ft"] + extra_options + ["--unicodes", unicodes] + options)
|
|
|
|
glyphs2 = shape_cmd ([fontfile, "--font-funcs=ot"] + extra_options + ["--unicodes", unicodes] + options)
|
2020-07-02 15:04:24 +02:00
|
|
|
|
|
|
|
if glyphs1 != glyphs2 and glyphs_expected != '*':
|
|
|
|
print ("FT funcs: " + glyphs1, file=sys.stderr)
|
|
|
|
print ("OT funcs: " + glyphs2, file=sys.stderr)
|
|
|
|
fails += 1
|
|
|
|
else:
|
|
|
|
passes += 1
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2020-07-02 15:37:01 +02:00
|
|
|
if glyphs1.strip() != glyphs_expected and glyphs_expected != '*':
|
|
|
|
print ("Actual: " + glyphs1, file=sys.stderr)
|
2020-05-28 21:13:55 +02:00
|
|
|
print ("Expected: " + glyphs_expected, file=sys.stderr)
|
2018-11-24 21:49:33 +01:00
|
|
|
fails += 1
|
|
|
|
else:
|
|
|
|
passes += 1
|
2017-12-07 08:52:55 +01:00
|
|
|
|
2021-08-01 19:38:39 +02:00
|
|
|
print ("%d tests passed; %d failed; %d skipped." % (passes, fails, skips), file=sys.stderr)
|
|
|
|
if not (fails + passes):
|
|
|
|
print ("No tests ran.")
|
|
|
|
elif not (fails + skips):
|
|
|
|
print ("All tests passed.")
|
2018-11-24 21:49:33 +01:00
|
|
|
|
|
|
|
if fails:
|
|
|
|
sys.exit (1)
|
|
|
|
elif passes:
|
|
|
|
sys.exit (0)
|
|
|
|
else:
|
|
|
|
sys.exit (77)
|