|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +mydir=$(readlink -f "$0") |
| 4 | +mydir=$(dirname "$mydir") |
| 5 | +testdir="$mydir" |
| 6 | +scriptdir=$(readlink -f "$mydir"/../scripts/) |
| 7 | +fs="$mydir"/../internal_filesystem/ |
| 8 | +onetest="$1" |
| 9 | + |
| 10 | + |
| 11 | +# print os and set binary |
| 12 | +os_name=$(uname -s) |
| 13 | +if [ "$os_name" = "Darwin" ]; then |
| 14 | + echo "Running on macOS" |
| 15 | + binary="$scriptdir"/../lvgl_micropython/build/lvgl_micropy_macOS |
| 16 | +else |
| 17 | + # other cases can be added here |
| 18 | + echo "Running on $os_name" |
| 19 | + binary="$scriptdir"/../lvgl_micropython/build/lvgl_micropy_unix |
| 20 | +fi |
| 21 | + |
| 22 | +one_test() { |
| 23 | + file="$1" |
| 24 | + pushd "$fs" |
| 25 | + echo "Testing $file" |
| 26 | + "$binary" -X heapsize=8M -c "import sys ; sys.path.append('lib') |
| 27 | +$(cat $file) |
| 28 | +result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) " |
| 29 | + result=$? |
| 30 | + popd |
| 31 | + return "$result" |
| 32 | +} |
| 33 | + |
| 34 | +failed=0 |
| 35 | + |
| 36 | +if [ -z "$onetest" ]; then |
| 37 | + echo "Usage: $0 [one_test_to_run.py]" |
| 38 | + echo "Example: $0 tests/simple.py" |
| 39 | + echo |
| 40 | + echo "If no test is specified: run all tests from $testdir" |
| 41 | + while read file; do |
| 42 | + one_test "$file" |
| 43 | + result=$? |
| 44 | + if [ $result -ne 0 ]; then |
| 45 | + echo "test $file got error $result" |
| 46 | + failed=$(expr $failed \+ 1) |
| 47 | + fi |
| 48 | + |
| 49 | + done < <( find "$testdir" -iname "*.py" ) |
| 50 | +else |
| 51 | + one_test $(readlink -f "$onetest") |
| 52 | + [ $? -ne 0 ] && failed=1 |
| 53 | +fi |
| 54 | + |
| 55 | + |
| 56 | +if [ $failed -ne 0 ]; then |
| 57 | + echo "ERROR: $failed .py files have failing unit tests" |
| 58 | + exit 1 |
| 59 | +else |
| 60 | + echo "GOOD: no .py files have failing unit tests" |
| 61 | + exit 0 |
| 62 | +fi |
| 63 | + |
0 commit comments