Skip to content

Commit

Permalink
Merge pull request #35 from saffroy/master
Browse files Browse the repository at this point in the history
Add tests for multiline statements, run tests in github workflow
  • Loading branch information
redguardtoo committed Nov 26, 2023
2 parents 3790e01 + fd08ea4 commit ef2cccc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Run tests across emacs versions
on: [push, pull_request]
jobs:
test-emacs-versions:
strategy:
matrix:
emacs-version: [26, 27, 28, 29]
runs-on: ubuntu-latest
container: silex/emacs:${{matrix.emacs-version}}
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install test dependencies
run: ./install-deps.sh
- name: Run tests
run: ./runtests.sh
6 changes: 6 additions & 0 deletions install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -xeu

apt-get update
apt-get install -y nodejs
apt-get clean
9 changes: 9 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -xeu

cd "$(dirname $0)"
emacs -Q --batch \
-l ert \
-l js-comint.el \
-l test-js-comint.el \
-f ert-run-tests-batch-and-exit
44 changes: 44 additions & 0 deletions test-js-comint.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(defun js-comint-test-buffer-matches (regex)
"Search the js-comint buffer for the given regular expression.
Return 't if a match is found, nil otherwise."
(with-current-buffer (js-comint-get-buffer)
(save-excursion
(goto-char (point-min))
(if (re-search-forward regex nil t) t nil))))

(defun js-comint-test-output-matches (input regex)
"Verify that sending INPUT yields output that matches REGEX."

;; Start an instance to run tests on.
(js-comint-reset-repl)

(sit-for 1)

(js-comint-send-string input)

(sit-for 1)

(js-comint-test-buffer-matches regex))

(ert-deftest js-comint-test-multiline-dotchain-line-start ()
"Test multiline statement with dots at beginning of lines."
(should (js-comint-test-output-matches "[1, 2, 3]
.map((it) => it + 1)
.filter((it) => it > 0)
.reduce((prev, curr) => prev + curr, 0);" "^9$")))

(ert-deftest js-comint-test-multiline-dotchain-line-start-dos ()
"Test multiline statement with dots at beginning of lines, with
DOS line separators."
(should (js-comint-test-output-matches "[1, 2, 3]\r
.map((it) => it + 1)\r
.filter((it) => it > 0)\r
.reduce((prev, curr) => prev + curr, 0);\r
" "^9$")))

(ert-deftest js-comint-test-multiline-dotchain-line-end ()
"Test multiline statement with dots at end of lines."
(should (js-comint-test-output-matches "[1, 2, 3].
map((it) => it + 1).
filter((it) => it > 0).
reduce((prev, curr) => prev + curr, 0);" "^9$")))

0 comments on commit ef2cccc

Please sign in to comment.