#!/bin/bash # test.sh - 测试脚本 set -e echo "================================" echo " Running Tests" echo "================================" echo "" # 颜色定义 GREEN='\033[0;32m' RED='\033[0;31m' NC='\033[0m' # 运行单元测试 echo "Running unit tests..." if go test ./... -v -cover; then echo -e "${GREEN}✓ Unit tests passed${NC}" else echo -e "${RED}✗ Unit tests failed${NC}" exit 1 fi echo "" # 运行竞态检测 echo "Running race detector..." if go test ./... -race; then echo -e "${GREEN}✓ Race detector passed${NC}" else echo -e "${RED}✗ Race conditions detected${NC}" exit 1 fi echo "" # 运行 vet echo "Running go vet..." if go vet ./...; then echo -e "${GREEN}✓ Go vet passed${NC}" else echo -e "${RED}✗ Go vet found issues${NC}" exit 1 fi echo "" # 检查格式 echo "Checking code format..." if [ -z "$(gofmt -l .)" ]; then echo -e "${GREEN}✓ Code is properly formatted${NC}" else echo -e "${RED}✗ Code needs formatting:${NC}" gofmt -l . exit 1 fi echo "" echo -e "${GREEN}================================${NC}" echo -e "${GREEN} All Tests Passed!${NC}" echo -e "${GREEN}================================${NC}"