[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/6] py-compile: normalize error and help messages
From: |
Stefano Lattarini |
Subject: |
[PATCH 4/6] py-compile: normalize error and help messages |
Date: |
Thu, 9 Jun 2011 16:15:25 +0200 |
* 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 <address@hidden>
+ 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 <address@hidden>
+
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 <stdout` -eq 1
for opt in --basedir --destdir; do
./py-compile $opt 2>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
:
--
1.7.2.3
- [PATCH 0/6] Some python patches, Stefano Lattarini, 2011/06/09
- [PATCH 2/6] py-compile: the '--destdir' option now accepts a blank argument, Stefano Lattarini, 2011/06/09
- [PATCH 4/6] py-compile: normalize error and help messages,
Stefano Lattarini <=
- [PATCH 5/6] py-compile: complain on unrecognized options, Stefano Lattarini, 2011/06/09
- [PATCH 1/6] python: run the 'py-compile' script with $(SHELL), Stefano Lattarini, 2011/06/09
- [PATCH 3/6] python tests: add "unit tests" on py-compile, Stefano Lattarini, 2011/06/09
- [PATCH 6/6] py-compile: '--' and non-option arguments terminate the option list, Stefano Lattarini, 2011/06/09
- Re: [PATCH 0/6] Some python patches, Stefano Lattarini, 2011/06/12