test-compatibility.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/usr/bin/env bash
  2. #############################################################################
  3. # Compatibility Test Script
  4. # Tests the installer across different bash versions and platforms
  5. #############################################################################
  6. set -e
  7. echo "╔════════════════════════════════════════════════════════════════╗"
  8. echo "║ OpenCode Installer Compatibility Test ║"
  9. echo "╚════════════════════════════════════════════════════════════════╝"
  10. echo ""
  11. # Colors
  12. GREEN='\033[0;32m'
  13. RED='\033[0;31m'
  14. YELLOW='\033[1;33m'
  15. NC='\033[0m'
  16. pass() {
  17. echo -e "${GREEN}✓${NC} $1"
  18. }
  19. fail() {
  20. echo -e "${RED}✗${NC} $1"
  21. exit 1
  22. }
  23. warn() {
  24. echo -e "${YELLOW}⚠${NC} $1"
  25. }
  26. echo "System Information:"
  27. echo " Platform: $(uname -s)"
  28. echo " Bash Version: $BASH_VERSION"
  29. echo " Shell: $SHELL"
  30. echo ""
  31. # Test 1: Bash version check
  32. echo "Test 1: Bash Version Compatibility"
  33. bash_major="${BASH_VERSION%%.*}"
  34. if [ "$bash_major" -ge 3 ]; then
  35. pass "Bash version $BASH_VERSION is compatible (3.2+ required)"
  36. else
  37. fail "Bash version $BASH_VERSION is too old (3.2+ required)"
  38. fi
  39. # Test 2: Required commands
  40. echo ""
  41. echo "Test 2: Required Dependencies"
  42. for cmd in curl jq; do
  43. if command -v "$cmd" &> /dev/null; then
  44. pass "$cmd is installed"
  45. else
  46. fail "$cmd is not installed"
  47. fi
  48. done
  49. # Test 3: Script syntax check
  50. echo ""
  51. echo "Test 3: Script Syntax Check"
  52. if bash -n install.sh 2>/dev/null; then
  53. pass "Script syntax is valid"
  54. else
  55. fail "Script has syntax errors"
  56. fi
  57. # Test 4: Help command
  58. echo ""
  59. echo "Test 4: Help Command"
  60. if bash install.sh help 2>&1 | grep -q "Usage:"; then
  61. pass "Help command works"
  62. else
  63. fail "Help command failed"
  64. fi
  65. # Test 5: List command
  66. echo ""
  67. echo "Test 5: List Command"
  68. if bash install.sh list 2>&1 | grep -q "Available Components"; then
  69. pass "List command works"
  70. else
  71. fail "List command failed"
  72. fi
  73. # Test 6: Profile argument parsing
  74. echo ""
  75. echo "Test 6: Profile Argument Parsing"
  76. for profile in essential developer full advanced; do
  77. # shellcheck disable=SC2216
  78. if echo "n" | bash install.sh "$profile" 2>&1 | grep -q "Profile:"; then
  79. pass "Profile '$profile' argument works"
  80. else
  81. fail "Profile '$profile' argument failed"
  82. fi
  83. done
  84. # Test 7: Profile with dashes
  85. echo ""
  86. echo "Test 7: Profile Arguments with Dashes"
  87. for profile in --essential --developer --full --advanced; do
  88. # shellcheck disable=SC2216
  89. if echo "n" | bash install.sh "$profile" 2>&1 | grep -q "Profile:"; then
  90. pass "Profile '$profile' argument works"
  91. else
  92. fail "Profile '$profile' argument failed"
  93. fi
  94. done
  95. # Test 8: Array operations
  96. echo ""
  97. echo "Test 8: Array Operations"
  98. test_array=()
  99. test_array+=("item1")
  100. test_array+=("item2")
  101. if [ ${#test_array[@]} -eq 2 ]; then
  102. pass "Array operations work"
  103. else
  104. fail "Array operations failed"
  105. fi
  106. # Test 9: Parameter expansion
  107. echo ""
  108. echo "Test 9: Parameter Expansion"
  109. test_string="type:id"
  110. type="${test_string%%:*}"
  111. id="${test_string##*:}"
  112. if [ "$type" = "type" ] && [ "$id" = "id" ]; then
  113. pass "Parameter expansion works"
  114. else
  115. fail "Parameter expansion failed"
  116. fi
  117. # Test 10: Temp directory creation
  118. echo ""
  119. echo "Test 10: Temp Directory Operations"
  120. test_temp="/tmp/opencode-test-$$"
  121. mkdir -p "$test_temp"
  122. if [ -d "$test_temp" ]; then
  123. pass "Temp directory creation works"
  124. rm -rf "$test_temp"
  125. else
  126. fail "Temp directory creation failed"
  127. fi
  128. # Test 11: File operations
  129. echo ""
  130. echo "Test 11: File Operations"
  131. test_file="/tmp/opencode-test-$$.txt"
  132. echo "test" > "$test_file"
  133. if [ -f "$test_file" ]; then
  134. content=$(cat "$test_file")
  135. if [ "$content" = "test" ]; then
  136. pass "File operations work"
  137. rm -f "$test_file"
  138. else
  139. fail "File read failed"
  140. fi
  141. else
  142. fail "File write failed"
  143. fi
  144. # Test 12: Network connectivity
  145. echo ""
  146. echo "Test 12: Network Connectivity"
  147. if curl -fsSL --max-time 5 https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/README.md > /dev/null 2>&1; then
  148. pass "Network connectivity to GitHub works"
  149. else
  150. warn "Network connectivity test failed (may be offline)"
  151. fi
  152. echo ""
  153. echo "╔════════════════════════════════════════════════════════════════╗"
  154. echo "║ All Tests Passed! ✓ ║"
  155. echo "╚════════════════════════════════════════════════════════════════╝"
  156. echo ""
  157. echo "Your system is compatible with the OpenCode installer."
  158. echo "You can safely run:"
  159. echo " curl -fsSL https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/install.sh | bash"
  160. echo ""