Skip to content

Commit f3c3f3c

Browse files
abueideclaude
andcommitted
test: add POSIX compatibility tests for init scripts
Add tests that verify sourced scripts (lib.sh, core.sh, device_config.sh, setup.sh) work correctly under dash. Uses shellcheck --shell=sh for static analysis and dash runtime sourcing when available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0b83a7f commit f3c3f3c

2 files changed

Lines changed: 200 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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"
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
# iOS 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 "iOS POSIX Compatibility Tests"
16+
echo "========================================"
17+
18+
# ============================================================================
19+
# Setup
20+
# ============================================================================
21+
22+
scripts_dir="$script_dir/../../ios/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+
if dash -c ". '$scripts_dir/lib/lib.sh'" >/dev/null 2>&1; then
66+
echo " ✓ PASS: lib.sh sources cleanly under dash"
67+
test_passed=$((test_passed + 1))
68+
else
69+
echo " ✗ FAIL: lib.sh failed under dash"
70+
test_failed=$((test_failed + 1))
71+
fi
72+
73+
start_test "platform/core.sh sources under dash without error"
74+
# core.sh sources lib.sh, so set IOS_SCRIPTS_DIR
75+
if dash -c "IOS_SCRIPTS_DIR='$scripts_dir'; export IOS_SCRIPTS_DIR; . '$scripts_dir/platform/core.sh'" >/dev/null 2>&1; then
76+
echo " ✓ PASS: core.sh sources cleanly under dash"
77+
test_passed=$((test_passed + 1))
78+
else
79+
echo " ✗ FAIL: core.sh failed under dash"
80+
test_failed=$((test_failed + 1))
81+
fi
82+
83+
start_test "platform/device_config.sh sources under dash without error"
84+
if dash -c "IOS_SCRIPTS_DIR='$scripts_dir'; export IOS_SCRIPTS_DIR; . '$scripts_dir/platform/device_config.sh'" >/dev/null 2>&1; then
85+
echo " ✓ PASS: device_config.sh sources cleanly under dash"
86+
test_passed=$((test_passed + 1))
87+
else
88+
echo " ✗ FAIL: device_config.sh failed under dash"
89+
test_failed=$((test_failed + 1))
90+
fi
91+
else
92+
echo "SKIP: dash not available (install for runtime POSIX testing)"
93+
fi
94+
95+
# ============================================================================
96+
# Summary
97+
# ============================================================================
98+
99+
test_summary "ios-posix-compat"

0 commit comments

Comments
 (0)