|
| 1 | +.PHONY: test test-go test-node test-python test-quarkus test-rust test-springboot test-typescript test-ci invoke-ci |
| 2 | + |
| 3 | +LOG := test-results.log |
| 4 | +START_TIME := $(shell date +%s%3N) |
| 5 | + |
| 6 | +# Skipped templates: |
| 7 | +# go/blog — Hugo theme is a broken submodule, func create doesn't fetch submodules |
| 8 | +# python/llamacpp, mcp, mcp-ollama, mcp-ollama-rag, ollama-client — need external services or have broken tests |
| 9 | +GO_SKIP := blog |
| 10 | +PYTHON_SKIP := llamacpp mcp mcp-ollama mcp-ollama-rag ollama-client |
| 11 | + |
| 12 | +# Run tests for each template in a language directory. |
| 13 | +# For each template: check skip list, run test command, print colored result with timing. |
| 14 | +# Detailed output goes to LOG file; PASS/FAIL/SKIP printed to stdout. |
| 15 | +# Args: $(1)=language dir $(2)=space-separated skip list $(3)=test command |
| 16 | +define run_tests |
| 17 | + @for dir in $(1)/*/; do \ |
| 18 | + t=$$(basename $$dir); \ |
| 19 | + skip=false; for s in $(2); do [ "$$t" = "$$s" ] && skip=true && break; done; \ |
| 20 | + if [ "$$skip" = "true" ]; then \ |
| 21 | + printf "\033[33mSKIP\033[0m %s\n" "$$dir"; echo "SKIP $$dir" >> $(LOG); continue; \ |
| 22 | + fi; \ |
| 23 | + start=$$(date +%s%3N); \ |
| 24 | + if (cd $$dir && $(3)) >> $(LOG) 2>&1; then \ |
| 25 | + ms=$$(( $$(date +%s%3N) - $$start )); \ |
| 26 | + printf "\033[32mPASS\033[0m %s (%d.%03ds)\n" "$$dir" "$$((ms/1000))" "$$((ms%1000))"; \ |
| 27 | + echo "PASS $$dir ($${ms}ms)" >> $(LOG); \ |
| 28 | + else \ |
| 29 | + ms=$$(( $$(date +%s%3N) - $$start )); \ |
| 30 | + printf "\033[31mFAIL\033[0m %s (%d.%03ds)\n" "$$dir" "$$((ms/1000))" "$$((ms%1000))"; \ |
| 31 | + echo "FAIL $$dir ($${ms}ms)" >> $(LOG); \ |
| 32 | + fi; \ |
| 33 | + done |
| 34 | +endef |
| 35 | + |
| 36 | +test: clean-log test-go test-node test-python test-quarkus test-rust test-springboot test-typescript summary |
| 37 | + |
| 38 | +clean-log: |
| 39 | + @rm -f $(LOG) |
| 40 | + @echo "Running tests..." |
| 41 | + |
| 42 | +test-go: ; $(call run_tests,go,$(GO_SKIP),go test -count=1 ./...) |
| 43 | +test-node: ; $(call run_tests,node,,npm install --silent && npm test && rm -rf node_modules) |
| 44 | +test-python: ; $(call run_tests,python,$(PYTHON_SKIP),python -m venv .venv && .venv/bin/pip install -q '.[dev]' && .venv/bin/python -m pytest tests/ && rm -rf .venv) |
| 45 | +test-quarkus: ; $(call run_tests,quarkus,,mvn test -q) |
| 46 | +test-rust: ; $(call run_tests,rust,,cargo test) |
| 47 | +test-springboot: ; $(call run_tests,springboot,,mvn test -q) |
| 48 | +test-typescript: ; $(call run_tests,typescript,,npm install --silent && npm test && rm -rf node_modules build) |
| 49 | + |
| 50 | +summary: |
| 51 | + @echo "" |
| 52 | + @echo "=== Test Summary ===" |
| 53 | + @passed=$$(grep -c "^PASS" $(LOG) || true); \ |
| 54 | + failed=$$(grep -c "^FAIL" $(LOG) || true); \ |
| 55 | + skipped=$$(grep -c "^SKIP" $(LOG) || true); \ |
| 56 | + ms=$$(( $$(date +%s%3N) - $(START_TIME) )); \ |
| 57 | + printf "\033[32m$$passed passed\033[0m, \033[31m$$failed failed\033[0m, \033[33m$$skipped skipped\033[0m in %d.%03ds\n" "$$((ms/1000))" "$$((ms%1000))"; \ |
| 58 | + echo "Full log: $(LOG)"; \ |
| 59 | + if [ "$$failed" -gt 0 ]; then echo ""; echo "=== Failed ==="; grep "^FAIL" $(LOG); exit 1; fi |
| 60 | + |
0 commit comments