|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Android Plugin - POSIX Compatibility Tests |
| 3 | +# |
| 4 | +# Verifies that init scripts (sourced during devbox shell startup) work |
| 5 | +# correctly under dash, which is the default /bin/sh on Linux. |
| 6 | +# These scripts use #!/usr/bin/env sh and must avoid bash-isms. |
| 7 | + |
| 8 | +set -euo pipefail |
| 9 | + |
| 10 | +script_dir="$(cd "$(dirname "$0")" && pwd)" |
| 11 | +. "$script_dir/../test-framework.sh" |
| 12 | +setup_logging |
| 13 | + |
| 14 | +echo "========================================" |
| 15 | +echo "Android POSIX Compatibility Tests" |
| 16 | +echo "========================================" |
| 17 | + |
| 18 | +# ============================================================================ |
| 19 | +# Setup |
| 20 | +# ============================================================================ |
| 21 | + |
| 22 | +scripts_dir="$script_dir/../../android/virtenv/scripts" |
| 23 | + |
| 24 | +# Scripts that are sourced (must be POSIX-compatible) |
| 25 | +sourced_scripts=( |
| 26 | + "$scripts_dir/lib/lib.sh" |
| 27 | + "$scripts_dir/platform/core.sh" |
| 28 | + "$scripts_dir/platform/device_config.sh" |
| 29 | + "$scripts_dir/init/setup.sh" |
| 30 | +) |
| 31 | + |
| 32 | +# ============================================================================ |
| 33 | +# Tests: ShellCheck POSIX Validation |
| 34 | +# ============================================================================ |
| 35 | + |
| 36 | +if command -v shellcheck >/dev/null 2>&1; then |
| 37 | + for script in "${sourced_scripts[@]}"; do |
| 38 | + script_name="$(basename "$script")" |
| 39 | + start_test "shellcheck --shell=sh $script_name" |
| 40 | + if [ ! -f "$script" ]; then |
| 41 | + echo " ✗ FAIL: Script not found: $script" |
| 42 | + test_failed=$((test_failed + 1)) |
| 43 | + continue |
| 44 | + fi |
| 45 | + output="$(shellcheck --shell=sh --severity=error "$script" 2>&1 || true)" |
| 46 | + if [ -z "$output" ]; then |
| 47 | + echo " ✓ PASS: No POSIX errors" |
| 48 | + test_passed=$((test_passed + 1)) |
| 49 | + else |
| 50 | + echo " ✗ FAIL: ShellCheck found POSIX issues" |
| 51 | + echo "$output" | head -20 |
| 52 | + test_failed=$((test_failed + 1)) |
| 53 | + fi |
| 54 | + done |
| 55 | +else |
| 56 | + echo "SKIP: shellcheck not available (install for POSIX validation)" |
| 57 | +fi |
| 58 | + |
| 59 | +# ============================================================================ |
| 60 | +# Tests: Dash Compatibility (if dash is available) |
| 61 | +# ============================================================================ |
| 62 | + |
| 63 | +if command -v dash >/dev/null 2>&1; then |
| 64 | + start_test "lib.sh sources under dash without error" |
| 65 | + output="$(dash -c ". '$scripts_dir/lib/lib.sh'" 2>&1 || true)" |
| 66 | + if dash -c ". '$scripts_dir/lib/lib.sh'" >/dev/null 2>&1; then |
| 67 | + echo " ✓ PASS: lib.sh sources cleanly under dash" |
| 68 | + test_passed=$((test_passed + 1)) |
| 69 | + else |
| 70 | + echo " ✗ FAIL: lib.sh failed under dash" |
| 71 | + echo " Output: $output" |
| 72 | + test_failed=$((test_failed + 1)) |
| 73 | + fi |
| 74 | + |
| 75 | + start_test "platform/core.sh sources under dash without error" |
| 76 | + # core.sh sources lib.sh, so set ANDROID_SCRIPTS_DIR |
| 77 | + if dash -c "ANDROID_SCRIPTS_DIR='$scripts_dir'; export ANDROID_SCRIPTS_DIR; . '$scripts_dir/platform/core.sh'" >/dev/null 2>&1; then |
| 78 | + echo " ✓ PASS: core.sh sources cleanly under dash" |
| 79 | + test_passed=$((test_passed + 1)) |
| 80 | + else |
| 81 | + echo " ✗ FAIL: core.sh failed under dash" |
| 82 | + test_failed=$((test_failed + 1)) |
| 83 | + fi |
| 84 | + |
| 85 | + start_test "platform/device_config.sh sources under dash without error" |
| 86 | + if dash -c "ANDROID_SCRIPTS_DIR='$scripts_dir'; export ANDROID_SCRIPTS_DIR; . '$scripts_dir/platform/device_config.sh'" >/dev/null 2>&1; then |
| 87 | + echo " ✓ PASS: device_config.sh sources cleanly under dash" |
| 88 | + test_passed=$((test_passed + 1)) |
| 89 | + else |
| 90 | + echo " ✗ FAIL: device_config.sh failed under dash" |
| 91 | + test_failed=$((test_failed + 1)) |
| 92 | + fi |
| 93 | +else |
| 94 | + echo "SKIP: dash not available (install for runtime POSIX testing)" |
| 95 | +fi |
| 96 | + |
| 97 | +# ============================================================================ |
| 98 | +# Summary |
| 99 | +# ============================================================================ |
| 100 | + |
| 101 | +test_summary "android-posix-compat" |
0 commit comments