diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..28a94b3 --- /dev/null +++ b/.github/workflows/actions.yml @@ -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 diff --git a/install-deps.sh b/install-deps.sh new file mode 100755 index 0000000..7d8faf7 --- /dev/null +++ b/install-deps.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -xeu + +apt-get update +apt-get install -y nodejs +apt-get clean diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..58e9b85 --- /dev/null +++ b/runtests.sh @@ -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 diff --git a/test-js-comint.el b/test-js-comint.el new file mode 100644 index 0000000..e89adf9 --- /dev/null +++ b/test-js-comint.el @@ -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$")))