summaryrefslogtreecommitdiffstats
path: root/share/extensions/test/run-all-extension-tests
blob: aa20c8c7b4b4548983cd9974fca40e4e9546e8b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash

# TODO: check for GNU mktemp and sed (from coreutils), else exit
# ---------------------------------------------------------------------
# solution below is based on
# <http://www.ooblick.com/weblog/2011/05/12/a-couple-of-shell-quickies/>

# Wrapper function for GNU mktemp
gnu_mktemp() {
	mktemp "$@"
}

# Wrapper function for BSD mktemp
bsd_mktemp() {
	mktemp -t tmpfile.XXXXXX "$@"
}

# Try to figure out which wrapper to use
if mktemp -V | grep version >/dev/null 2>&1; then
	MKTEMP=gnu_mktemp
else
	MKTEMP=bsd_mktemp
fi

#mytmpfile=`$MKTEMP`
echo "MKTEMP to be used: $MKTEMP"

# ---------------------------------------------------------------------

echo -e "\n##### Extension Tests #####"

cd "$(dirname "$0")"

has_py_coverage=false
py_cover_files=$( $MKTEMP )
failed_tests=$( $MKTEMP )

if coverage.py -e >/dev/null 2>/dev/null; then
  has_py_coverage=true
  cover_py_cmd=coverage.py
else
  if coverage -e >/dev/null 2>/dev/null; then
    has_py_coverage=true
    cover_py_cmd=coverage
  fi
fi

#if $has_py_coverage; then
#  $cover_py_cmd -e
#fi

function run_py_test() {
  echo -e "\n>> Testing $1"
  if $has_py_coverage; then
    if ! $cover_py_cmd -x "$1.test.py"; then
      echo "$1" >> $failed_tests
    fi
    echo "../$1.py" >> $py_cover_files
  else
    if ! python "$1.test.py"; then
      echo "$1" >> $failed_tests
    fi
  fi
  return 0
}

tot_FAILED=0

# TODO: check for GNU mktemp and sed (from coreutils), else exit
# ---------------------------------------------------------------------
# solution below is based on
# <http://notmuchmail.org/pipermail/notmuch/2011/004579.html>

if [ `sed --version >/dev/null 2>/dev/null && echo 1` ]; then
    SED_EXTENDED='sed -r' # GNU sed (e.g. on Linux)
else
    SED_EXTENDED='sed -E' # BSD sed (e.g. on Mac OS X)
fi

echo "sed regex command: $SED_EXTENDED"

# ---------------------------------------------------------------------

for testFile in *.test.py; do
  if ! run_py_test $( echo $testFile | $SED_EXTENDED 's/^([^.]+)..*$/\1/' ); then
    let tot_FAILED++
  fi
done

if $has_py_coverage; then
  echo -e "\n>> Coverage Report:"
  cat $py_cover_files | xargs $cover_py_cmd -r
fi

fail=false
if ! test -z "$( cat $failed_tests )"; then
  echo -e "\nFailed $( cat $failed_tests | wc -l ) of $( ls -1 *.test.py | wc -l ) extension tests:"
  cat $failed_tests | sed 's/^/  - /'
  fail=true
fi
echo ""

rm $py_cover_files $failed_tests

if [ x$fail == xtrue ]; then
	exit 1
else
	exit 0
fi