       (concat dir file)
     (concat dir "/" file)))
 
+;;; Get info about the most recent running of EUnit
+(defun erlang-eunit-recent (key)
+  (cdr (assq key erlang-eunit-recent-info)))
+
+;;; Record info about the most recent running of EUnit
+;;; Known modes are 'module-mode and 'test-mode
+(defun erlang-eunit-record-recent (mode module test)
+  (setq erlang-eunit-recent-info (pairlis '(mode module test cover)
+                                          (list mode module test
+                                                (erlang-eunit-recent 'cover)))))
+
+;;; Record whether the most recent running of EUnit included cover
+;;; compilation
+(defun erlang-eunit-record-recent-compile (under-cover)
+  (setcdr (assq 'cover erlang-eunit-recent-info) under-cover))
+
 ;;; Determine options for EUnit.
 (defun erlang-eunit-opts ()
   (if current-prefix-arg ", [verbose]" ""))
 
 ;;; Determine current test function
-(defun erlang-eunit-test-name ()
+(defun erlang-eunit-current-test ()
   (save-excursion
     (erlang-end-of-function 1)
     (erlang-beginning-of-function 1)

(defun erlang-eunit-test-generator-p (test-name)
  (if (erlang-eunit-string-match-p "^\\(.+\\)_test_$" test-name) t nil))

;;; Run the current EUnit test
(defun erlang-eunit-run-current-test ()
  (let* ((module-name (erlang-add-quotes-if-needed
                       (erlang-eunit-module-name buffer-file-name)))
         (test-name (erlang-eunit-test-name))
         (command
          (cond ((erlang-eunit-simple-test-p test-name)
                 (format "eunit:test({%s, %s}%s)."
                         module-name test-name (erlang-eunit-opts)))
                ((erlang-eunit-test-generator-p test-name)
                 (format "eunit:test({generator, %s, %s}%s)."
                         module-name test-name (erlang-eunit-opts)))
                (t
                 (format "%% WARNING: '%s' is not a test function"
                         test-name)))))
    (erlang-eunit-inferior-erlang-send-command command)))

;;; Run EUnit tests for the current module
(defun erlang-eunit-run-module-tests ()
  (let* ((module-name (erlang-add-quotes-if-needed
                       (erlang-eunit-source-module-name buffer-file-name)))
         (command (format "eunit:test(%s%s)." module-name (erlang-eunit-opts))))
    (erlang-eunit-inferior-erlang-send-command command)))

(defun erlang-eunit-cover-compile ()
  "Cover compile current module."

  "*Set to non-nil to automtically save unsaved buffers before running tests.
This is useful, reducing the save-compile-load-test cycle to one keychord.")

(defvar erlang-eunit-recent-info '((mode . nil) (module . nil) (test . nil) (cover . nil))
  "Info about the most recent running of an EUnit test representation.")

;;;
;;; Switch between src/EUnit test buffers
;;;
