anchor-symlink-test.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # This test script verifies that running 'anchor' commands
  3. # correctly proxies to the installed Anchor CLI binary (e.g., shows Anchor "something")
  4. # instead of launching AVM itself.
  5. # Exit on first error
  6. set -e
  7. # --- Helper for timing and logging ---
  8. function step_start {
  9. echo ""
  10. echo "============================================================"
  11. echo "🚀 Starting Step: $1"
  12. echo "============================================================"
  13. STEP_START_TIME=$(date +%s)
  14. }
  15. function step_end {
  16. local end_time=$(date +%s)
  17. local duration=$((end_time - STEP_START_TIME))
  18. echo "✅ Step completed in ${duration}s."
  19. }
  20. trap 'echo ""; echo "🧹 Cleaning up..."' INT TERM EXIT
  21. step_start "Building local avm"
  22. (cd ../.. && cargo build --package avm)
  23. step_end
  24. step_start "Installing local anchor-cli via avm (force to ensure fresh install)"
  25. ../../target/debug/avm install --path ../.. --force
  26. step_end
  27. # --- Set a Specific Version ---
  28. step_start "Setting AVM to use a known version (e.g., latest)"
  29. ../../target/debug/avm use latest
  30. step_end
  31. # --- Test 'avm' Command (Should Show AVM Help) ---
  32. step_start "Testing 'avm --help' (should show AVM usage)"
  33. AVM_OUTPUT=$(~/.avm/bin/avm --help 2>&1) || true
  34. if echo "$AVM_OUTPUT" | grep -q "Anchor version manager"; then
  35. echo "✅ 'avm --help' shows AVM usage as expected."
  36. else
  37. echo "❌ Test failed: 'avm --help' did not show expected AVM output."
  38. echo "$AVM_OUTPUT"
  39. exit 1
  40. fi
  41. step_end
  42. # --- Test 'anchor' Command (Should Proxy to Anchor CLI) ---
  43. step_start "Testing 'anchor --version' (should show Anchor CLI version, not AVM)"
  44. ANCHOR_OUTPUT=$(~/.avm/bin/anchor --version 2>&1) || true
  45. if echo "$ANCHOR_OUTPUT" | grep -q "anchor-cli"; then
  46. echo "✅ 'anchor --version' proxies to Anchor CLI successfully."
  47. elif echo "$ANCHOR_OUTPUT" | grep -q "Anchor version manager"; then
  48. echo "❌ Test failed: 'anchor --version' is still launching AVM instead of proxying."
  49. echo "$ANCHOR_OUTPUT"
  50. exit 1
  51. else
  52. echo "❌ Test failed: Unexpected output from 'anchor --version'."
  53. echo "$ANCHOR_OUTPUT"
  54. exit 1
  55. fi
  56. step_end
  57. echo ""
  58. echo "============================================================"
  59. echo "🎉 All tests passed successfully! 🎉"
  60. echo "============================================================"