| #!/bin/bash |
| # |
| # Convenience script to clean, build, install and run unit and/or integration tests. |
| # Recommend you run this prior to pushing to Github to reduce the chances of breaking |
| # the continuous integration (unit tests) or overnight builds (integration tests.) |
| # |
| # Also very useful when using "git bisect" to find out which commit was responsible |
| # for breaking the overnight build - invoke as "git bisect run ./buildAndRun" |
| # |
| # Run "./buildAndRun --help" to see the usage. |
| # |
| |
| # Has an integration test left a Java process running? See if there is any running |
| # Java processes and offer to kill them/ |
| cleanup(){ |
| PROCS=$(ps ax | grep '[j]ava' | grep -v set_tab_title) |
| if [ ! -z "${PROCS}" ]; then |
| echo "These Java processes are running:" |
| echo ${PROCS} |
| echo -n "Kill them? y=yes, n=no, x=abort: " |
| read $RESPONSE |
| [ "${RESPONSE}" = "y" ] && killall java && sleep 1s |
| [ "${RESPONSE}" = "x" ] && exit 50 |
| fi |
| } |
| |
| # Check a return value, and bail if its non-zero - invoke as "assert $? 'Unit tests'" |
| assert(){ |
| [ $1 -eq 0 ] && return |
| echo '*** Command returned '$1' on '$2 |
| exit $1 |
| } |
| |
| # The defaults |
| unit=1 |
| integration=1 |
| |
| if [ ! -z "$1" ]; then |
| case "$1" in |
| u) |
| unit=1 |
| integration=0 |
| ;; |
| i) |
| unit=0 |
| integration=1 |
| ;; |
| ui) |
| unit=1 |
| integration=1 |
| ;; |
| b) |
| unit=0 |
| integration=0 |
| ;; |
| *) |
| echo >&2 Usage: buildAndTest [action] |
| echo >&2 where action is: |
| echo >&2 u - build from clean and run unit tests |
| echo >&2 i - build from clean and run integration tests |
| echo >&2 ui - build from clean and run unit and integration tests \(default\) |
| echo >&2 b - build from clean and do not run any tests |
| exit 1 |
| ;; |
| esac |
| fi |
| |
| echo '*** BUILD' |
| mvn clean install -DskipTests -PConsole |
| assert $? 'BUILD' |
| cleanup |
| if [ $unit -eq 1 ]; then |
| echo '*** UNIT TEST' |
| mvn integration-test -PConsole |
| assert $? 'UNIT TEST' |
| cleanup |
| fi |
| if [ $integration -eq 1 ]; then |
| echo '*** INTEGRATION TEST' |
| mvn integration-test -PConsole,Integration |
| assert $? 'INTEGRATION TEST' |
| cleanup |
| fi |
| |
| exit 0 |