mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 23:11:04 +01:00
[test/draw] Switch tests to U+XXXX notation instead of text
This commit is contained in:
1 parent
e91036cf0b
commit
f035a1df87
4 files changed
+33
-11
No files matched your search
+6
-4
@@ -10,19 +10,20 @@ Test file format (`data/tests/*.tests`)
|
||||
Each non-empty, non-comment line has 4 semicolon-separated fields:
|
||||
|
||||
```
|
||||
font-file;options;text;expected-file
|
||||
font-file;options;unicodes;expected-file
|
||||
```
|
||||
|
||||
- `font-file`: relative to the `.tests` file (or absolute path).
|
||||
- `options`: shell-split arguments passed to `hb-draw`.
|
||||
- `text`: literal UTF-8 text argument passed to `hb-draw`.
|
||||
- `unicodes`: Unicode sequence, using shape-style codepoint format
|
||||
(for example `U+0061,U+0062,U+0063`).
|
||||
- `expected-file`: path to golden output, relative to the `.tests` file.
|
||||
This is also used as the TAP test name.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64;abc;../expected/reuse-svg.svg
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64;U+0061,U+0062,U+0063;../expected/reuse-svg.svg
|
||||
```
|
||||
|
||||
Running draw tests
|
||||
@@ -55,4 +56,5 @@ It subsets the input font, verifies subset-vs-original rendering with
|
||||
`../expected/<test-name>.<ext>` (unless `--expected-file` is provided), and
|
||||
appends one test line to the target `.tests` file. `hb-shape`, `hb-view`, and
|
||||
`hb-subset` are resolved as sibling executables next to the provided
|
||||
`hb-draw` binary.
|
||||
`hb-draw` binary. The emitted test line uses Unicode codepoint input in the
|
||||
`unicodes` field.
|
||||
@@ -1,4 +1,4 @@
|
||||
# font-file;options;text;expected-file
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64;abc;../expected/reuse-svg.svg
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64 --ned;abc;../expected/flat-svg.svg
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64 -q;a a;../expected/quiet-paths-space.txt
|
||||
# font-file;options;unicodes;expected-file
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64;U+0061,U+0062,U+0063;../expected/reuse-svg.svg
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64 --ned;U+0061,U+0062,U+0063;../expected/flat-svg.svg
|
||||
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64 -q;U+0061,U+0020,U+0061;../expected/quiet-paths-space.txt
|
||||
@@ -7,7 +7,7 @@ usage() {
|
||||
Usage: $0 [-o TESTS_FILE] [-n TEST_NAME] [-e EXPECTED_FILE] [--expected-dir DIR] [--subset-dir DIR] HB_DRAW FONT_FILE [DRAW_OPTIONS] [TEXT]
|
||||
|
||||
Subset font, verify visual equivalence with hb-view, and append draw test line:
|
||||
font-file;options;text;expected-file
|
||||
font-file;options;unicodes;expected-file
|
||||
|
||||
Options:
|
||||
-o TESTS_FILE Append test line to this file (default: stdout).
|
||||
@@ -190,6 +190,7 @@ if [[ "$test_name" == *$'\n'* ]]; then
|
||||
echo "Test name cannot contain newlines." >&2
|
||||
exit 1
|
||||
fi
|
||||
unicodes=$(/usr/bin/env python3 -c 'import sys; s=sys.argv[1]; print(",".join(f"U+{ord(c):04X}" for c in s))' "$text")
|
||||
|
||||
options_str=
|
||||
for arg in "${options[@]}"; do
|
||||
@@ -278,6 +279,6 @@ else
|
||||
out_file="$out"
|
||||
fi
|
||||
|
||||
echo "${font_field};${options_str};${text};${expected_field}" >> "$out_file"
|
||||
echo "${font_field};${options_str};${unicodes};${expected_field}" >> "$out_file"
|
||||
|
||||
rm -rf "$tmpdir"
|
||||
+20
-1
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -37,6 +38,16 @@ def run_draw(font_path, options, text):
|
||||
return subprocess.run(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
|
||||
|
||||
def parse_unicodes(s):
|
||||
# Match test/shape/hb_test_tools.py Unicode.parse semantics.
|
||||
s = re.sub(r"0[xX]", " ", s)
|
||||
s = re.sub(r"[<+\->{},;&#\\xXuUnNiI\n\t]", " ", s)
|
||||
try:
|
||||
return "".join(chr(int(x, 16)) for x in s.split())
|
||||
except ValueError as e:
|
||||
raise ValueError(f"invalid unicode codepoint list: {s!r}") from e
|
||||
|
||||
|
||||
number = 0
|
||||
fails = 0
|
||||
|
||||
@@ -63,7 +74,7 @@ for filename in args:
|
||||
print("# malformed test line, expected 4 ';'-separated fields")
|
||||
continue
|
||||
|
||||
font_file, options, text, expected_file = fields
|
||||
font_file, options, unicodes, expected_file = fields
|
||||
name = expected_file
|
||||
font_path = resolve_path(base, font_file)
|
||||
expected_path = resolve_path(base, expected_file)
|
||||
@@ -80,6 +91,14 @@ for filename in args:
|
||||
print(f"# expected output file not found: {expected_path}")
|
||||
continue
|
||||
|
||||
try:
|
||||
text = parse_unicodes(unicodes)
|
||||
except ValueError as e:
|
||||
fails += 1
|
||||
print(f"not ok {number} - {name}")
|
||||
print("# " + str(e))
|
||||
continue
|
||||
|
||||
result = run_draw(font_path, options, text)
|
||||
if result.returncode != 0:
|
||||
fails += 1
|
||||
|
||||
Reference in new issue
Block a user