diff --git a/tests/unittest.sh b/tests/unittest.sh index f27d096d..87aa1d37 100755 --- a/tests/unittest.sh +++ b/tests/unittest.sh @@ -6,6 +6,7 @@ testdir="$mydir" scriptdir=$(readlink -f "$mydir"/../scripts/) fs="$mydir"/../internal_filesystem/ onetest="$1" +ondevice="$2" # print os and set binary @@ -26,10 +27,25 @@ one_test() { file="$1" pushd "$fs" echo "Testing $file" - "$binary" -X heapsize=8M -c "import sys ; sys.path.append('lib') + if [ -z "$ondevice" ]; then + "$binary" -X heapsize=8M -c "import sys ; sys.path.append('lib') $(cat $file) result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) " - result=$? + result=$? + else + cleanname=$(echo "$file" | sed "s#/#_#g") + testlog=/tmp/"$cleanname".log + mpremote.py exec "import sys ; sys.path.append('lib') +$(cat $file) +result = unittest.main() +if result.wasSuccessful(): + print('TEST WAS A SUCCESS') +else: + print('TEST WAS A FAILURE') +" > "$testlog" + grep "TEST WAS A SUCCESS" "$testlog" + result=$? + fi popd return "$result" } @@ -37,10 +53,13 @@ result = unittest.main() ; sys.exit(0 if result.wasSuccessful() else 1) " failed=0 if [ -z "$onetest" ]; then - echo "Usage: $0 [one_test_to_run.py]" + echo "Usage: $0 [one_test_to_run.py] [ondevice]" echo "Example: $0 tests/simple.py" + echo "Example: $0 tests/simple.py ondevice" echo - echo "If no test is specified: run all tests from $testdir" + echo "If no test is specified: run all tests from $testdir on local machine." + echo + echo "The 'ondevice' argument will try to run the test on a connected device using mpremote.py (should be on the PATH) over a serial connection." while read file; do one_test "$file" result=$?