Skip to content
Gracjan Polak edited this page Jan 12, 2016 · 3 revisions

Tests for haskell-mode reside in tests directory and are divided roughly according to functionality. To run the test suite use the command:

make check

or

make check EMACS=/path/to/your/emacs

As test framework we use Emacs Lisp Regression Testing. A test roughly looks like this:

(ert-deftest haskell-test ()
  (should (equal .. ..))
  (should (not (equal .. ..))
  ...)

To document that a functionality has a known issue waiting for a bugfix use tests that are expected to fail:

(ert-deftest haskell-test ()
  :expected-result :failed
  (should (equal .. ..))
  (should (not (equal .. ..))
  ...)

Notes about tests cases:

  • names of tests must be unique and should be meaningful
  • do not use docstrings as those are not shown when a tests fails
  • the should macro tries to explain what went wrong, make extra sure that in case of test failure reported error message contains necessary information to proceed with fixing
  • tests that are expected to fail are a worthwhile contribution

Mocking and non-pure functionality

To test functionality that touches filesystem we use el-mock.el to mock all the necessary details.

Example:

(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-ghci ()
  (should (equal '("Starting inferior GHCi process ghci ..." "dumses1" nil "nix-shell" "default.nix" "--command" "ghci\\ -ferror-spans")
                 (let ((haskell-process-path-ghci "ghci")
                       (haskell-process-args-ghci '("-ferror-spans")))
                   (custom-set-variables '(haskell-process-wrapper-function
                                           (lambda (argv) (append (list "nix-shell" "default.nix" "--command" )
                                                             (list (shell-quote-argument (mapconcat 'identity argv " ")))))))
                   (mocklet (((haskell-session-name "dummy-session") => "dumses1"))
                     (haskell-process-compute-process-log-and-command "dummy-session" 'ghci))))))

Note the usage of mocklet in the above snippet.