Skip to content

Instantly share code, notes, and snippets.

@mscalora
Last active May 18, 2016 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mscalora/2fca909c88351d4920a68fd44b7dd01f to your computer and use it in GitHub Desktop.
Save mscalora/2fca909c88351d4920a68fd44b7dd01f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# script for testing nano build configurations
grep 'GNU nano - an enhanced clone of the Pico text editor' README >/dev/null 2>&1
if [ $? -ne 0 ] ; then
printf "\n\e[31mError: Must be run from the nano dev folder! \e[39m\n"
exit 1
fi
PASSED=0
FAILED=0
declare -a extra_options=("")
if [ "$1" == "--deep" ] ; then
shift
extra_options=("" "--enable-debug" "--disable-utf8" "--enable-debug --disable-utf8")
printf "===== Running Deep Tests =====\n"
fi
test_passed () {
printf "Test \e[42m\e[30m PASSED \e[49m\e[39m\n"
PASSED=$(( PASSED + 1 ))
}
test_failed () {
printf "Test \e[41m\e[30m FAILED \e[49m\n\e[39m"
FAILED=$(( FAILED + 1 ))
}
test_configure_and_make() {
# $1 expected status of configure
# $2 expected status of make
# $3-* configure params
passed=1
if [ $# -lt 2 ] ; then
printf "\e[41mAt least 2 arguments required\e[49m"
passed=0
else
echo "===== Testing $* ====="
config_status=$1
shift
make_status=$1
shift
[ -f src/nano ] && rm src/nano
./configure $* >/tmp/configure.out 2>/tmp/configure.err
rc=$?
if (( $rc != $config_status )) ; then
printf "\e[31m### configure failed ###\e[39m\nrc=$rc\n...\n"
tail -n 5 /tmp/configure.out
printf "\e[31m"
cat /tmp/configure.err
printf "\e[39m"
passed=0
else
printf "configure \e[32mrc=%d\e[39m as expected\n" $rc
cat /tmp/configure.err
if (( $rc == 0 )) ; then
make clean install >/tmp/make.out 2>/tmp/make.err
if (( $? != $make_status )) ; then
printf "\e[31m### make failed ###\e[39m\n\n...\n"
#tail -n 5 /tmp/make.out
printf "\e[31m"
cat /tmp/make.err
printf "\e[39m"
passed=0
else
printf "make \e[32mrc=%d\e[39m as expected\n" $rc
cat /tmp/make.err
fi
fi
fi
fi
(( $passed )) && test_passed || test_failed
}
if [ $# -eq 0 ] ; then
for extra in "${extra_options[@]}" ; do
test_configure_and_make 0 0 $extra
test_configure_and_make 0 0 --enable-tiny $extra
test_configure_and_make 1 0 --enable-tiny --enable-color $extra
test_configure_and_make 1 0 --enable-tiny --enable-comment $extra
test_configure_and_make 1 0 --enable-tiny --enable-comment --enable-color $extra
test_configure_and_make 1 0 --enable-tiny --enable-comment --enable-nanorc $extra
test_configure_and_make 1 0 --enable-tiny --enable-comment --enable-nanorc --enable-color $extra
test_configure_and_make 0 0 --enable-tiny --enable-nanorc --enable-color $extra
test_configure_and_make 0 0 --enable-tiny --disable-comment --enable-nanorc --enable-color $extra
test_configure_and_make 0 0 --enable-tiny --disable-comment --enable-nanorc --disable-color $extra
test_configure_and_make 0 0 --enable-tiny --enable-nanorc --disable-color $extra
test_configure_and_make 0 0 --enable-tiny --enable-nanorc $extra
test_configure_and_make 0 0 --disable-nanorc $extra
test_configure_and_make 0 0 --disable-nanorc --disable-color $extra
test_configure_and_make 0 0 --disable-nanorc --disable-color --disable-comment $extra
test_configure_and_make 1 0 --disable-nanorc --enable-color $extra
test_configure_and_make 1 0 --disable-nanorc --enable-comment $extra
test_configure_and_make 1 0 --disable-color --enable-comment $extra
done
# always end with normal dev mode build
test_configure_and_make 0 0 --enable-debug
printf "==============================================\n"
if [ $FAILED -eq 0 ] ; then
printf "All $PASSED tests \e[42m\e[30m PASSED \e[49m\e[39m\n"
printf "\e[32m100%% success\e[39m"
else
printf "\e[32m$PASSED tests \e[42m\e[30m PASSED \e[49m\n\e[39m"
printf "\e[31m$FAILED tests \e[41m\e[30m FAILED \e[49m\n\e[39m"
printf "\e[31m%2.2f%% failure\e[39m" $(bc <<< "scale=4; $FAILED/($PASSED+$FAILED)*100")
fi
elif [ $# -eq 1 ] ; then
if [ "$1" != "-h" ] && [ "$1" != "--help" ] && [ "$1" != "-?" ] ; then
printf "\n\e[31mError: At least two arguments are required! \e[39m\n"
fi
printf "\n Usage:\n $(basename $0) [options] <expected-configure-status> <expected-make-status> [<configure-arguments> ...]\n\n"
printf " --deep\trun all tests with combinations of --enable-debug and -disable-utf8 on and off\n\n"
else
test_configure_and_make $*
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment