summaryrefslogtreecommitdiffstats
path: root/share/extensions/test/run-all-extension-tests
blob: ff739c31187601183478540b77579455ef1fbde1 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/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 erase >/dev/null 2>/dev/null; then
  has_py_coverage=true
  cover_py_cmd=coverage.py
  else
    if coverage erase >/dev/null 2>/dev/null; then
      has_py_coverage=true
      cover_py_cmd=coverage
      else
        if python-coverage erase >/dev/null 2>/dev/null; then
          has_py_coverage=true
          cover_py_cmd=python-coverage
          else
            if coverage-script.py erase >/dev/null 2>/dev/null; then
            has_py_coverage=true
            cover_py_cmd=coverage-script.py
            fi
        fi
    fi
fi

if $has_py_coverage; then
    echo -e "\nRunning tests with coverage (${cover_py_cmd})"
fi
#if $has_py_coverage; then
#  $cover_py_cmd -e
#fi

function run_py_test() {
  echo -e "\n>>>>>> Testing $1 <<<<<<\n"
  if $has_py_coverage; then
    if ! $cover_py_cmd run -a "$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 -e "sed regex command: $SED_EXTENDED\n"

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

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 report
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