diff --git a/test/subset/run-repack-tests.py b/test/subset/run-repack-tests.py index 22154ba9f..2334edfee 100755 --- a/test/subset/run-repack-tests.py +++ b/test/subset/run-repack-tests.py @@ -22,6 +22,12 @@ except ImportError: ots_sanitize = shutil.which ("ots-sanitize") +def subset_cmd (command): + global process + process.stdin.write ((';'.join (command) + '\n').encode ("utf-8")) + process.stdin.flush () + return process.stdout.readline().decode ("utf-8").strip () + def cmd (command): p = subprocess.Popen ( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -45,10 +51,10 @@ def run_test (test, should_check_ots): "--unicodes=%s" % test.codepoints_string (), "--drop-tables-=GPOS,GSUB,GDEF",] print (' '.join (cli_args)) - _, return_code = cmd (cli_args) + ret = subset_cmd (cli_args) - if return_code: - return fail_test (test, cli_args, "%s returned %d" % (' '.join (cli_args), return_code)) + if ret != "success": + return fail_test (test, cli_args, "%s failed" % ' '.join (cli_args)) try: with TTFont (out_file) as font: @@ -87,6 +93,11 @@ if len (args) != 1: has_ots = has_ots() +process = subprocess.Popen ([hb_subset, '--batch'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=sys.stdout) + fails = 0 path = args[0] diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py index c86c6bc41..c9bd58db7 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py @@ -22,6 +22,12 @@ except ImportError: ots_sanitize = shutil.which ("ots-sanitize") +def subset_cmd (command): + global process + process.stdin.write ((';'.join (command) + '\n').encode ("utf-8")) + process.stdin.flush () + return process.stdout.readline().decode ("utf-8").strip () + def cmd (command): p = subprocess.Popen ( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -51,10 +57,10 @@ def run_test (test, should_check_ots): "--drop-tables-=sbix"] cli_args.extend (test.get_profile_flags ()) print (' '.join (cli_args)) - _, return_code = cmd (cli_args) + ret = subset_cmd (cli_args) - if return_code: - return fail_test (test, cli_args, "%s returned %d" % (' '.join (cli_args), return_code)) + if ret != "success": + return fail_test (test, cli_args, "%s failed" % ' '.join (cli_args)) expected_file = os.path.join (test_suite.get_output_directory (), test.get_font_ttx_name ()) with open(expected_file, encoding="utf-8") as expected_ttx: @@ -115,6 +121,11 @@ if not len (args): has_ots = has_ots() +process = subprocess.Popen ([hb_subset, '--batch'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=sys.stdout) + fails = 0 for path in args: with open (path, mode="r", encoding="utf-8") as f: diff --git a/util/hb-subset.cc b/util/hb-subset.cc index 3a69f66b9..4ad3f54b9 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -130,6 +130,40 @@ struct subset_consumer_t int main (int argc, char **argv) { + if (argc == 2 && !strcmp (argv[1], "--batch")) + { + unsigned int ret = 0; + char buf[4092]; + while (fgets (buf, sizeof (buf), stdin)) + { + size_t l = strlen (buf); + if (l && buf[l - 1] == '\n') buf[l - 1] = '\0'; + main_font_text_t driver; + char *args[32]; + argc = 0; + char *p = buf, *e; + args[argc++] = p; + unsigned start_offset = 0; + while ((e = strchr (p + start_offset, ';')) && argc < (int) ARRAY_LENGTH (args)) + { + *e++ = '\0'; + while (*e == ':') + e++; + args[argc++] = p = e; + } + int result = driver.main (argc, args); + if (result == 0) + fprintf (stdout, "success\n"); + else + fprintf (stdout, "failure\n"); + ret |= result; + fflush (stdout); + + if (ret) + break; + } + return ret; + } main_font_text_t driver; return driver.main (argc, argv); }