From bd36d6bda0f5259703585f789bded7e11436bb55 Mon Sep 17 00:00:00 2001 From: Mahmoud Emad Date: Sat, 17 May 2025 16:10:37 +0300 Subject: [PATCH] test: Add shell script to run all examples --- heromodels/run_all_examples.sh | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 heromodels/run_all_examples.sh diff --git a/heromodels/run_all_examples.sh b/heromodels/run_all_examples.sh new file mode 100755 index 0000000..69d4a7d --- /dev/null +++ b/heromodels/run_all_examples.sh @@ -0,0 +1,81 @@ +#!/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