diff --git a/CLAUDE.md b/CLAUDE.md index e62c3be4..fc68a469 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -178,13 +178,16 @@ Tests are in the `tests/` directory. There are two types: unit tests and manual ./tests/unittest.sh tests/test_start_app.py # Run a specific test on connected device (via mpremote) -./tests/unittest.sh tests/test_shared_preferences.py ondevice +./tests/unittest.sh tests/test_shared_preferences.py --ondevice + +# Run all tests on connected device +./tests/unittest.sh --ondevice ``` The `unittest.sh` script: - Automatically detects the platform (Linux/macOS) and uses the correct binary - Sets up the proper paths and heapsize -- Can run tests on device using `mpremote` with the `ondevice` argument +- Can run tests on device using `mpremote` with the `--ondevice` flag - Runs all `test_*.py` files when no argument is provided - On device, assumes the OS is already running (boot.py and main.py already executed), so tests run against the live system - Test infrastructure (graphical_test_helper.py) is automatically installed by `scripts/install.sh` @@ -202,7 +205,7 @@ The `unittest.sh` script: ./tests/unittest.sh tests/test_graphical_about_app.py # Run graphical tests on device -./tests/unittest.sh tests/test_graphical_about_app.py ondevice +./tests/unittest.sh tests/test_graphical_about_app.py --ondevice # Convert screenshots from raw RGB565 to PNG cd tests/screenshots diff --git a/tests/test_graphical_about_app.py b/tests/test_graphical_about_app.py index c81f69f7..409c2024 100644 --- a/tests/test_graphical_about_app.py +++ b/tests/test_graphical_about_app.py @@ -12,7 +12,7 @@ This is a proof of concept for graphical testing that: Usage: Desktop: ./tests/unittest.sh tests/test_graphical_about_app.py - Device: ./tests/unittest.sh tests/test_graphical_about_app.py ondevice + Device: ./tests/unittest.sh tests/test_graphical_about_app.py --ondevice """ import unittest diff --git a/tests/test_graphical_animation_deleted_widget.py b/tests/test_graphical_animation_deleted_widget.py index 70e5dd00..b64ca236 100644 --- a/tests/test_graphical_animation_deleted_widget.py +++ b/tests/test_graphical_animation_deleted_widget.py @@ -12,7 +12,7 @@ trying to access it. Usage: Desktop: ./tests/unittest.sh tests/test_graphical_animation_deleted_widget.py - Device: ./tests/unittest.sh tests/test_graphical_animation_deleted_widget.py ondevice + Device: ./tests/unittest.sh tests/test_graphical_animation_deleted_widget.py --ondevice """ import unittest diff --git a/tests/test_graphical_custom_keyboard.py b/tests/test_graphical_custom_keyboard.py index 5d94af30..77ae61a0 100644 --- a/tests/test_graphical_custom_keyboard.py +++ b/tests/test_graphical_custom_keyboard.py @@ -6,7 +6,7 @@ and mode switching. Captures screenshots for regression testing. Usage: Desktop: ./tests/unittest.sh tests/test_graphical_custom_keyboard.py - Device: ./tests/unittest.sh tests/test_graphical_custom_keyboard.py ondevice + Device: ./tests/unittest.sh tests/test_graphical_custom_keyboard.py --ondevice """ import unittest diff --git a/tests/test_graphical_custom_keyboard_basic.py b/tests/test_graphical_custom_keyboard_basic.py index d4cbdcd8..34bf42c3 100644 --- a/tests/test_graphical_custom_keyboard_basic.py +++ b/tests/test_graphical_custom_keyboard_basic.py @@ -5,7 +5,7 @@ Tests keyboard creation, mode switching, text input, and API compatibility. Usage: Desktop: ./tests/unittest.sh tests/test_custom_keyboard.py - Device: ./tests/unittest.sh tests/test_custom_keyboard.py ondevice + Device: ./tests/unittest.sh tests/test_custom_keyboard.py --ondevice """ import unittest diff --git a/tests/test_graphical_keyboard_animation.py b/tests/test_graphical_keyboard_animation.py index 050f2f33..0c171ee9 100644 --- a/tests/test_graphical_keyboard_animation.py +++ b/tests/test_graphical_keyboard_animation.py @@ -6,7 +6,7 @@ required by mpos.ui.anim.smooth_show() and smooth_hide(). Usage: Desktop: ./tests/unittest.sh tests/test_graphical_keyboard_animation.py - Device: ./tests/unittest.sh tests/test_graphical_keyboard_animation.py ondevice + Device: ./tests/unittest.sh tests/test_graphical_keyboard_animation.py --ondevice """ import unittest diff --git a/tests/test_graphical_keyboard_styling.py b/tests/test_graphical_keyboard_styling.py index 695d0c6c..8bde4ab2 100644 --- a/tests/test_graphical_keyboard_styling.py +++ b/tests/test_graphical_keyboard_styling.py @@ -13,7 +13,7 @@ This test should INITIALLY FAIL, demonstrating the bug before the fix is applied Usage: Desktop: ./tests/unittest.sh tests/test_graphical_keyboard_styling.py - Device: ./tests/unittest.sh tests/test_graphical_keyboard_styling.py ondevice + Device: ./tests/unittest.sh tests/test_graphical_keyboard_styling.py --ondevice """ import unittest diff --git a/tests/unittest.sh b/tests/unittest.sh index 90f6ef7e..f382ae64 100755 --- a/tests/unittest.sh +++ b/tests/unittest.sh @@ -5,8 +5,18 @@ mydir=$(dirname "$mydir") testdir="$mydir" scriptdir=$(readlink -f "$mydir"/../scripts/) fs="$mydir"/../internal_filesystem/ -onetest="$1" -ondevice="$2" + +# Parse arguments +ondevice="" +onetest="" + +for arg in "$@"; do + if [ "$arg" = "--ondevice" ]; then + ondevice="yes" + else + onetest="$arg" + fi +done # print os and set binary @@ -95,19 +105,21 @@ else: failed=0 if [ -z "$onetest" ]; then - echo "Usage: $0 [one_test_to_run.py] [ondevice]" + echo "Usage: $0 [one_test_to_run.py] [--ondevice]" echo "Example: $0 tests/simple.py" - echo "Example: $0 tests/simple.py ondevice" + echo "Example: $0 tests/simple.py --ondevice" + echo "Example: $0 --ondevice" echo 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." + echo "The '--ondevice' flag will run the test(s) on a connected device using mpremote.py (should be on the PATH) over a serial connection." while read file; do one_test "$file" result=$? if [ $result -ne 0 ]; then echo "\n\n\nWARNING: test $file got error $result !!!\n\n\n" failed=$(expr $failed \+ 1) + exit 1 fi done < <( find "$testdir" -iname "test_*.py" ) else