From 8536ea51d05f3540a1179f230b625e04ece455d8 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Wed, 11 Dec 2024 01:33:40 +0300 Subject: [PATCH] Implement testing with existing tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code that's being removed here made no sense. It is a `check` rule, and it did the following things: 1. For every `.el` file it was searching its `tests.el` counterpart. Which doesn't exist. 2. It was checking the correctness of `declare-function`s. Which would be fine, wasn't it for the fact the project has zero `declare-function`s. 3. It was checking that `ert` exists, which it does on all supported Emacs versions. 4. It was removing .elc files before running the tests. Why? 🤷‍♂️ Replace everything with a single `test` rule which simply loads the test files and runs the tests. Besides being actually useful, this also improves running time as: Initial state | Before | After | Non-compiled | 2.177 | 0.340 | Compiled | 2.182 | 1.614 | --- .github/workflows/ci.yml | 2 +- Makefile | 30 +++++++++--------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57381f9..0df5c07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,4 +29,4 @@ jobs: - uses: actions/checkout@v2 - name: Run tests - run: make check + run: make test diff --git a/Makefile b/Makefile index b930b15..e893977 100644 --- a/Makefile +++ b/Makefile @@ -23,43 +23,31 @@ ELFILES = \ purescript-unicode-input-method.el \ purescript-utils.el \ purescript-decl-scan.el \ - purescript-yas.el + purescript-yas.el \ + tests/purescript-sort-imports-tests.el \ + tests/purescript-str-tests.el ELCFILES = $(ELFILES:.el=.elc) AUTOLOADS = purescript-mode-autoloads.el PKG_DIST_FILES = $(ELFILES) logo.svg NEWS purescript-mode.info dir PKG_TAR = purescript-mode-$(VERSION).tar -ELCHECKS=$(addprefix check-, $(ELFILES:.el=)) %.elc: %.el @$(BATCH) \ --eval "(setq byte-compile-error-on-warn t)" -f batch-byte-compile $< -.PHONY: all compile info clean check $(ELCHECKS) elpa package +.PHONY: all compile info clean test elpa package all: compile $(AUTOLOADS) info compile: $(ELCFILES) -$(ELCHECKS): check-%: %.el - @$(BATCH) --eval '(when (check-declare-file "$*.el") (error "check-declare failed"))' - @$(BATCH) \ - --eval "(setq byte-compile-error-on-warn t)" \ - -f batch-byte-compile $*.el - @$(RM) $*.elc - @if [ -f "$(<:%.el=tests/%-tests.el)" ]; then \ - if $(BATCH) --eval "(require 'ert)" 2> /dev/null; then \ - echo; \ - $(BATCH) -l "$(<:%.el=tests/%-tests.el)" -f ert-run-tests-batch-and-exit; \ - else \ - echo "ERT not available, skipping unit tests"; \ - fi; \ - fi - @echo "--" - -check: clean $(ELCHECKS) - @echo "checks passed!" +test: compile + @$(BATCH) -l tests/purescript-sort-imports-tests.elc \ + -l tests/purescript-str-tests.elc \ + -f ert-run-tests-batch-and-exit + @echo "tests passed!" clean: $(RM) $(ELCFILES) $(AUTOLOADS) $(AUTOLOADS:.el=.elc) $(PKG_TAR) purescript-mode.tmp.texi purescript-mode.info dir