82 lines
2.1 KiB
Bash
Executable File
82 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script to run all examples in the heromodels crate and check if they executed successfully
|
|
|
|
# Set colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[0;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to run an example and check if it executed successfully
|
|
run_example() {
|
|
local example=$1
|
|
echo -e "${YELLOW}Running example: ${example}${NC}"
|
|
|
|
# Run the example and capture the exit code
|
|
cargo run --example $example
|
|
local exit_code=$?
|
|
|
|
# Check if the example executed successfully
|
|
if [ $exit_code -eq 0 ]; then
|
|
echo -e "${GREEN}✓ Example ${example} executed successfully${NC}"
|
|
return 0
|
|
else
|
|
echo -e "${RED}✗ Example ${example} failed with exit code ${exit_code}${NC}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Make sure we're in the heromodels directory
|
|
cd "$(dirname "$0")"
|
|
|
|
# Get all examples
|
|
examples=$(find examples -type f -name "*.rs" -not -path "*/*/main.rs" -not -path "*/*/example.rs" | grep -v "/mod.rs$" | sed 's/examples\///g' | sed 's/\.rs$//g' | sort)
|
|
|
|
# Add directory examples
|
|
dir_examples=$(find examples -type d -depth 1 | sed 's/examples\///g' | sort)
|
|
|
|
# Initialize counters
|
|
total=0
|
|
passed=0
|
|
failed=0
|
|
|
|
# Run all file examples
|
|
echo -e "${YELLOW}Running file examples...${NC}"
|
|
for example in $examples; do
|
|
((total++))
|
|
if run_example $example; then
|
|
((passed++))
|
|
else
|
|
((failed++))
|
|
failed_examples="$failed_examples $example"
|
|
fi
|
|
echo ""
|
|
done
|
|
|
|
# Run all directory examples
|
|
echo -e "${YELLOW}Running directory examples...${NC}"
|
|
for example in $dir_examples; do
|
|
((total++))
|
|
if run_example $example; then
|
|
((passed++))
|
|
else
|
|
((failed++))
|
|
failed_examples="$failed_examples $example"
|
|
fi
|
|
echo ""
|
|
done
|
|
|
|
# Print summary
|
|
echo -e "${YELLOW}Summary:${NC}"
|
|
echo -e "Total examples: ${total}"
|
|
echo -e "${GREEN}Passed: ${passed}${NC}"
|
|
if [ $failed -gt 0 ]; then
|
|
echo -e "${RED}Failed: ${failed}${NC}"
|
|
echo -e "${RED}Failed examples:${failed_examples}${NC}"
|
|
exit 1
|
|
else
|
|
echo -e "${GREEN}All examples executed successfully!${NC}"
|
|
exit 0
|
|
fi
|