tweak all-tests:
[nepi.git] / all-tests
1 #!/bin/bash
2 #
3 # helper script to run some predefined set of tests
4 # store results in a file that contains the git hash
5 # and also shows differences if any
6 #
7 # if this command is run as all-tests3, then we will just do
8 # make PYTHON=python3
9 #
10 # xxx - WARNING : most likely the python2 and python3 tests
11 # cannot safely be run together; need to check the nepi exp_ids
12 # used more closely
13
14 COMMAND=$(basename $0)
15
16 PYTHON=python
17 version=2
18 echo $COMMAND | grep -q 3 && { PYTHON=python3; version=3; }
19
20 hash=$(git log -n 1 | head -1 | sed -e 's,commit ,,' -e 's,\(........\).*,\1,')
21
22 # compute output file name
23 output="zz.py$version.$hash"
24
25 # if there is any pending change, use another name
26 is_pristine=""
27 changes=$(git diff HEAD | wc -l); changes=$(echo $changes)
28 [ "$changes" == 0 ] && is_pristine=true
29 [ -n "$is_pristine" ] || output="$output-pending"
30
31 function all_tests () {
32     echo all-tests : begin at; date
33     begin=$(date +%s)
34     echo ========================================
35     echo status
36     echo ========================================
37     echo ===== Current hash $hash
38     echo ===== Current branch
39     git branch
40     echo ===== Uncommitted changes
41     git diff HEAD
42     echo ========================================
43     echo tests
44     echo ========================================
45     make PYTHON=$PYTHON all-tests
46     echo ========================================
47     end=$(date +%s)
48     echo all-tests : end at; date; echo total duration $(($end-$begin)) seconds
49 }
50
51 # WARNING: the current code for analyzing the output is not quite right
52 # I've seen cases where the tests session goes very badly - with broken imports for example
53 # but it's considered OK though
54 # we mght wish to take the opposite angle : check we have as many OK as expected
55 # but then the list of default targets should be declared here and not in Makefile
56 # in any case this is good enough for now
57
58 all_tests >& $output
59 retcod=$?
60
61 # analyze this output for success or not
62 success=$output.success
63 failure=$output.failed
64
65 if [ "$retcod" != 0 ]; then
66     touch $failure
67 elif grep -q '^FAIL' $output; then
68      touch $failure
69 else
70     touch $success
71 fi
72