Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type1] Implement '-h' option. Fix exit code for known options #537

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion c/detype1/source/detype1.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,9 @@ int main(int argc, char *argv[]) {
detype1(fp1, fp2);
fclose(fp1);
fclose(fp2);
} else
} else {
usage();
return 1;
}
return 0;
}
26 changes: 16 additions & 10 deletions c/type1/source/type1.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ for(;;){
*/

static void usage(void) {
fprintf(stderr, "usage: type1 [text [font]]\n");
exit(1);
printf("usage: type1 [text [font]]\n");
}

#ifndef _MSC_VER /* unix */
Expand Down Expand Up @@ -486,11 +485,16 @@ int getopt (int argc, char **argv, char *opstring) {
#endif /* getopt(3) definition for dos */

int main(int argc, char *argv[]) {
int c;
while ((c = getopt(argc, argv, "?")) != EOF)
switch (c) {
default: usage();
}
int c;
while ((c = getopt(argc, argv, "h")) != EOF)
switch (c) {
case 'h':
usage();
exit(0);
default:
usage();
exit(1);
}
if (optind == argc){
#if _MSC_VER
_setmode(_fileno(stdin),_O_BINARY);
Expand Down Expand Up @@ -526,7 +530,9 @@ int main(int argc, char *argv[]) {
type1(fp1,fp2);
fclose(fp1);
fclose(fp2);
} else
usage();
return 0;
} else {
usage();
return 1;
}
return 0;
}
8 changes: 3 additions & 5 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.3'
__version__ = '0.5.4'

logger = logging.getLogger('runner')

Expand Down Expand Up @@ -104,11 +104,9 @@ def _check_tool(tool_name):
"""
if platform.system() == 'Windows':
tool_name += '.exe'
# XXX start hack to bypass these issues
# https://github.com/adobe-type-tools/afdko/issues/347
# XXX start hack to bypass this issue
# https://github.com/adobe-type-tools/afdko/issues/348
if tool_name.split('.')[0] in ('sfntdiff', 'sfntedit', 'makeotfexe',
'type1'):
if tool_name.split('.')[0] in ('sfntdiff', 'sfntedit', 'makeotfexe'):
return tool_name
# XXX end hack
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_check_tool_error(tool_name):
assert isinstance(_check_tool(tool_name), tuple)


@pytest.mark.parametrize('tool_name', ['detype1'])
@pytest.mark.parametrize('tool_name', ['detype1', 'type1'])
def test_check_tool_unhacked(tool_name):
expected_name = tool_name
if platform.system() == 'Windows':
Expand Down
21 changes: 21 additions & 0 deletions tests/type1_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_txt_data():
actual_path = runner(['-t', TOOL, '-f', 'type1.txt'])
expected_path = _get_expected_path('type1.pfa')
Expand Down