Skip to content

Instantly share code, notes, and snippets.

@punitrathore
Created January 20, 2014 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save punitrathore/8516121 to your computer and use it in GitHub Desktop.
Save punitrathore/8516121 to your computer and use it in GitHub Desktop.
clojure-test-mode.el custom functions to navigate to code/test files for Staples Labs(Runa) projects
;; clojure-test mode enhancements to make it work with Runa's
;; convention for paths of test files
;; for example for the ns foo.server.core
;; implementation path: src/foo/server/core.clj
;; test path: test/foo/test/server/core_test.clj
(defun runa-clojure-test-implementation-for (namespace)
"Returns the path of the src file for the given test namespace."
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(segments (split-string namespace "\\."))
(namespace-end (split-string (car (last segments)) "_"))
(namespace-end (mapconcat 'identity (butlast namespace-end 1) "_"))
(impl-segments (append (butlast segments 1) (list namespace-end)))
(runa-impl-segments (cons (first impl-segments) (rest (rest impl-segments)))))
(format "%s/src/%s.clj"
(locate-dominating-file buffer-file-name "src/")
(mapconcat 'identity runa-impl-segments "/"))))
(defun runa-clojure-test-for (namespace)
"Return the path of the test file for the given NAMESPACE."
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(segments (split-string namespace "\\."))
(runa-segments (cons (first segments) (cons "test" (rest segments)))))
(format "%stest/%s_test.clj"
(file-name-as-directory
(locate-dominating-file buffer-file-name "src/"))
(mapconcat 'identity runa-segments "/"))))
(defvar clojure-test-implementation-for-fn 'runa-clojure-test-implementation-for
"Var pointing to the function that will return the full path of the
Clojure src file for the given test namespace.")
(defvar clojure-test-for-fn 'runa-clojure-test-for
"The function that will return the full path of the Clojure test file for the given namespace.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment