1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 11:31:46 +00:00

Parallel scanning and testing

This commit is contained in:
Tw93
2025-12-11 19:24:23 +08:00
parent d5f36e1e9a
commit 2d7932025f
4 changed files with 62 additions and 78 deletions

View File

@@ -13,9 +13,9 @@ GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "================================"
echo "==============================="
echo " Mole Test Runner"
echo "================================"
echo "==============================="
echo ""
# Track failures
@@ -26,13 +26,13 @@ echo "1. Running ShellCheck..."
if command -v shellcheck > /dev/null 2>&1; then
if shellcheck mole bin/*.sh 2> /dev/null &&
find lib -name "*.sh" -type f -exec shellcheck {} + 2> /dev/null; then
echo -e "${GREEN}✓ ShellCheck passed${NC}"
printf "${GREEN}✓ ShellCheck passed${NC}\n"
else
echo -e "${RED}✗ ShellCheck failed${NC}"
printf "${RED}✗ ShellCheck failed${NC}\n"
((FAILED++))
fi
else
echo -e "${YELLOW}⚠ ShellCheck not installed, skipping${NC}"
printf "${YELLOW}⚠ ShellCheck not installed, skipping${NC}\n"
fi
echo ""
@@ -41,9 +41,9 @@ echo "2. Running syntax check..."
if bash -n mole &&
bash -n bin/*.sh 2> /dev/null &&
find lib -name "*.sh" -type f -exec bash -n {} \; 2> /dev/null; then
echo -e "${GREEN}✓ Syntax check passed${NC}"
printf "${GREEN}✓ Syntax check passed${NC}\n"
else
echo -e "${RED}✗ Syntax check failed${NC}"
printf "${RED}✗ Syntax check failed${NC}\n"
((FAILED++))
fi
echo ""
@@ -51,14 +51,16 @@ echo ""
# 3. Unit Tests
echo "3. Running unit tests..."
if command -v bats > /dev/null 2>&1; then
# Note: bats might detect non-TTY and suppress color.
# Adding --tap prevents spinner issues in background.
if bats tests/*.bats; then
echo -e "${GREEN}✓ Unit tests passed${NC}"
printf "${GREEN}✓ Unit tests passed${NC}\n"
else
echo -e "${RED}✗ Unit tests failed${NC}"
printf "${RED}✗ Unit tests failed${NC}\n"
((FAILED++))
fi
else
echo -e "${YELLOW}⚠ Bats not installed, skipping unit tests${NC}"
printf "${YELLOW}⚠ Bats not installed, skipping unit tests${NC}\n"
echo " Install with: brew install bats-core"
fi
echo ""
@@ -67,45 +69,46 @@ echo ""
echo "4. Running Go tests..."
if command -v go > /dev/null 2>&1; then
if go build ./... && go vet ./cmd/... && go test ./cmd/...; then
echo -e "${GREEN}✓ Go tests passed${NC}"
printf "${GREEN}✓ Go tests passed${NC}\n"
else
echo -e "${RED}✗ Go tests failed${NC}"
printf "${RED}✗ Go tests failed${NC}\n"
((FAILED++))
fi
else
echo -e "${YELLOW}⚠ Go not installed, skipping Go tests${NC}"
printf "${YELLOW}⚠ Go not installed, skipping Go tests${NC}\n"
fi
echo ""
# 5. Module Loading Test
echo "5. Testing module loading..."
if bash -c 'source lib/core/common.sh && echo "OK"' > /dev/null 2>&1; then
echo -e "${GREEN}✓ Module loading passed${NC}"
printf "${GREEN}✓ Module loading passed${NC}\n"
else
echo -e "${RED}✗ Module loading failed${NC}"
printf "${RED}✗ Module loading failed${NC}\n"
((FAILED++))
fi
echo ""
# 6. Integration Tests
echo "6. Running integration tests..."
export MOLE_MAX_PARALLEL_JOBS=30
if ./bin/clean.sh --dry-run > /dev/null 2>&1; then
echo -e "${GREEN}✓ Clean dry-run passed${NC}"
printf "${GREEN}✓ Clean dry-run passed${NC}\n"
else
echo -e "${RED}✗ Clean dry-run failed${NC}"
printf "${RED}✗ Clean dry-run failed${NC}\n"
((FAILED++))
fi
echo ""
# Summary
echo "================================"
echo "==============================="
if [[ $FAILED -eq 0 ]]; then
echo -e "${GREEN}All tests passed!${NC}"
printf "${GREEN}All tests passed!${NC}\n"
echo ""
echo "You can now commit your changes."
exit 0
else
echo -e "${RED}$FAILED test(s) failed!${NC}"
printf "${RED}$FAILED test(s) failed!${NC}\n"
echo ""
echo "Please fix the failing tests before committing."
exit 1