From f035a1df87cd4933e8fcf1f7397a12062a867945 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 Feb 2026 00:12:45 -0700 Subject: [PATCH] [test/draw] Switch tests to U+XXXX notation instead of text --- test/draw/README.md | 10 ++++++---- test/draw/data/tests/basic.tests | 8 ++++---- test/draw/record-test.sh | 5 +++-- test/draw/run-tests.py | 21 ++++++++++++++++++++- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/test/draw/README.md b/test/draw/README.md index e5a53c352..0285b3f1e 100644 --- a/test/draw/README.md +++ b/test/draw/README.md @@ -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/.` (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. diff --git a/test/draw/data/tests/basic.tests b/test/draw/data/tests/basic.tests index 7127bfcc5..c7c6b3f39 100644 --- a/test/draw/data/tests/basic.tests +++ b/test/draw/data/tests/basic.tests @@ -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 diff --git a/test/draw/record-test.sh b/test/draw/record-test.sh index 9c7d8d731..2c63cea34 100755 --- a/test/draw/record-test.sh +++ b/test/draw/record-test.sh @@ -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" diff --git a/test/draw/run-tests.py b/test/draw/run-tests.py index 4574b9e7a..6dc51b6b9 100755 --- a/test/draw/run-tests.py +++ b/test/draw/run-tests.py @@ -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