From d1df90aac02b01ee1ca638b5a30ea7e9ce6bb356 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Wed, 8 Aug 2018 00:31:34 -0700 Subject: [PATCH 1/3] [detype1] Add tests to validate current exit codes --- tests/detype1_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/detype1_test.py b/tests/detype1_test.py index aaffa16ba..84622591c 100755 --- a/tests/detype1_test.py +++ b/tests/detype1_test.py @@ -1,6 +1,9 @@ from __future__ import print_function, division, absolute_import import os +import platform +import pytest +import subprocess32 as subprocess from .runner import main as runner from .differ import main as differ @@ -18,6 +21,24 @@ def _get_expected_path(file_name): # Tests # ----- +@pytest.mark.parametrize('arg', ['-h', '-u']) +def test_exit_known_option(arg): + if platform.system() == 'Windows': + tool_name = TOOL + '.exe' + else: + tool_name = TOOL + assert subprocess.call([tool_name, arg]) == 1 + + +@pytest.mark.parametrize('arg', ['-v', '-a']) +def test_exit_unknown_option(arg): + if platform.system() == 'Windows': + tool_name = TOOL + '.exe' + else: + tool_name = TOOL + assert subprocess.call([tool_name, arg]) == 1 + + def test_run_on_pfa_data(): actual_path = runner(['-t', TOOL, '-f', 'type1.pfa']) expected_path = _get_expected_path('type1.txt') From a041b22205bf4a27569ecb22d6c7269126ebc7f0 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Wed, 8 Aug 2018 01:52:32 -0700 Subject: [PATCH 2/3] [runner] Remove 'detype1' from hack list --- tests/runner.py | 4 ++-- tests/runner_test.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/runner.py b/tests/runner.py index 8f9255a07..1221d9f92 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -17,7 +17,7 @@ import sys import tempfile -__version__ = '0.5.2' +__version__ = '0.5.3' logger = logging.getLogger('runner') @@ -108,7 +108,7 @@ def _check_tool(tool_name): # https://github.com/adobe-type-tools/afdko/issues/347 # https://github.com/adobe-type-tools/afdko/issues/348 if tool_name.split('.')[0] in ('sfntdiff', 'sfntedit', 'makeotfexe', - 'type1', 'detype1'): + 'type1'): return tool_name # XXX end hack try: diff --git a/tests/runner_test.py b/tests/runner_test.py index ca190e9cd..af8a839b6 100755 --- a/tests/runner_test.py +++ b/tests/runner_test.py @@ -4,6 +4,7 @@ import subprocess32 as subprocess from .runner import main as runner +from .runner import _check_tool def test_bad_tx_cmd(): @@ -11,3 +12,8 @@ def test_bad_tx_cmd(): # it is handled correctly. with pytest.raises(subprocess.CalledProcessError): runner(['-t', 'tx', '-n', '-o', 'bad_opt']) + + +@pytest.mark.parametrize('tool_name', ['detype1']) +def test_check_tool_error(tool_name): + assert isinstance(_check_tool(tool_name), tuple) From 2cb8b83c5edf174f419e95d75d6c93addcf38fc8 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Wed, 8 Aug 2018 02:10:08 -0700 Subject: [PATCH 3/3] [detype1] Fix exit code for known options Partial fix for #347 --- c/detype1/source/detype1.c | 10 +++++++--- tests/detype1_test.py | 6 +++--- tests/runner_test.py | 11 ++++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/c/detype1/source/detype1.c b/c/detype1/source/detype1.c index c3fb552f7..5987fe435 100644 --- a/c/detype1/source/detype1.c +++ b/c/detype1/source/detype1.c @@ -534,8 +534,7 @@ static void detype1(FILE *fp1, FILE *fp2) { */ static void usage(void) { - fprintf(stderr, "usage: detype1 [font [text]]\n"); - exit(1); + printf("usage: detype1 [font [text]]\n"); } #ifndef _MSC_VER /* unix */ @@ -593,10 +592,14 @@ int getopt(int argc, char **argv, char *opstring) { int main(int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "?uh")) != EOF) + while ((c = getopt(argc, argv, "h")) != EOF) switch (c) { + case 'h': + usage(); + exit(0); default: usage(); + exit(1); } if (optind == argc) { #if _MSC_VER @@ -635,5 +638,6 @@ int main(int argc, char *argv[]) { fclose(fp2); } else usage(); + return 1; return 0; } diff --git a/tests/detype1_test.py b/tests/detype1_test.py index 84622591c..191fa4774 100755 --- a/tests/detype1_test.py +++ b/tests/detype1_test.py @@ -21,16 +21,16 @@ def _get_expected_path(file_name): # Tests # ----- -@pytest.mark.parametrize('arg', ['-h', '-u']) +@pytest.mark.parametrize('arg', ['-h']) def test_exit_known_option(arg): if platform.system() == 'Windows': tool_name = TOOL + '.exe' else: tool_name = TOOL - assert subprocess.call([tool_name, arg]) == 1 + assert subprocess.call([tool_name, arg]) == 0 -@pytest.mark.parametrize('arg', ['-v', '-a']) +@pytest.mark.parametrize('arg', ['-v', '-u']) def test_exit_unknown_option(arg): if platform.system() == 'Windows': tool_name = TOOL + '.exe' diff --git a/tests/runner_test.py b/tests/runner_test.py index af8a839b6..988219c7e 100755 --- a/tests/runner_test.py +++ b/tests/runner_test.py @@ -1,5 +1,6 @@ from __future__ import print_function, division, absolute_import +import platform import pytest import subprocess32 as subprocess @@ -14,6 +15,14 @@ def test_bad_tx_cmd(): runner(['-t', 'tx', '-n', '-o', 'bad_opt']) -@pytest.mark.parametrize('tool_name', ['detype1']) +@pytest.mark.parametrize('tool_name', ['not_a_tool']) def test_check_tool_error(tool_name): assert isinstance(_check_tool(tool_name), tuple) + + +@pytest.mark.parametrize('tool_name', ['detype1']) +def test_check_tool_unhacked(tool_name): + expected_name = tool_name + if platform.system() == 'Windows': + expected_name += '.exe' + assert _check_tool(tool_name) == expected_name