1#!/bin/sh
2#
3# This is plain shell variant of run-tests script, which uses .exp files
4# as generated by run-tests --write-exp. It is useful to run testsuite
5# on embedded systems which don't have CPython3.
6#
7
8RM="rm -f"
9MP_PY=micropython
10
11numtests=0
12numtestcases=0
13numpassed=0
14numskipped=0
15numfailed=0
16nameskipped=
17namefailed=
18
19if [ $# -eq 0 ]
20then
21    tests="basics/*.py micropython/*.py float/*.py import/*.py io/*.py misc/*.py unicode/*.py extmod/*.py unix/*.py"
22else
23    tests="$@"
24fi
25
26for infile in $tests
27do
28    basename=`basename $infile .py`
29    outfile=${basename}.py.out
30    expfile=$infile.exp
31
32    $MP_PY $infile > $outfile
33    numtestcases=$(expr $numtestcases + $(cat $expfile | wc -l))
34
35    if grep -q "SKIP\|SyntaxError: invalid micropython decorator" $outfile
36    then
37        # we don't count tests that explicitly ask to be skipped
38        # we don't count tests that fail due to unsupported decorator
39        echo "skip  $infile"
40        $RM $outfile
41        numskipped=$(expr $numskipped + 1)
42        nameskipped="$nameskipped $basename"
43    else
44        diff --brief $expfile $outfile > /dev/null
45
46        if [ $? -eq 0 ]
47        then
48            echo "pass  $infile"
49            $RM $outfile
50            numpassed=$(expr $numpassed + 1)
51        else
52            echo "FAIL  $infile"
53            numfailed=$(expr $numfailed + 1)
54            namefailed="$namefailed $basename"
55        fi
56    fi
57
58    numtests=$(expr $numtests + 1)
59done
60
61echo "$numtests tests performed ($numtestcases individual testcases)"
62echo "$numpassed tests passed"
63if [ $numskipped != 0 ]
64then
65    echo "$numskipped tests skipped -$nameskipped"
66fi
67if [ $numfailed != 0 ]
68then
69    echo "$numfailed tests failed -$namefailed"
70    exit 1
71else
72    exit 0
73fi
74