1#!/bin/bash
2set -e
3
4############################################################
5#
6# This script prints statistics about the tests (whether they did not run,
7# they failed, or they were passed) to stdout
8#
9# Usage:
10#   script/print_test_statistics.sh
11#
12# Return value:
13#   0     upon success
14#   >0 represents the number of failed tests
15#
16#-----------------------------------------------------------
17
18#-----------------------------------------------------------
19# Prints a visible separator to stdout
20#-----------------------------------------------------------
21separator () {
22    cat <<EOF
23
24========================================================
25
26EOF
27}
28
29
30TESTS=0
31SUCCEEDED_TESTS=0
32
33separator #-------------------------------------------------
34
35PREVIOUS_NAME_START=""
36
37# Print the information for each test separately
38for FILE in $( ls -1 *.test-spec | sort )
39do
40    NAME_STUB=${FILE%.test-spec}
41    NAME_START=${NAME_STUB:0:1}
42    STATUS_FILE="$NAME_STUB".status
43    if [ -e "$STATUS_FILE" ]
44    then
45	RESULT=$(cat "$NAME_STUB".status)
46    else
47	RESULT="did not run"
48    fi
49
50    if [ "$PREVIOUS_NAME_START" != "$NAME_START" ] #-a ! -z "$PREVIOUS_NAME_START" ]
51    then
52	echo "--------$NAME_START*----------------------------------------------"
53    fi
54
55    echo "$RESULT: ${FILE%.test-spec}"
56
57    TESTS=$((TESTS+1))
58
59    if [ "passed" = "$RESULT" ]
60    then
61	SUCCEEDED_TESTS=$((SUCCEEDED_TESTS+1))
62    fi
63    PREVIOUS_NAME_START="${NAME_START}"
64done
65
66separator #-------------------------------------------------
67
68# Print the accumulated statistics
69cat <<EOF
70  Total # of tests           : $TESTS
71  Total # of succeeded tests : $SUCCEEDED_TESTS
72  Total # of failed tests    : $((TESTS-SUCCEEDED_TESTS))
73EOF
74
75separator #-------------------------------------------------
76
77#return the number of failed tests
78exit $((TESTS-SUCCEEDED_TESTS))
79