-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathagent_test.sh
More file actions
executable file
·127 lines (107 loc) · 4.24 KB
/
agent_test.sh
File metadata and controls
executable file
·127 lines (107 loc) · 4.24 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
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# Check if running on macOS
if [[ "$(uname)" != "Darwin" ]]; then
echo "❌ This script requires macOS to run Xcode tests"
exit 1
fi
# Parse command line arguments
FILTER=""
LIST_TESTS=false
if [[ $# -eq 1 ]]; then
if [[ "$1" == "--list" ]]; then
LIST_TESTS=true
else
FILTER="$1"
echo "🎯 Running tests with filter: $FILTER"
fi
elif [[ $# -gt 1 ]]; then
echo "❌ Usage: $0 [filter|--list]"
echo " filter: Test suite name (e.g., 'IterableApiCriteriaFetchTests')"
echo " or specific test (e.g., 'IterableApiCriteriaFetchTests.testForegroundCriteriaFetchWhenConditionsMet')"
echo " or full path (e.g., 'unit-tests/IterableApiCriteriaFetchTests/testForegroundCriteriaFetchWhenConditionsMet')"
echo " --list: List all available test suites and tests"
exit 1
fi
# Handle test listing
if [[ "$LIST_TESTS" == true ]]; then
echo "📋 Listing available test suites..."
# Use grep to extract test class names from source files
echo "📦 Available Test Suites:"
find tests/unit-tests -name "*.swift" -exec basename {} .swift \; | sort | while read test_file; do
# Count test methods in each file
test_count=$(grep -c "func test" "tests/unit-tests/$test_file.swift" 2>/dev/null || echo "0")
echo " • $test_file ($test_count tests)"
done
echo ""
echo "🔍 Example Usage:"
echo " ./agent_test.sh AuthTests"
echo " ./agent_test.sh \"AuthTests.testAsyncAuthTokenRetrieval\""
echo ""
echo "💡 To see specific test methods in a suite, check the source file:"
echo " grep 'func test' tests/unit-tests/AuthTests.swift"
exit 0
fi
# Make sure xcpretty is installed
if ! command -v xcpretty &> /dev/null; then
echo "xcpretty not found, installing via gem..."
sudo gem install xcpretty
fi
echo "Running Iterable Swift SDK unit tests..."
# Create a temporary file for the test output
TEMP_OUTPUT=$(mktemp)
# Build the xcodebuild command
XCODEBUILD_CMD="xcodebuild test \
-project swift-sdk.xcodeproj \
-scheme swift-sdk \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 16 Pro,OS=18.2' \
-enableCodeCoverage YES \
-skipPackagePluginValidation \
CODE_SIGNING_REQUIRED=NO"
# Add filter if specified
if [[ -n "$FILTER" ]]; then
# If filter contains a slash, use it as-is (already in unit-tests/TestSuite/testMethod format)
if [[ "$FILTER" == *"/"* ]]; then
XCODEBUILD_CMD="$XCODEBUILD_CMD -only-testing:$FILTER"
# If filter contains a dot, convert TestSuite.testMethod to unit-tests/TestSuite/testMethod
elif [[ "$FILTER" == *"."* ]]; then
TEST_SUITE=$(echo "$FILTER" | cut -d'.' -f1)
TEST_METHOD=$(echo "$FILTER" | cut -d'.' -f2)
XCODEBUILD_CMD="$XCODEBUILD_CMD -only-testing:unit-tests/$TEST_SUITE/$TEST_METHOD"
# Otherwise, assume it's just a test suite name and add the target
else
XCODEBUILD_CMD="$XCODEBUILD_CMD -only-testing:unit-tests/$FILTER"
fi
fi
# Run the tests with xcpretty for clean output (incremental - skips rebuild if possible)
eval $XCODEBUILD_CMD 2>&1 | tee $TEMP_OUTPUT | xcpretty
# Check the exit status
TEST_STATUS=$?
# Parse the "Executed X test(s), with Y failure(s)" line
EXECUTED_LINE=$(grep "Executed.*test.*with.*failure" $TEMP_OUTPUT | tail -1)
if [[ -n "$EXECUTED_LINE" ]]; then
TOTAL_TESTS=$(echo "$EXECUTED_LINE" | sed -n 's/.*Executed \([0-9][0-9]*\) test.*/\1/p')
FAILED_TESTS=$(echo "$EXECUTED_LINE" | sed -n 's/.*with \([0-9][0-9]*\) failure.*/\1/p')
# Ensure we have valid numbers
if [[ -z "$TOTAL_TESTS" ]]; then TOTAL_TESTS=0; fi
if [[ -z "$FAILED_TESTS" ]]; then FAILED_TESTS=0; fi
PASSED_TESTS=$(($TOTAL_TESTS - $FAILED_TESTS))
else
TOTAL_TESTS=0
FAILED_TESTS=0
PASSED_TESTS=0
fi
# Show test results
if [ "$FAILED_TESTS" -eq 0 ] && [ "$TOTAL_TESTS" -gt 0 ]; then
echo "✅ All tests passed! ($TOTAL_TESTS tests)"
FINAL_STATUS=0
elif [ "$FAILED_TESTS" -gt 0 ]; then
echo "❌ Tests failed: $FAILED_TESTS failed, $PASSED_TESTS passed ($TOTAL_TESTS total)"
FINAL_STATUS=1
else
echo "⚠️ No test results found"
FINAL_STATUS=$TEST_STATUS
fi
# Remove the temporary file
rm $TEMP_OUTPUT
exit $FINAL_STATUS