Skip to content

Commit 433b277

Browse files
authored
Merge pull request #30 from Hi-Angel/fix-tests
Fix tests and implement testing in CI
2 parents e0de552 + 8fc387f commit 433b277

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929

3030
- uses: actions/checkout@v2
3131
- name: Run tests
32-
run: make check
32+
run: make test

Makefile

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,31 @@ ELFILES = \
2323
purescript-unicode-input-method.el \
2424
purescript-utils.el \
2525
purescript-decl-scan.el \
26-
purescript-yas.el
26+
purescript-yas.el \
27+
tests/purescript-sort-imports-tests.el \
28+
tests/purescript-str-tests.el
2729

2830
ELCFILES = $(ELFILES:.el=.elc)
2931
AUTOLOADS = purescript-mode-autoloads.el
3032

3133
PKG_DIST_FILES = $(ELFILES) logo.svg NEWS purescript-mode.info dir
3234
PKG_TAR = purescript-mode-$(VERSION).tar
33-
ELCHECKS=$(addprefix check-, $(ELFILES:.el=))
3435

3536
%.elc: %.el
3637
@$(BATCH) \
37-
-f batch-byte-compile $<
38+
--eval "(setq byte-compile-error-on-warn t)" -f batch-byte-compile $(ELFILES)
3839

39-
.PHONY: all compile info clean check $(ELCHECKS) elpa package
40+
.PHONY: all compile info clean test elpa package
4041

4142
all: compile $(AUTOLOADS) info
4243

4344
compile: $(ELCFILES)
4445

45-
$(ELCHECKS): check-%: %.el
46-
@$(BATCH) --eval '(when (check-declare-file "$*.el") (error "check-declare failed"))'
47-
@$(BATCH) \
48-
--eval "(setq byte-compile-error-on-warn t)" \
49-
-f batch-byte-compile $*.el
50-
@$(RM) $*.elc
51-
@if [ -f "$(<:%.el=tests/%-tests.el)" ]; then \
52-
if $(BATCH) --eval "(require 'ert)" 2> /dev/null; then \
53-
echo; \
54-
$(BATCH) -l "$(<:%.el=tests/%-tests.el)" -f ert-run-tests-batch-and-exit; \
55-
else \
56-
echo "ERT not available, skipping unit tests"; \
57-
fi; \
58-
fi
59-
@echo "--"
60-
61-
check: clean $(ELCHECKS)
62-
@echo "checks passed!"
46+
test: compile
47+
@$(BATCH) -l tests/purescript-sort-imports-tests.elc \
48+
-l tests/purescript-str-tests.elc \
49+
-f ert-run-tests-batch-and-exit
50+
@echo "tests passed!"
6351

6452
clean:
6553
$(RM) $(ELCFILES) $(AUTOLOADS) $(AUTOLOADS:.el=.elc) $(PKG_TAR) purescript-mode.tmp.texi purescript-mode.info dir

tests/haskell-sort-imports-tests.el renamed to tests/purescript-sort-imports-tests.el

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
(ert-deftest single-line ()
2929
(should (with-temp-buffer
3030
(insert "import A\n")
31-
(goto-line 1)
31+
(goto-char (point-min))
3232
(purescript-sort-imports)
3333
(string= (buffer-string)
3434
"import A\n"))))
@@ -38,7 +38,7 @@
3838
(insert "import A
3939
import B
4040
")
41-
(goto-line 1)
41+
(goto-char (point-min))
4242
(purescript-sort-imports)
4343
(string= (buffer-string)
4444
"import A
@@ -48,7 +48,7 @@ import B
4848
(insert "import qualified A
4949
import B
5050
")
51-
(goto-line 1)
51+
(goto-char (point-min))
5252
(purescript-sort-imports)
5353
(string= (buffer-string)
5454
"import qualified A
@@ -58,7 +58,7 @@ import B
5858
(insert "import qualified \"mtl\" A
5959
import B
6060
")
61-
(goto-line 1)
61+
(goto-char (point-min))
6262
(purescript-sort-imports)
6363
(string= (buffer-string)
6464
"import qualified \"mtl\" A
@@ -70,7 +70,7 @@ import B
7070
(insert "import B
7171
import A
7272
")
73-
(goto-line 1)
73+
(goto-char (point-min))
7474
(purescript-sort-imports)
7575
(string= (buffer-string)
7676
"import A
@@ -83,7 +83,9 @@ import B
8383
import B
8484
import A
8585
")
86-
(goto-line 2)
86+
;; test at line 2
87+
(goto-char (point-min))
88+
(forward-line 1)
8789
(purescript-sort-imports)
8890
(string= (buffer-string)
8991
"module A where
@@ -96,7 +98,9 @@ import B
9698
import B
9799
import A
98100
")
99-
(goto-line 3)
101+
;; test at line 3
102+
(goto-char (point-min))
103+
(forward-line 2)
100104
(purescript-sort-imports)
101105
(string= (buffer-string)
102106
"module C where
@@ -115,7 +119,7 @@ import Data.Aeson.Parser.Internal (decodeWith, decodeStrictWith,
115119
import qualified Data.ByteString as B
116120
import qualified Data.ByteString.Lazy as L
117121
")
118-
(goto-line 1)
122+
(goto-char (point-min))
119123
(purescript-sort-imports)
120124
(string= (buffer-string)
121125
"import Data.Aeson.Encode (encode)

tests/haskell-str-tests.el renamed to tests/purescript-str-tests.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; unit tests for purescript-str.el
1+
;; unit tests for purescript-str.el -*- lexical-binding: t -*-
22

33
(require 'ert)
44

0 commit comments

Comments
 (0)