-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchanged-test.sh
executable file
·51 lines (43 loc) · 1.56 KB
/
changed-test.sh
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
#!/bin/bash
# Get the changed files
changed_files=$(git diff --name-only HEAD | grep '\.rs$')
# Initialize counters
success_count=0
failure_count=0
test_error_detected=false
for file in $changed_files; do
# Match files in the `crates/<crate-name>/src/` structure
if [[ $file == crates/*/src/* ]]; then
# Extract the crate name from the path
crate=$(echo $file | awk -F'/' '{print $2}')
# Extract the module name (file without extension)
module=$(basename "${file%.*}")
echo "Running tests for crate: $crate, module: $module"
# Run tests for the crate and module, capture status
cargo test -p "$crate" "$module"
status=$?
if [[ $status -eq 0 ]]; then
((success_count++))
elif [[ $status -ne 0 ]]; then
# Check if it's a compilation error
if [[ $(cargo test -p "$crate" "$module" 2>&1 | grep -q "error: could not compile") ]]; then
echo "Compilation failed for crate: $crate, module: $module."
else
((failure_count++))
test_error_detected=true
echo "Test failure detected in crate: $crate, module: $module"
fi
fi
fi
done
# Create a summary message
if [[ $success_count -gt 0 || $failure_count -gt 0 ]]; then
message="Tests completed. Success: $success_count, Failures: $failure_count."
echo "$message"
# Display macOS notification only for test failures or success
if [[ $test_error_detected == true || $failure_count -eq 0 ]]; then
osascript -e "display notification \"$message\" with title \"Test Execution Results\""
fi
else
echo "No tests run."
fi