Skip to content

Commit

Permalink
Merge pull request #30 from Hi-Angel/fix-tests
Browse files Browse the repository at this point in the history
Fix tests and implement testing in CI
  • Loading branch information
purcell authored Feb 4, 2025
2 parents e0de552 + 8fc387f commit 433b277
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 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
32 changes: 10 additions & 22 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) \
-f batch-byte-compile $<
--eval "(setq byte-compile-error-on-warn t)" -f batch-byte-compile $(ELFILES)

.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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(ert-deftest single-line ()
(should (with-temp-buffer
(insert "import A\n")
(goto-line 1)
(goto-char (point-min))
(purescript-sort-imports)
(string= (buffer-string)
"import A\n"))))
Expand All @@ -38,7 +38,7 @@
(insert "import A
import B
")
(goto-line 1)
(goto-char (point-min))
(purescript-sort-imports)
(string= (buffer-string)
"import A
Expand All @@ -48,7 +48,7 @@ import B
(insert "import qualified A
import B
")
(goto-line 1)
(goto-char (point-min))
(purescript-sort-imports)
(string= (buffer-string)
"import qualified A
Expand All @@ -58,7 +58,7 @@ import B
(insert "import qualified \"mtl\" A
import B
")
(goto-line 1)
(goto-char (point-min))
(purescript-sort-imports)
(string= (buffer-string)
"import qualified \"mtl\" A
Expand All @@ -70,7 +70,7 @@ import B
(insert "import B
import A
")
(goto-line 1)
(goto-char (point-min))
(purescript-sort-imports)
(string= (buffer-string)
"import A
Expand All @@ -83,7 +83,9 @@ import B
import B
import A
")
(goto-line 2)
;; test at line 2
(goto-char (point-min))
(forward-line 1)
(purescript-sort-imports)
(string= (buffer-string)
"module A where
Expand All @@ -96,7 +98,9 @@ import B
import B
import A
")
(goto-line 3)
;; test at line 3
(goto-char (point-min))
(forward-line 2)
(purescript-sort-imports)
(string= (buffer-string)
"module C where
Expand All @@ -115,7 +119,7 @@ import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
")
(goto-line 1)
(goto-char (point-min))
(purescript-sort-imports)
(string= (buffer-string)
"import Data.Aeson.Encode (encode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; unit tests for purescript-str.el
;; unit tests for purescript-str.el -*- lexical-binding: t -*-

(require 'ert)

Expand Down

0 comments on commit 433b277

Please sign in to comment.