-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·116 lines (107 loc) · 3.19 KB
/
test.sh
File metadata and controls
executable file
·116 lines (107 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
# Default values
PROGRAM=""
NO_BUILD=false
NO_SDK_BUILD=false
NO_LOGS=false
WATCH=true
# Parse command line arguments
while [ $# -gt 0 ]; do
case "$1" in
-p|--program)
PROGRAM="$2"
shift 2
;;
--skip-build)
NO_BUILD=true
shift
;;
--no-sdk-build)
NO_SDK_BUILD=true
shift
;;
--no-logs)
NO_LOGS=true
shift
;;
--no-watch)
WATCH=false
shift
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -p, --program <name> Build specific program (e.g., autocrat, amm, conditional_vault)"
echo " --skip-build Skip program building"
echo " --no-sdk-build Skip SDK building"
echo " --no-logs Suppress logs (add RUST_LOG=)"
echo " --no-watch Run once instead of watching for changes"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Build all programs, SDK, and test with logs"
echo " $0 -p autocrat # Build only autocrat program and test"
echo " $0 --skip-build # Skip building, just test"
echo " $0 --no-logs # Test without logs"
echo " $0 -p amm --no-sdk-build --no-logs # Build amm, skip SDK, no logs"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use -h or --help for usage information"
exit 1
;;
esac
done
# Build the command components
BUILD_CMD=""
SDK_CMD=""
TEST_CMD="anchor test --skip-build"
LOG_PREFIX=""
# Add program-specific build if specified
if [ -n "$PROGRAM" ]; then
BUILD_CMD="anchor build -p $PROGRAM"
else
BUILD_CMD="anchor build"
fi
# Add SDK build if not skipped
if [ "$NO_SDK_BUILD" = false ]; then
SDK_CMD="(cd sdk && yarn build-local) &&"
fi
# Add log suppression if requested
if [ "$NO_LOGS" = true ]; then
LOG_PREFIX="RUST_LOG= "
fi
# Construct the final command
if [ "$NO_BUILD" = true ]; then
# Skip program building
FINAL_CMD="$SDK_CMD $LOG_PREFIX$TEST_CMD"
else
# Include program building
FINAL_CMD="$BUILD_CMD && $SDK_CMD $LOG_PREFIX$TEST_CMD"
fi
# Determine what to watch based on what we're building
if [ "$WATCH" = true ]; then
if [ "$NO_BUILD" = true ]; then
# Only watch tests and SDK if not building programs
WATCH_PATHS="tests sdk"
else
# Watch everything
WATCH_PATHS="programs tests sdk"
fi
echo "Watching for changes in: $WATCH_PATHS"
echo "Command: $FINAL_CMD"
echo ""
find $WATCH_PATHS -type f \
-not -path "*/node_modules/*" \
-not -path "*/target/*" \
-not -path "*/.anchor/*" \
-not -path "*/dist/*" \
-not -path "*/.git/*" \
| entr -sc "$FINAL_CMD"
else
echo "Running command: $FINAL_CMD"
echo ""
eval "$FINAL_CMD"
fi