Skip to content

Commit 8a9c097

Browse files
committed
feat: add idempotent feature in battle test script
1 parent 8619f16 commit 8a9c097

File tree

2 files changed

+37
-184
lines changed

2 files changed

+37
-184
lines changed

tests/battle_test/battle_testing.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
22

3-
#!/bin/bash
4-
53
# -----------------------------------------------------------------------------
64
# Script to format files in repos with improved git error handling
75
# -----------------------------------------------------------------------------
@@ -93,6 +91,13 @@ done < "$REPO_LIST"
9391
> "$LOG_FILE"
9492
# > "$LONG_LINES_LOG_FILE"
9593

94+
# Check for idempotent mode flag
95+
IDEMPOTENT_MODE=false
96+
if [ "$1" == "--idempotent" ]; then
97+
IDEMPOTENT_MODE=true
98+
echo "Idempotent testing mode activated."
99+
fi
100+
96101
# Function to format files and log errors with clear info
97102
format_files() {
98103
local FILE_PATH="$1"
@@ -129,7 +134,30 @@ format_files() {
129134
# echo "$OUTPUT" | grep -E "$PATTERN" >> "$LONG_LINES_LOG_FILE"
130135
}
131136

137+
idempotent_test() {
138+
local FILE_PATH="$1"
139+
TMP1=$(mktemp)
140+
TMP2=$(mktemp)
141+
142+
# Format once and save output to TMP1
143+
$FORMATTER_BINARY "$FILE_PATH" > "$TMP1" 2>/dev/null
144+
145+
# Format the result of the first formatting and save to TMP2
146+
$FORMATTER_BINARY "$TMP1" > "$TMP2" 2>/dev/null
147+
148+
# Compare the two outputs
149+
if ! diff -q "$TMP1" "$TMP2" &>/dev/null; then
150+
echo "Idempotency test failed for $FILE_PATH" >> "$LOG_FILE"
151+
echo "Difference found in idempotency test for: $FILE_PATH"
152+
else
153+
echo "Idempotency test passed for $FILE_PATH"
154+
fi
155+
156+
rm -f "$TMP1" "$TMP2"
157+
}
158+
132159
export -f format_files
160+
export -f idempotent_test
133161
export FORMATTER_BINARY
134162
export LOG_FILE
135163
# export LONG_LINES_LOG_FILE
@@ -142,6 +170,13 @@ START_TIME=$(date +%s)
142170
find "$TARGET_DIR" \( -type d \( -name ".sfdx" -o -name "scripts" \) \) -prune -o -type f \( -name "*.cls" -o -name "*.trigger" \) -print0 | \
143171
parallel -0 -j+0 format_files
144172

173+
# Run idempotent testing if mode is activated
174+
if [ "$IDEMPOTENT_MODE" = true ]; then
175+
echo "Running idempotency tests..."
176+
find "$TARGET_DIR" \( -type d \( -name ".sfdx" -o -name "scripts" \) \) -prune -o -type f \( -name "*.cls" -o -name "*.trigger" \) -print0 | \
177+
parallel -0 -j+0 idempotent_test
178+
fi
179+
145180
# find "$TARGET_DIR" -path "$TARGET_DIR/.sfdx" -prune -o -type f \( -name "*.cls" -o -name "*.trigger" \) -print0 | \
146181
# parallel -0 -j+0 format_files
147182

tests/battle_test/download_latest_binary_to_home_path.sh

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)