From b2b7f2468154435a28a174f5ec31e19e20fe44d2 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 17:05:49 -0500 Subject: Consolidate Makefiles and update TESTING.org Root Makefile now delegates to tests/Makefile. Fixed stale UNIT_TESTS/INTEGRATION_TESTS definitions, added test-name target, switched to per-file test execution for better isolation. --- Makefile | 127 ++++++++++++++------------------------------------------- tests/Makefile | 75 +++++++++++++++++++--------------- 2 files changed, 73 insertions(+), 129 deletions(-) diff --git a/Makefile b/Makefile index 79bf631..092de0f 100644 --- a/Makefile +++ b/Makefile @@ -1,114 +1,47 @@ # Makefile for chime.el -# -# Usage: -# make test - Run all tests (unit + integration) -# make test-unit - Run unit tests only -# make test-integration - Run integration tests only -# make test-file FILE=test-chime-notify.el - Run specific test file -# make test-name TEST=test-chime-check-* - Run tests matching pattern -# make clean - Remove generated files +# Delegates all test targets to tests/Makefile. +# Run 'make help' for available commands. -# Emacs binary to use (override with: make EMACS=emacs29 test) -EMACS ?= emacs - -# Test directories and files TEST_DIR = tests -UNIT_TESTS = $(filter-out $(TEST_DIR)/test-integration-%.el, $(wildcard $(TEST_DIR)/test-*.el)) -INTEGRATION_TESTS = $(wildcard $(TEST_DIR)/test-integration-*.el) -ALL_TESTS = $(UNIT_TESTS) $(INTEGRATION_TESTS) - -# Emacs batch flags -EMACS_BATCH = $(EMACS) --batch --no-site-file --no-site-lisp -.PHONY: help test test-all test-unit test-integration test-file test-name clean +.PHONY: help test test-unit test-integration test-file test-one test-name \ + count list validate lint check-deps clean -# Default target help: - @echo "Chime.el Test Targets:" - @echo "" - @echo " make test - Run all tests (unit + integration)" - @echo " make test-unit - Run unit tests only ($(words $(UNIT_TESTS)) files)" - @echo " make test-integration - Run integration tests only ($(words $(INTEGRATION_TESTS)) files)" - @echo " make test-file FILE= - Run specific test file" - @echo " make test-name TEST= - Run tests matching pattern" - @echo " make clean - Remove generated files" - @echo "" - @echo "Examples:" - @echo " make test-file FILE=test-chime-notify.el" - @echo " make test-name TEST=test-chime-check-early-return" - @echo " make EMACS=emacs29 test # Use specific Emacs version" - -# Run all tests -test: test-all + @$(MAKE) -C $(TEST_DIR) help -test-all: - @echo "[i] Running all tests ($(words $(ALL_TESTS)) files)..." - @$(MAKE) test-unit - @$(MAKE) test-integration - @echo "[✓] All tests complete" +test: + @$(MAKE) -C $(TEST_DIR) test -# Run unit tests only test-unit: - @echo "[i] Running unit tests ($(words $(UNIT_TESTS)) files)..." - @failed=0; \ - for test in $(UNIT_TESTS); do \ - echo " Testing $$test..."; \ - (cd $(TEST_DIR) && $(EMACS_BATCH) -l ert -l $$(basename $$test) -f ert-run-tests-batch-and-exit) || failed=$$((failed + 1)); \ - done; \ - if [ $$failed -eq 0 ]; then \ - echo "[✓] All unit tests passed"; \ - else \ - echo "[✗] $$failed unit test file(s) failed"; \ - exit 1; \ - fi + @$(MAKE) -C $(TEST_DIR) test-unit -# Run integration tests only test-integration: - @echo "[i] Running integration tests ($(words $(INTEGRATION_TESTS)) files)..." - @failed=0; \ - for test in $(INTEGRATION_TESTS); do \ - echo " Testing $$test..."; \ - (cd $(TEST_DIR) && $(EMACS_BATCH) -l ert -l $$(basename $$test) -f ert-run-tests-batch-and-exit) || failed=$$((failed + 1)); \ - done; \ - if [ $$failed -eq 0 ]; then \ - echo "[✓] All integration tests passed"; \ - else \ - echo "[✗] $$failed integration test file(s) failed"; \ - exit 1; \ - fi + @$(MAKE) -C $(TEST_DIR) test-integration -# Run specific test file -# Usage: make test-file FILE=test-chime-notify.el test-file: -ifndef FILE - @echo "[✗] Error: FILE parameter required" - @echo "Usage: make test-file FILE=test-chime-notify.el" - @exit 1 -endif - @echo "[i] Running tests in $(FILE)..." - @cd $(TEST_DIR) && $(EMACS_BATCH) -l ert -l $(FILE) -f ert-run-tests-batch-and-exit - @echo "[✓] Tests in $(FILE) complete" + @$(MAKE) -C $(TEST_DIR) test-file FILE="$(FILE)" + +test-one: + @$(MAKE) -C $(TEST_DIR) test-one TEST="$(TEST)" -# Run specific test by name/pattern -# Usage: make test-name TEST=test-chime-check-early-return -# make test-name TEST="test-chime-check-*" test-name: -ifndef TEST - @echo "[✗] Error: TEST parameter required" - @echo "Usage: make test-name TEST=test-chime-check-early-return" - @echo " make test-name TEST='test-chime-check-*'" - @exit 1 -endif - @echo "[i] Running tests matching pattern: $(TEST)..." - @cd $(TEST_DIR) && $(EMACS_BATCH) \ - -l ert \ - $(foreach test,$(ALL_TESTS),-l $(notdir $(test))) \ - --eval '(ert-run-tests-batch-and-exit "$(TEST)")' - @echo "[✓] Tests matching '$(TEST)' complete" + @$(MAKE) -C $(TEST_DIR) test-name TEST="$(TEST)" + +count: + @$(MAKE) -C $(TEST_DIR) count + +list: + @$(MAKE) -C $(TEST_DIR) list + +validate: + @$(MAKE) -C $(TEST_DIR) validate + +lint: + @$(MAKE) -C $(TEST_DIR) lint + +check-deps: + @$(MAKE) -C $(TEST_DIR) check-deps -# Clean generated files clean: - @echo "[i] Cleaning generated files..." - @find . -name "*.elc" -delete - @find $(TEST_DIR) -name "chime-test-*" -delete - @echo "[✓] Clean complete" + @$(MAKE) -C $(TEST_DIR) clean diff --git a/tests/Makefile b/tests/Makefile index 18df12e..12e81f1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -22,9 +22,9 @@ ASYNC_DIR = $(shell find $(ELPA_DIR) -maxdepth 1 -name 'async-*' -type d 2>/dev/ LOADPATH = -L $(DASH_DIR) -L $(ALERT_DIR) -L $(ASYNC_DIR) # Test files -ALL_TESTS = $(wildcard test-*.el) -UNIT_TESTS = $(filter-out test-chime-gcal% test-chime-notifications.el test-chime-process-notifications.el,$(ALL_TESTS)) -INTEGRATION_TESTS = test-chime-notifications.el test-chime-process-notifications.el +ALL_TESTS = $(filter-out test-bootstrap.el,$(wildcard test-*.el)) +UNIT_TESTS = $(filter-out test-integration-%.el,$(ALL_TESTS)) +INTEGRATION_TESTS = $(wildcard test-integration-*.el) # Colors for output (if terminal supports it) RED = \033[0;31m @@ -32,7 +32,7 @@ GREEN = \033[0;32m YELLOW = \033[1;33m NC = \033[0m # No Color -.PHONY: all test test-file test-one test-unit test-integration validate lint clean help check-deps +.PHONY: all test test-file test-one test-name test-unit test-integration validate lint clean help check-deps # Default target all: test @@ -55,16 +55,10 @@ check-deps: # Run all tests test: check-deps - @echo "$(YELLOW)Running all tests ($(words $(ALL_TESTS)) files, ~339 tests)...$(NC)" - @$(EMACS) $(EMACSFLAGS) $(LOADPATH) $(TESTFLAGS) \ - --eval "(dolist (f (directory-files \".\" t \"^test-.*\\\\.el$$\")) (load f))" \ - --eval '(ert-run-tests-batch-and-exit)' 2>&1 | tee test-output.log - @if [ $$? -eq 0 ]; then \ - echo "$(GREEN)✓ All tests passed!$(NC)"; \ - else \ - echo "$(RED)✗ Some tests failed. See test-output.log for details.$(NC)"; \ - exit 1; \ - fi + @echo "$(YELLOW)Running all tests ($(words $(ALL_TESTS)) files)...$(NC)" + @$(MAKE) --no-print-directory test-unit + @$(MAKE) --no-print-directory test-integration + @echo "$(GREEN)[✓] All tests complete$(NC)" # Run tests in one file test-file: check-deps @@ -117,32 +111,48 @@ endif # Run only unit tests test-unit: check-deps @echo "$(YELLOW)Running unit tests ($(words $(UNIT_TESTS)) files)...$(NC)" - @for testfile in $(UNIT_TESTS); do \ + @failed=0; \ + for testfile in $(UNIT_TESTS); do \ echo " Testing $$testfile..."; \ - done - @$(EMACS) $(EMACSFLAGS) $(LOADPATH) $(TESTFLAGS) \ - $(foreach file,$(UNIT_TESTS),-l $(file)) \ - --eval '(ert-run-tests-batch-and-exit)' 2>&1 | tee test-unit-output.log - @if [ $$? -eq 0 ]; then \ - echo "$(GREEN)✓ All unit tests passed!$(NC)"; \ + $(EMACS) $(EMACSFLAGS) $(LOADPATH) $(TESTFLAGS) -l "$$testfile" \ + --eval '(ert-run-tests-batch-and-exit)' || failed=$$((failed + 1)); \ + done; \ + if [ $$failed -eq 0 ]; then \ + echo "$(GREEN)[✓] All unit tests passed$(NC)"; \ else \ - echo "$(RED)✗ Some unit tests failed.$(NC)"; \ + echo "$(RED)[✗] $$failed unit test file(s) failed$(NC)"; \ exit 1; \ fi # Run only integration tests test-integration: check-deps @echo "$(YELLOW)Running integration tests ($(words $(INTEGRATION_TESTS)) files)...$(NC)" - @$(EMACS) $(EMACSFLAGS) $(LOADPATH) $(TESTFLAGS) \ - $(foreach file,$(INTEGRATION_TESTS),-l $(file)) \ - --eval '(ert-run-tests-batch-and-exit)' 2>&1 | tee test-integration-output.log - @if [ $$? -eq 0 ]; then \ - echo "$(GREEN)✓ All integration tests passed!$(NC)"; \ + @failed=0; \ + for testfile in $(INTEGRATION_TESTS); do \ + echo " Testing $$testfile..."; \ + $(EMACS) $(EMACSFLAGS) $(LOADPATH) $(TESTFLAGS) -l "$$testfile" \ + --eval '(ert-run-tests-batch-and-exit)' || failed=$$((failed + 1)); \ + done; \ + if [ $$failed -eq 0 ]; then \ + echo "$(GREEN)[✓] All integration tests passed$(NC)"; \ else \ - echo "$(RED)✗ Some integration tests failed.$(NC)"; \ + echo "$(RED)[✗] $$failed integration test file(s) failed$(NC)"; \ exit 1; \ fi +# Run tests matching a name pattern (ERT selector) +test-name: check-deps +ifndef TEST + @echo "$(RED)Error: TEST not specified$(NC)" + @echo "Usage: make test-name TEST=test-chime-check-early-return" + @echo " make test-name TEST='test-chime-check-*'" + @exit 1 +endif + @echo "$(YELLOW)Running tests matching pattern: $(TEST)...$(NC)" + @$(EMACS) $(EMACSFLAGS) $(LOADPATH) $(TESTFLAGS) \ + --eval "(dolist (f (directory-files \".\" t \"^test-.*\\\\.el$$\")) (load f))" \ + --eval '(ert-run-tests-batch-and-exit "$(TEST)")' + # Count tests count: @echo "Test file inventory:" @@ -220,11 +230,12 @@ help: @echo "Chime Test Suite Makefile" @echo "" @echo "Usage:" - @echo " make test - Run all tests (339 tests)" - @echo " make test-file FILE=overdue - Run tests in one file (fuzzy match)" - @echo " make test-one TEST=pilot - Run one specific test (fuzzy match)" + @echo " make test - Run all tests (unit + integration)" @echo " make test-unit - Run unit tests only" @echo " make test-integration - Run integration tests only" + @echo " make test-file FILE=overdue - Run tests in one file (fuzzy match)" + @echo " make test-one TEST=pilot - Run one specific test (fuzzy match)" + @echo " make test-name TEST=pattern - Run tests matching ERT name pattern" @echo " make validate - Validate Emacs Lisp syntax (parens balance)" @echo " make lint - Comprehensive linting with elisp-lint" @echo " make count - Count tests per file" @@ -237,7 +248,7 @@ help: @echo " make test # Run everything" @echo " make test-file FILE=overdue # Run test-chime-overdue-todos.el" @echo " make test-one TEST=pilot # Run the pilot test" - @echo " make test-one TEST=test-overdue-has-passed # Run specific test" + @echo " make test-name TEST='test-chime-check-*' # Run tests matching pattern" @echo "" @echo "Environment variables:" @echo " EMACS - Emacs executable (default: emacs)" -- cgit v1.2.3