Clean up installer (remove unneeded checks, better editor & pager detection & path handling); update twtest to count failures instead of exiting on first one.

This commit is contained in:
Brian Cox 2017-03-30 22:22:52 -07:00
parent 9e1b078aac
commit a67d3c3a86
3 changed files with 128 additions and 129 deletions

View File

@ -17,7 +17,7 @@
## from Larry Wall's metaconfig.
##-------------------------------------------------------
PATH='.:/bin:/usr/bin'
PATH=".:/bin:/usr/bin:/usr/local/bin:$PATH"
export PATH || (echo 'You must use sh to run this script'; kill $$)
if [ ! -t 0 ] ; then
echo "Say 'sh install.sh', not 'sh < install.sh'"
@ -66,50 +66,22 @@ for p in $awknames; do
fi
done
##-------------------------------------------------------
## Does this system have a copy of grep we can use?
## Some greps don't return status (amazing, huh?),
## so we look for a copy of grep that
## returns 0 status for an exact match
## returns 0 status for a case-insensitive match
## returns 0 status for a wildcard match
## returns non-zero status for a failed match
##-------------------------------------------------------
GREP=""
grepnames="grep egrep"
lcgrepstr="findensiemich" # all lower case
mcgrepstr="FindenSieMich" # mixed case
wcgrepstr="sie.ich$" # wild card match
nogrepstr="WoBistDu" # should not be able to find this
for p in $grepnames; do
(echo "$lcgrepstr" | $p "$lcgrepstr") 2> /dev/null 1>&2
if [ $? -eq 0 ]; then
(echo "$lcgrepstr" | $p -i "$mcgrepstr") 2> /dev/null 1>&2
if [ $? -eq 0 ]; then
(echo "$lcgrepstr" | $p "$wcgrepstr") 2> /dev/null 1>&2
if [ $? -eq 0 ]; then
(echo "$lcgrepstr" | $p "$nogrepstr") 2> /dev/null 1>&2
if [ $? -ne 0 ]; then
GREP=$p
break
fi
fi
fi
fi
done
##-------------------------------------------------------
## Does this system have a pager that we can use?
## Use cat if desperate.
##-------------------------------------------------------
MORE="cat"
morenames="more less cat"
morenames="less more most pg cat"
for p in $morenames; do
($p $0 < /dev/null) 2> /dev/null 1>&2
if [ $? -eq 0 ]; then
MORE=$p
pagerpath=`command -v $p`
if [ -z $pagerpath ]; then
continue
fi
if [ -x $pagerpath ]; then
MORE=$pagerpath
break
fi
done
@ -405,14 +377,20 @@ else
## Verify that the specified editor program exists
##-------------------------------------------------------
TWEDITOR=${TWEDITOR:-'/bin/vi'}
DEFAULTEDITOR=${EDITOR:-/bin/vi}
TWEDITOR=${TWEDITOR:-$DEFAULTEDITOR}
TWEDITOR_PATH=`command -v $TWEDITOR`
if [ -n ${TWEDITOR_PATH} ]; then
TWEDITOR=$TWEDITOR_PATH
fi
if [ -x ${TWEDITOR} ]; then
echo "${TWEDITOR} exists. Continuing installation."
echo
else
echo "${TWEDITOR} does not exist. Exiting."
exit 1
echo "${TWEDITOR} not found. Continuing, but your configuration may need to be edited after installation."
echo
fi
##-------------------------------------------------------

View File

@ -154,10 +154,14 @@ void Usage()
const int MAX_TEST_ID = 88;
static int failed_count = 0;
static void Test(int testID)
{
TCERR << std::endl << "=== Running test ID #" << testID << " ===" << std::endl;
try {
switch (testID)
{
case 1: TestArchive(); break;
@ -240,6 +244,21 @@ static void Test(int testID)
case 88: TestConfigFile2(); break;
}
}
catch (eError& error)
{
cTWUtil::PrintErrorMsg(error);
failed_count++;
}
catch (std::exception& e) {
TCERR << "FAILED: " << e.what() << std::endl;
failed_count++;
}
catch (...) {
TCERR << "FAILED: <unknown>" << std::endl;
failed_count++;
}
TCERR << std::endl << "=== test ID #" << testID << " completed ===" << std::endl;
}
@ -333,9 +352,9 @@ int _tmain(int argc, TCHAR** argv)
// force user to hit <CR>
std::cout << std::endl << "Tests completed" << std::endl;
std::cout << std::endl << "Tests completed with " << failed_count << " failures." << std::endl;
return 0;
return failed_count ? -1 : 0;
}

View File

@ -49,6 +49,8 @@
#endif
#include <iostream>
#include <stdexcept>
using namespace std;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -69,7 +71,7 @@ TSS_EndPackage( cTest )
#define TEST(exp) if (!(exp)) \
{ \
std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \
exit(-1); \
throw std::runtime_error(#exp); \
}
///////////////////////////////////////////////////////////////////////////////