 ;; Keywords: languages go test
 ;; URL: https://github.com/yauhenl/gotn.el
 
+;;; Commentary:
 ;;; Code:
 
+(require 'compile)
+
+(add-to-list 'compilation-error-regexp-alist '("\\([a-zA-Z0-9_]+\\.go\\):\\([0-9]+\\)" 1 2))
+
 (defcustom go-test-case-command "go test -v -run"
-  "The 'godef' command."
+  "The command to run test case."
   :type 'string
   :group 'gotn)
+
+(defcustom go-test-package-command "go test -v ."
+  "The command to run tests of current pacakge."
+  :type 'string
+  :group 'gotn)
+
+(defcustom go-test-package-test-fallback t
+  "Whether no test case under position run all package tests."
+  :type 'boolean
+  :group 'gotn)
+
+(defun gotn--compilation-name (mode-name)
+  "Name of the go test.  MODE-NAME is unused."
+  "*Go test*")
+
+(defun gotn--run-test-as-compilation (cmd)
+  "Run CMD in gotn-mode."
+  (compilation-start cmd
+                     'gotn-mode
+                     'gotn--compilation-name))
+
+
+(defun gotn-run-test-package ()
+  "Run go test of current package."
+  (interactive "d")
+  (gotn--run-test-as-compilation go-test-package-command))
 
 (defun gotn-run-test (point)
   "Run go test at POINT."

          (list 1 (substring out 0 -1))
        (list 0 out)))))

(provide 'gotn)

;;; gotn.el ends here

  (condition-case nil
      (let ((gotn-out (gotn--call point)))
        (if (= (car gotn-out) 0)
            (gotn--run-test-as-compilation (concat go-test-case-command " ^" (car (cdr gotn-out)) "$"))
          (if go-test-package-test-fallback
              (gotn--run-test-as-compilation go-test-package-command)
            (message (format "Could not run gotn binary: %s" (cdr gotn-out))))))))

(defun gotn--call (point)
  "Call `gotn' to get test name at POINT."
