From 429b748cecaa046d11f5a93bea0c93c809179ed6 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Wed, 8 Jun 2011 22:00:38 +0200 Subject: [PATCH] py-compile: normalize error and help messages * lib/py-compile: Now error messages do not begin with a capital letter, nor end with a period, as per GNU standards. Prepend the error messages with the name of the script, not with its path. When an invalid usage is recognized, always display the customary message "Try `py-compile --help' ..." on a line of its own. ($me): New variable, containing the name of the program, i.e., `py-compile'. Use it throughout. (usage_error): New function, used to display error messages about invalid usage. * tests/py-compile-usage.test: Extend and tighten accordingly. --- ChangeLog | 14 ++++++++++++++ lib/py-compile | 20 +++++++++++++------- tests/py-compile-usage.test | 7 ++++--- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index f6e80ac..070ac06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-06-08 Stefano Lattarini + py-compile: normalize error and help messages + * lib/py-compile: Now error messages do not begin with a capital + letter, nor end with a period, as per GNU standards. Prepend the + error messages with the name of the script, not with its path. + When an invalid usage is recognized, always display the customary + message "Try `py-compile --help' ..." on a line of its own. + ($me): New variable, containing the name of the + program, i.e., `py-compile'. Use it throughout. + (usage_error): New function, used to display error messages about + invalid usage. + * tests/py-compile-usage.test: Extend and tighten accordingly. + +2011-06-08 Stefano Lattarini + python tests: add "unit tests" on py-compile * tests/py-compile-basic.test: New test. * tests/py-compile-basic2.test: New test. diff --git a/lib/py-compile b/lib/py-compile index 2a526ca..140536b 100755 --- a/lib/py-compile +++ b/lib/py-compile @@ -32,6 +32,15 @@ if [ -z "$PYTHON" ]; then PYTHON=python fi +me=py-compile + +usage_error () +{ + echo "$me: $*" >&2 + echo "Try \`$me --help' for more information." >&2 + exit 1 +} + basedir= destdir= files= @@ -39,8 +48,7 @@ while test $# -ne 0; do case "$1" in --basedir) if test $# -lt 2; then - echo "$0: Missing argument to --basedir." 1>&2 - exit 1 + usage_error "option '--basedir' requires an argument" else basedir=$2 fi @@ -48,8 +56,7 @@ while test $# -ne 0; do ;; --destdir) if test $# -lt 2; then - echo "$0: Missing argument to --destdir." 1>&2 - exit 1 + usage_error "option '--destdir' requires an argument" else destdir=$2 fi @@ -72,7 +79,7 @@ EOF exit $? ;; -v|--v*) - echo "py-compile $scriptversion" + echo "$me $scriptversion" exit $? ;; *) @@ -83,8 +90,7 @@ EOF done if test -z "$files"; then - echo "$0: No files given. Try \`$0 --help' for more information." 1>&2 - exit 1 + usage_error "no files given" fi # if basedir was given, then it should be prepended to filenames before diff --git a/tests/py-compile-usage.test b/tests/py-compile-usage.test index c2a927f..6a0f2f2 100755 --- a/tests/py-compile-usage.test +++ b/tests/py-compile-usage.test @@ -51,7 +51,8 @@ test `wc -l stderr && { cat stderr >&2; Exit 1; } cat stderr >&2 - grep "py-compile:.* [Mm]issing argument.*$opt" stderr + grep "^py-compile: option ['\`]$opt' requires an argument" stderr + grep "^Try [\`']py-compile --help' for more information" stderr done # Missing files. @@ -59,8 +60,8 @@ done for args in '' '--basedir dir' '--destdir dir'; do ./py-compile $args 2>stderr && { cat stderr >&2; Exit 1; } cat stderr >&2 - grep 'py-compile:.* [nN]o files given' stderr - grep "Try [\`'].*py-compile --help' for more information" stderr + grep '^py-compile: no files given' stderr + grep "^Try [\`']py-compile --help' for more information" stderr done : -- 2.7.4