Skip to content

Commit

Permalink
Implement testing with existing tests
Browse files Browse the repository at this point in the history
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 |
  • Loading branch information
Hi-Angel committed Dec 10, 2024
1 parent eae0f4a commit 8536ea5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:

- uses: actions/checkout@v2
- name: Run tests
run: make check
run: make test
30 changes: 9 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8536ea5

Please sign in to comment.