Skip to content

Commit

Permalink
[detype1] Fix exit code for known options (#536)
Browse files Browse the repository at this point in the history
Partial fix for #347
  • Loading branch information
miguelsousa authored Aug 8, 2018
1 parent 4b5e3b6 commit 9627a82
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
10 changes: 7 additions & 3 deletions c/detype1/source/detype1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -635,5 +638,6 @@ int main(int argc, char *argv[]) {
fclose(fp2);
} else
usage();
return 1;
return 0;
}
21 changes: 21 additions & 0 deletions tests/detype1_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,6 +21,24 @@ def _get_expected_path(file_name):
# Tests
# -----

@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]) == 0


@pytest.mark.parametrize('arg', ['-v', '-u'])
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')
Expand Down
4 changes: 2 additions & 2 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
import tempfile

__version__ = '0.5.2'
__version__ = '0.5.3'

logger = logging.getLogger('runner')

Expand Down Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions tests/runner_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
from __future__ import print_function, division, absolute_import

import platform
import pytest
import subprocess32 as subprocess

from .runner import main as runner
from .runner import _check_tool


def test_bad_tx_cmd():
# Trigger a fatal error from a command line tool, to make sure
# it is handled correctly.
with pytest.raises(subprocess.CalledProcessError):
runner(['-t', 'tx', '-n', '-o', 'bad_opt'])


@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

0 comments on commit 9627a82

Please sign in to comment.