211 lines
5.2 KiB
Bash
211 lines
5.2 KiB
Bash
#!/bin/bash
|
|
|
|
# Flalingo Test Runner Script
|
|
# This script runs all tests for the Flalingo project with proper setup and cleanup
|
|
|
|
set -e # Exit on any error
|
|
|
|
echo "🧪 Flalingo Test Runner"
|
|
echo "======================="
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Check if we're in the right directory
|
|
if [ ! -f "Cargo.toml" ]; then
|
|
print_error "Please run this script from the src-tauri directory"
|
|
exit 1
|
|
fi
|
|
|
|
# Create test directories if they don't exist
|
|
print_status "Setting up test environment..."
|
|
mkdir -p test_dbs
|
|
mkdir -p test_json_files
|
|
mkdir -p test_exports
|
|
mkdir -p test_backups
|
|
|
|
# Set environment variables for testing
|
|
export RUST_LOG=debug
|
|
export RUST_BACKTRACE=1
|
|
|
|
# Function to cleanup test files
|
|
cleanup() {
|
|
print_status "Cleaning up test files..."
|
|
rm -rf test_dbs
|
|
rm -rf test_json_files
|
|
rm -rf test_exports
|
|
rm -rf test_backups
|
|
rm -rf test_templates
|
|
rm -rf test_validation
|
|
rm -rf test_directory
|
|
rm -rf test_stats
|
|
print_success "Cleanup completed"
|
|
}
|
|
|
|
# Cleanup on script exit
|
|
trap cleanup EXIT
|
|
|
|
# Run different types of tests
|
|
run_unit_tests() {
|
|
print_status "Running unit tests..."
|
|
cargo test --lib --verbose
|
|
if [ $? -eq 0 ]; then
|
|
print_success "Unit tests passed"
|
|
else
|
|
print_error "Unit tests failed"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
run_integration_tests() {
|
|
print_status "Running integration tests..."
|
|
cargo test --test integration_tests --verbose
|
|
if [ $? -eq 0 ]; then
|
|
print_success "Integration tests passed"
|
|
else
|
|
print_error "Integration tests failed"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
run_repository_tests() {
|
|
print_status "Running repository tests..."
|
|
|
|
# Run individual repository test files
|
|
local test_files=(
|
|
"metadata_repository_tests"
|
|
"exercise_repository_tests"
|
|
"node_repository_tests"
|
|
"path_repository_tests"
|
|
"repository_manager_tests"
|
|
"json_utils_tests"
|
|
)
|
|
|
|
for test_file in "${test_files[@]}"; do
|
|
print_status "Running ${test_file}..."
|
|
cargo test --test "$test_file" --verbose
|
|
if [ $? -eq 0 ]; then
|
|
print_success "${test_file} passed"
|
|
else
|
|
print_error "${test_file} failed"
|
|
return 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
run_performance_tests() {
|
|
print_status "Running performance tests..."
|
|
cargo test --test integration_tests test_large_data_operations --verbose --release
|
|
if [ $? -eq 0 ]; then
|
|
print_success "Performance tests passed"
|
|
else
|
|
print_warning "Performance tests failed (this may be expected on slower systems)"
|
|
fi
|
|
}
|
|
|
|
run_doc_tests() {
|
|
print_status "Running documentation tests..."
|
|
cargo test --doc
|
|
if [ $? -eq 0 ]; then
|
|
print_success "Documentation tests passed"
|
|
else
|
|
print_warning "Documentation tests failed"
|
|
fi
|
|
}
|
|
|
|
# Main test execution
|
|
main() {
|
|
print_status "Starting test suite..."
|
|
|
|
# Check if cargo is available
|
|
if ! command -v cargo &> /dev/null; then
|
|
print_error "Cargo not found. Please install Rust and Cargo."
|
|
exit 1
|
|
fi
|
|
|
|
# Build the project first
|
|
print_status "Building project..."
|
|
cargo build
|
|
if [ $? -ne 0 ]; then
|
|
print_error "Build failed"
|
|
exit 1
|
|
fi
|
|
print_success "Build completed"
|
|
|
|
# Parse command line arguments
|
|
case "${1:-all}" in
|
|
"unit")
|
|
run_unit_tests
|
|
;;
|
|
"integration")
|
|
run_integration_tests
|
|
;;
|
|
"repository")
|
|
run_repository_tests
|
|
;;
|
|
"performance")
|
|
run_performance_tests
|
|
;;
|
|
"doc")
|
|
run_doc_tests
|
|
;;
|
|
"all")
|
|
print_status "Running all tests..."
|
|
run_unit_tests && \
|
|
run_repository_tests && \
|
|
run_integration_tests && \
|
|
run_performance_tests && \
|
|
run_doc_tests
|
|
;;
|
|
"quick")
|
|
print_status "Running quick test suite (unit + repository)..."
|
|
run_unit_tests && \
|
|
run_repository_tests
|
|
;;
|
|
*)
|
|
echo "Usage: $0 [unit|integration|repository|performance|doc|all|quick]"
|
|
echo ""
|
|
echo "Test Categories:"
|
|
echo " unit - Run unit tests only"
|
|
echo " integration - Run integration tests only"
|
|
echo " repository - Run repository tests only"
|
|
echo " performance - Run performance tests only"
|
|
echo " doc - Run documentation tests only"
|
|
echo " all - Run all tests (default)"
|
|
echo " quick - Run unit and repository tests only"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
if [ $? -eq 0 ]; then
|
|
print_success "🎉 All requested tests completed successfully!"
|
|
else
|
|
print_error "❌ Some tests failed. Check the output above for details."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Run the main function with all arguments
|
|
main "$@"
|