run-all-extension-tests revision d4d3743f0388af16b07b640a8b145eee32f36f73
4e10d188042815c5285edf00ea96896b862e0863aurium#!/bin/bash
4e10d188042815c5285edf00ea96896b862e0863aurium
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# TODO: check for GNU mktemp and sed (from coreutils), else exit
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# ---------------------------------------------------------------------
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# solution below is based on
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# <http://www.ooblick.com/weblog/2011/05/12/a-couple-of-shell-quickies/>
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# Wrapper function for GNU mktemp
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisgnu_mktemp() {
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis mktemp "$@"
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis}
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# Wrapper function for BSD mktemp
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisbsd_mktemp() {
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis mktemp -t tmpfile.XXXXXX "$@"
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis}
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# Try to figure out which wrapper to use
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisif mktemp -V | grep version >/dev/null 2>&1; then
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis MKTEMP=gnu_mktemp
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavaniselse
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis MKTEMP=bsd_mktemp
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisfi
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis#mytmpfile=`$MKTEMP`
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisecho "MKTEMP to be used: $MKTEMP"
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# ---------------------------------------------------------------------
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
2ebfcf72203f94f579931a9cfe6658a65ca5027dauriumecho -e "\n##### Extension Tests #####"
4e10d188042815c5285edf00ea96896b862e0863aurium
4e10d188042815c5285edf00ea96896b862e0863auriumcd "$(dirname "$0")"
4e10d188042815c5285edf00ea96896b862e0863aurium
4e10d188042815c5285edf00ea96896b862e0863auriumhas_py_coverage=false
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanispy_cover_files=$( $MKTEMP )
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisfailed_tests=$( $MKTEMP )
4e10d188042815c5285edf00ea96896b862e0863aurium
4e10d188042815c5285edf00ea96896b862e0863auriumif coverage.py -e >/dev/null 2>/dev/null; then
4e10d188042815c5285edf00ea96896b862e0863aurium has_py_coverage=true
4e10d188042815c5285edf00ea96896b862e0863aurium cover_py_cmd=coverage.py
4e10d188042815c5285edf00ea96896b862e0863auriumelse
4e10d188042815c5285edf00ea96896b862e0863aurium if coverage -e >/dev/null 2>/dev/null; then
4e10d188042815c5285edf00ea96896b862e0863aurium has_py_coverage=true
4e10d188042815c5285edf00ea96896b862e0863aurium cover_py_cmd=coverage
4e10d188042815c5285edf00ea96896b862e0863aurium fi
4e10d188042815c5285edf00ea96896b862e0863auriumfi
4e10d188042815c5285edf00ea96896b862e0863aurium
4e10d188042815c5285edf00ea96896b862e0863aurium#if $has_py_coverage; then
4e10d188042815c5285edf00ea96896b862e0863aurium# $cover_py_cmd -e
4e10d188042815c5285edf00ea96896b862e0863aurium#fi
4e10d188042815c5285edf00ea96896b862e0863aurium
4e10d188042815c5285edf00ea96896b862e0863auriumfunction run_py_test() {
4e10d188042815c5285edf00ea96896b862e0863aurium echo -e "\n>> Testing $1"
4e10d188042815c5285edf00ea96896b862e0863aurium if $has_py_coverage; then
83aaf46c9feab529aeb9add871c05c3d1177afccaurium if ! $cover_py_cmd -x "$1.test.py"; then
83aaf46c9feab529aeb9add871c05c3d1177afccaurium echo "$1" >> $failed_tests
83aaf46c9feab529aeb9add871c05c3d1177afccaurium fi
4e10d188042815c5285edf00ea96896b862e0863aurium echo "../$1.py" >> $py_cover_files
4e10d188042815c5285edf00ea96896b862e0863aurium else
83aaf46c9feab529aeb9add871c05c3d1177afccaurium if ! python "$1.test.py"; then
83aaf46c9feab529aeb9add871c05c3d1177afccaurium echo "$1" >> $failed_tests
83aaf46c9feab529aeb9add871c05c3d1177afccaurium fi
4e10d188042815c5285edf00ea96896b862e0863aurium fi
83aaf46c9feab529aeb9add871c05c3d1177afccaurium return 0
4e10d188042815c5285edf00ea96896b862e0863aurium}
4e10d188042815c5285edf00ea96896b862e0863aurium
83aaf46c9feab529aeb9add871c05c3d1177afccauriumtot_FAILED=0
83aaf46c9feab529aeb9add871c05c3d1177afccaurium
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# TODO: check for GNU mktemp and sed (from coreutils), else exit
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# ---------------------------------------------------------------------
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# solution below is based on
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# <http://notmuchmail.org/pipermail/notmuch/2011/004579.html>
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisif [ `sed --version >/dev/null 2>/dev/null && echo 1` ]; then
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis SED_EXTENDED='sed -r' # GNU sed (e.g. on Linux)
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavaniselse
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis SED_EXTENDED='sed -E' # BSD sed (e.g. on Mac OS X)
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisfi
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanisecho "sed regex command: $SED_EXTENDED"
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis# ---------------------------------------------------------------------
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis
83aaf46c9feab529aeb9add871c05c3d1177afccauriumfor testFile in *.test.py; do
d4d3743f0388af16b07b640a8b145eee32f36f73Alex Valavanis if ! run_py_test $( echo $testFile | $SED_EXTENDED 's/^([^.]+)..*$/\1/' ); then
83aaf46c9feab529aeb9add871c05c3d1177afccaurium let tot_FAILED++
83aaf46c9feab529aeb9add871c05c3d1177afccaurium fi
905e42f96548e175ead68243a632f06b19285e1fauriumdone
4e10d188042815c5285edf00ea96896b862e0863aurium
4e10d188042815c5285edf00ea96896b862e0863auriumif $has_py_coverage; then
83aaf46c9feab529aeb9add871c05c3d1177afccaurium echo -e "\n>> Coverage Report:"
4e10d188042815c5285edf00ea96896b862e0863aurium cat $py_cover_files | xargs $cover_py_cmd -r
4e10d188042815c5285edf00ea96896b862e0863auriumfi
4e10d188042815c5285edf00ea96896b862e0863aurium
83aaf46c9feab529aeb9add871c05c3d1177afccauriumfail=false
83aaf46c9feab529aeb9add871c05c3d1177afccauriumif ! test -z "$( cat $failed_tests )"; then
4b20bf95123c697a0635b14433d183b02d8b8781aurium echo -e "\nFailed $( cat $failed_tests | wc -l ) of $( ls -1 *.test.py | wc -l ) extension tests:"
83aaf46c9feab529aeb9add871c05c3d1177afccaurium cat $failed_tests | sed 's/^/ - /'
83aaf46c9feab529aeb9add871c05c3d1177afccaurium fail=true
83aaf46c9feab529aeb9add871c05c3d1177afccauriumfi
83aaf46c9feab529aeb9add871c05c3d1177afccauriumecho ""
83aaf46c9feab529aeb9add871c05c3d1177afccaurium
83aaf46c9feab529aeb9add871c05c3d1177afccauriumrm $py_cover_files $failed_tests
83aaf46c9feab529aeb9add871c05c3d1177afccaurium
05c0670a5ec29b57709b1a0bd01010d120a76d8dAlex Valavanisif [ x$fail == xtrue ]; then
05c0670a5ec29b57709b1a0bd01010d120a76d8dAlex Valavanis exit 1
05c0670a5ec29b57709b1a0bd01010d120a76d8dAlex Valavaniselse
05c0670a5ec29b57709b1a0bd01010d120a76d8dAlex Valavanis exit 0
05c0670a5ec29b57709b1a0bd01010d120a76d8dAlex Valavanisfi