branch: elpa/haskell-tng-mode commit 374835c822a31a3c574d0cd3208951f1c4c58501 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
a test for interactive commands --- haskell-tng-hsinspect.el | 17 ++++++---- test/haskell-tng-dynamic-test.el | 44 +++++++++++++++++++++++++ test/haskell-tng-hsinspect-test.el | 2 -- test/src/hsinspect.hs | 6 ++-- test/src/{hsinspect.hs => hsinspect.hs.dynamic} | 6 ++-- 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el index 2855132..a44f422 100644 --- a/haskell-tng-hsinspect.el +++ b/haskell-tng-hsinspect.el @@ -431,14 +431,17 @@ Does not persist the cache changes to disk." (append haskell-tng--hsinspect-imports updates)))) ;; TODO add a package-wide variable cache +(defvar-local haskell-tng--hsinspect-index nil) (defun haskell-tng--hsinspect-index (&optional flush-cache) - (when-let (ghcflags-dir - (locate-dominating-file default-directory ".ghc.flags")) - (haskell-tng--util-cached-disk - (lambda () (haskell-tng--hsinspect flush-cache "index")) - (concat "hsinspect-0.0.7" (expand-file-name ghcflags-dir) "index") - nil - flush-cache))) + (or ;; this variable cache is only used in tests + haskell-tng--hsinspect-index + (when-let (ghcflags-dir + (locate-dominating-file default-directory ".ghc.flags")) + (haskell-tng--util-cached-disk + (lambda () (haskell-tng--hsinspect flush-cache "index")) + (concat "hsinspect-0.0.7" (expand-file-name ghcflags-dir) "index") + nil + flush-cache)))) ;; TODO add a project-wide variable cache (defun haskell-tng--hsinspect-exe (&optional flush-cache) diff --git a/test/haskell-tng-dynamic-test.el b/test/haskell-tng-dynamic-test.el new file mode 100644 index 0000000..8da74d3 --- /dev/null +++ b/test/haskell-tng-dynamic-test.el @@ -0,0 +1,44 @@ +;;; haskell-tng-dynamic-test.el --- tests that run dynamic commands -*- lexical-binding: t -*- + +;; Copyright (C) 2020 Tseen She +;; License: GPL 3 or any later version + +;;; Commentary: +;; +;; These tests load a user-file and search for comments containing dynamic +;; interactive commands, simulating user input, which are then compared to a +;; file on disk containing the expected output. +;; +;;; Code: + +(require 'ert) +(require 's) + +(require 'haskell-tng-mode) + +(require 'haskell-tng-testutils + "test/haskell-tng-testutils.el") + +(ert-deftest haskell-tng-dynamic-file-tests () + (should (have-expected-dynamic-output (testdata "src/hsinspect.hs")))) + +(defun have-expected-dynamic-output (file) + (haskell-tng--testutils-assert-file-contents + file + #'haskell-tng-mode + #'haskell-tng-dynamic-test-to-string + "dynamic")) + +(defun haskell-tng-dynamic-test-to-string () + (goto-char (point-min)) + + (while (re-search-forward (rx word-start "RUN" word-end) nil t) + (when (is-comment-at-point) + (let ((start (point)) + (command (read (current-buffer)))) + (eval command) + (goto-char start)))) + (buffer-substring-no-properties (point-min) (point-max))) + +(provide 'haskell-tng-dynamic-test) +;;; haskell-tng-dynamic-test.el ends here diff --git a/test/haskell-tng-hsinspect-test.el b/test/haskell-tng-hsinspect-test.el index a4653f6..9a17cda 100644 --- a/test/haskell-tng-hsinspect-test.el +++ b/test/haskell-tng-hsinspect-test.el @@ -11,8 +11,6 @@ (require 'haskell-tng-testutils "test/haskell-tng-testutils.el") -;; TODO tests of the user facing functions in the golden data format - (ert-deftest haskell-tng-hsinspect-test-qualify-latest () (let ((imports (haskell-tng--util-read diff --git a/test/src/hsinspect.hs b/test/src/hsinspect.hs index 39631a1..906f760 100644 --- a/test/src/hsinspect.hs +++ b/test/src/hsinspect.hs @@ -1,11 +1,13 @@ --- IMPORTS "../data/hsinspect-0.0.8-imports.sexp.gz" --- INDEX "../data/hsinspect-0.0.9-index.sexp.gz" +-- RUN (setq haskell-tng--hsinspect-imports (haskell-tng--util-read "test/data/hsinspect-0.0.8-imports.sexp.gz")) +-- +-- RUN (setq haskell-tng--hsinspect-index (haskell-tng--util-read "test/data/hsinspect-0.0.9-index.sexp.gz")) module Medley.Wibble where import Data.Functor.Contravariant as C import Medley.Wobble import Prelude (zip) +-- FIXME commands -- COMPLETE 11 foo = C.pha diff --git a/test/src/hsinspect.hs b/test/src/hsinspect.hs.dynamic similarity index 63% copy from test/src/hsinspect.hs copy to test/src/hsinspect.hs.dynamic index 39631a1..906f760 100644 --- a/test/src/hsinspect.hs +++ b/test/src/hsinspect.hs.dynamic @@ -1,11 +1,13 @@ --- IMPORTS "../data/hsinspect-0.0.8-imports.sexp.gz" --- INDEX "../data/hsinspect-0.0.9-index.sexp.gz" +-- RUN (setq haskell-tng--hsinspect-imports (haskell-tng--util-read "test/data/hsinspect-0.0.8-imports.sexp.gz")) +-- +-- RUN (setq haskell-tng--hsinspect-index (haskell-tng--util-read "test/data/hsinspect-0.0.9-index.sexp.gz")) module Medley.Wibble where import Data.Functor.Contravariant as C import Medley.Wobble import Prelude (zip) +-- FIXME commands -- COMPLETE 11 foo = C.pha