Author: sebor
Date: Mon Jul 10 16:08:31 2006
New Revision: 420652
URL: http://svn.apache.org/viewvc?rev=420652&view=rev
Log:
2006-07-10 Martin Sebor <[EMAIL PROTECTED]>
* run_locale_utils.sh (check_locale_location): Removed a bogus test.
(locale, localedef): Added helper variables to refer to the utilities
in the CWD.
(check_locale_xxx): Removed "let x+= 1" Bash-isms, replaced the non
portable Linux extension echo -n with printf.
(generate_locale): Removed inadvertent backgrounding of process.
(test_locale): Added assertions.
Used process id in temporary file name(s) and removed on exit.
Removed redundant debugging output.
Modified:
incubator/stdcxx/trunk/etc/config/run_locale_utils.sh
Modified: incubator/stdcxx/trunk/etc/config/run_locale_utils.sh
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/run_locale_utils.sh?rev=420652&r1=420651&r2=420652&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/run_locale_utils.sh (original)
+++ incubator/stdcxx/trunk/etc/config/run_locale_utils.sh Mon Jul 10 16:08:31
2006
@@ -1,4 +1,5 @@
-#! /bin/sh
+#!/bin/sh
+#
# $Id$
#
##############################################################################
@@ -24,40 +25,26 @@
#
##############################################################################
+locale="./locale"
+localedef="./localedef"
+
##############################################################################
# Function definitions - checking sanity
##############################################################################
-check_locale_location()
-{
- # 1 = location of util directory
- $echo_n "Checking location of locale utilities..." >$dbgout
- if test "`which locale`" != "$1/locale" ; then
- echo " incorrect." >$dbgout
- echo "ERROR: Locale utility is not present." >$dbgout
- echo >$dbgout
- exit 1
- fi
- if test "`which localedef`" != "$1/localedef"; then
- echo "ERROR: Localedef utility is not present." >$dbgout
- echo >$dbgout
- exit 1
- fi
- echo " correct." >$dbgout
-}
check_locale_help ()
{
- $echo_n "Checking \"locale --help\" output..." >$dbgout
- loc_h_out=`locale --help`
+ printf "Checking \"locale --help\" output..." >$dbgout
+ loc_h_out=`${locale} --help`
loc_h_xout="NAME SYNOPSIS DESCRIPTION"
loc_h_regexp="locale - get locale-specific information"
for it in $loc_h_xout; do
- let assertions+=1
+ assertions=`expr $assertions + 1`
if test -z "`echo $loc_h_out | grep $it`"; then
echo " incorrect." >$dbgout
echo "ERROR: \"locale --help\" gives wrong output ($it)." >$dbgout
echo >$dbgout
- let failedassertions+=1
+ failedassertions=`expr $failedassertions + 1`
fi;
done
echo " correct." >$dbgout
@@ -65,17 +52,17 @@
check_locale_all()
{
- $echo_n "Checking \"locale -a\" output..." >$dbgout
- loc_a_out=`locale -a`
+ printf "Checking \"locale -a\" output..." >$dbgout
+ loc_a_out=`${locale} -a`
loc_a_regexp="[a-z]\{2\}_[A-Z]\{2\}"
for it in $loc_a_out; do
- let assertions+=1
+ assertions=`expr $assertions + 1`
test "$it" = "C" && continue;
if test -z "`echo $it | grep -e \"$loc_a_regexp\"`"; then
echo "incorrect." >$dbgout
echo " Warning: Locale name \"$it\" not matching pattern." \
>$dbgout
- let failedassertions+=1
+ failedassertions=`expr $failedassertions + 1`
fi;
done
echo "check completed." >$dbgout
@@ -83,15 +70,15 @@
check_locale_m()
{
- $echo_n "Checking \"locale -m\" output..." >$dbgout
- loc_m_out=`locale -m`
+ printf "Checking \"locale -m\" output..." >$dbgout
+ loc_m_out=`${locale} -m`
for it in $loc_m_out; do
- let assertions+=1
+ assertions=`expr $assertions + 1`
if test -z "`echo $it | grep .cm`" ; then
echo " incorrect." >$dbgout
echo "ERROR: \"locale -m\" failed." >$dbgout
echo >$dbgout
- let failedassertions+=1
+ failedassertions=`expr $failedassertions + 1`
fi;
done;
echo " correct." >$dbgout
@@ -99,8 +86,8 @@
check_locale_k()
{
- $echo_n "Checking \"locale -k LC_ALL\" output..." >$dbgout
- loc_k_out=`locale -k LC_ALL`
+ printf "Checking \"locale -k LC_ALL\" output..." >$dbgout
+ loc_k_out=`${locale} -k LC_ALL`
loc_k_xout="upper lower space print \
cntrl alpha digit punct \
graph xdigit toupper tolower \
@@ -111,31 +98,36 @@
int_frac_digits frac_digits p_cs_precedes p_sep_by_space \
n_cs_precedes n_sep_by_space p_sign_posn n_sign_posn \
decimal_point thousands_sep grouping"
+
+ any_failed=0
for it in $loc_k_xout; do
- let assertions+=1;
+ assertions=`expr $assertions + 1`;
if test -z "`echo $loc_k_out | grep $it`"; then
- echo " incorrect." >$dbgout
+ # output text only for the first failure
+ [ $any_failed -eq 0 ] && echo " incorrect." >$dbgout
echo "ERROR: \"locale -k\" gives wrong output ($it)." >$dbgout
echo >$dbgout
- let failedassertions+=1
+ failedassertions=`expr $failedassertions + 1`
+ any_failed=1
fi;
done
- echo " (seems) correct." >$dbgout
+
+ [ $any_failed -eq 0 ] && echo " correct." >$dbgout
}
check_localedef_help()
{
- $echo_n "Checking \"localedef --help\" output..." >$dbgout
- locdef_h_out=`localedef --help`
+ printf "Checking \"localedef --help\" output..." >$dbgout
+ locdef_h_out=`${localedef} --help`
locdef_h_xout="NAME SYNOPSIS DESCRIPTION"
locdef_h_regexp="localedef - generate a locale environment"
for it in $locdef_h_xout; do
- let assertions+=1;
+ assertions=`expr $assertions + 1`;
if test -z "`echo $locdef_h_out | grep $it`"; then
echo " incorrect." >$dbgout
echo "ERROR: \"localedef --help\" gives wrong output ($it)."
>$dbgout
echo >$dbgout
- let failedassertions+=1
+ failedassertions=`expr $failedassertions + 1`
fi;
done
echo " correct." >$dbgout
@@ -172,20 +164,17 @@
exit 1;
fi
- let assertions+=1
+ assertions=`expr $assertions + 1`
# Generating the database
- echo Generating locale database $3... >$dbgout
- echo "localedef -c -f $1 -i $2 $3 &>/dev/null" >$dbgout
- localedef -c -f $1 -i $2 $3 &>/dev/null
+ echo "${localedef} -w -c -f $1 -i $2 $3 2>/dev/null" >$dbgout
+ ${localedef} -w -c -f $1 -i $2 $3 2>/dev/null
retcode=$?
if [ $retcode -ne 0 ] ; then
echo "Error - localedef returned code: $retcode" >>$out
- let failedassertions+=1
+ failedassertions=`expr $failedassertions + 1`
fi
-
- echo Done generating locale database. >$dbgout
}
#
@@ -202,20 +191,17 @@
exit 1
fi
- let assertions+=1
+ assertions=`expr $assertions + 1`
# Dumping locale database
- echo Dump current locale to $1... > $dbgout
- echo "locale -ck -h LC_ALL > $1" > $dbgout
- locale -ck -h LC_ALL > $1
+ echo "${locale} -ck -h LC_ALL > $1" > $dbgout
+ ${locale} -ck -h LC_ALL > $1
retcode=$?
if [ $retcode -ne 0 ] ; then
echo "Error - locale returned code: $retcode" >>$out
- let failedassertions+=1
+ failedassertions=`expr $failedassertions + 1`
fi
-
- echo Dumping done. > $dbgout
}
#
@@ -264,50 +250,40 @@
export RWSTD_LOCALE_ROOT
# dump the locale database content to temporary location
- echo Dump stage one database to file... > $dbgout
dump_locale $2/out.1
echo > $dbgout
# remove stage one database
- echo Remove stage one database... > $dbgout
+ echo "rm -rf $2/$3"
rm -rf $2/$3
- echo > $dbgout
# generate stage two database
- echo Generate stage two database... > $dbgout
generate_locale $1/charmaps/$locale_encoding \
$2/out.1 \
$2/$3
- echo > $dbgout
# dump stage two database to file
- echo Dump stage two database to file... > $dbgout
dump_locale $2/out.2
- echo > $dbgout
# remove stage two database
- echo Remove stage two database... > $dbgout
+ echo "rm -rf $2/$3"
rm -rf $2/$3
- echo > $dbgout
-
+
# generate stage three database
- echo Generate stage three database... > $dbgout
generate_locale $1/charmaps/$locale_encoding \
$2/out.2 \
$2/$3
- echo > $dbgout
# and finally dump it to file
- echo Dump stage three database to file... > $dbgout
dump_locale $2/out.3
- echo > $dbgout
+
+ assertions=`expr $assertions + 1`
# compare
- file_diff=`diff $2/out.2 $2/out.3`
- if [ "$file_diff" = "" ] ; then
- echo "Database $3 - encoding $locale_encoding - OK." > $dbgout
- else
- echo "Database $3 - encoding $locale_encoding - FAIL." > $dbgout
+ file_diff=`diff $2/out.2 $2/out.3` >/dev/null
+ if [ $? -ne 0 ] ; then
+ echo "ERROR: $2/out.2 $2/out.3 differ." > $dbgout
+ failedassertions=`expr $failedassertions + 1`
fi
# and remove database
@@ -339,14 +315,11 @@
bindir=""
nlsdir=""
locdir=""
-locale=""
## output stream
out="/dev/null"
dbgout="/dev/null"
-echo_n="echo -n"
-
## Get the options from the command line
while getopts ":sfdb:i:l:O:L:M:C:D:" opt_name; do
case $opt_name in
@@ -361,7 +334,7 @@
M);; ## ignored
C);; ## ignored
D);; ## ignored
- *) echo "Unimplemented option : -$opt_name" >> $out;
+ *) echo "Unimplemented option : -$opt_name" >&2;
exit 1;;
esac;
done
@@ -370,7 +343,6 @@
if [ "$chk_sanity" = "yes" ]; then
## checking locale sanity
- check_locale_location $bindir
check_locale_help
check_locale_all
check_locale_m
@@ -381,22 +353,28 @@
## set the temp dir
[ -z "$TMP" ] && TMP="/tmp";
- [ -d $TMP/locale ] || mkdir $TMP/locale;
+ tmpdir=$TMP/locale.$$
+ mkdir $tmpdir
+ if [ $? -ne 0 ]; then
+ echo "$0: Unable to create $tmpdir, aborting" >&2
+ exit 1
+ fi
## checking locale functionality
RWSTD_SRC_ROOT=$nlsdir
export RWSTD_SRC_ROOT
- RWSTD_LOCALE_ROOT=$TMP/locale
+ RWSTD_LOCALE_ROOT=$tmpdir
export RWSTD_LOCALE_ROOT
# test only one locale
- test_locale $nlsdir $TMP/locale $locale_db;
+ test_locale $nlsdir $tmpdir $locale_db;
+
+ rm -rf $tmpdir
else
## Invocation is wrong
- echo "Wrong invocation." >> $out
- echo "Usage : " >> $out
- echo "script -s -b <bindir> ## checking sanity" >> $out
- echo "script -f -i <nlsdir> -l <locale name> ## check functionality" >>
$out
+ echo "$0: Usage : " >&2
+ echo "script -s -b <bindir> ## checking sanity" >&2
+ echo "script -f -i <nlsdir> -l <locale name> ## check functionality" >&2
exit 2
fi