[EMAIL PROTECTED] wrote:
Subject: [OT] Buffer loading magic?
From: "James Higginbotham" <[EMAIL PROTECTED]>
Date: Wed, 30 Oct 2002 17:22:05 -0600

Can someone point me to something that would allow me to toggle between the source and unit test for a class, if my directory structure is usually something like:

src
com
mycompany
foo
Bar.java
test
com
mycompany
foo
BarTest.java

�and my tests always end in 'Test.java'?

Just wondering if someone has done this or something similar. If found an elisp snippet for C to header, but that assumes the same dir and I'm not elisp literate enough to determine how best to mod the code.
Here's what I use on xemacs. I can't remember if I wrote these or if I based them on code posted here...


;; Swap between file in src hierarchy and matching one in test hierarchy
(defun jde-swap-testsrc-file()
"Swaps between test and code source files."
(interactive)
(find-file (jde-get-swap-testsrc-file)))
(defun jde-get-swap-testsrc-file()
"Gets the swapped source file name for unit test vs code files."
(if (string-match "/src/" (buffer-file-name))
(simple-replace-in-string (simple-replace-in-string (buffer-file-name) "/src/" "/test/") ".java$" "Test.java")
(simple-replace-in-string (simple-replace-in-string (buffer-file-name) "/test/" "/src/") "Test.java$" ".java")
))
(defun simple-replace-in-string (str oldtext newtext)
"Replace all matches in STR for OLDTEXT with NEWTEXT string,
and returns the new string."
(setq index (string-match oldtext str))
(if index
(concat (substring str 0 index)
newtext
(if (< (+ (length oldtext) index) (length str))
(substring str (+ (length oldtext) index))
"")
)
str)
)


I also have the following functions for running the unit tests corresponding to the current class, or the AllTests for running the package tests.

;; JUnit extension for JDE
(defun jde-run-test-class()
"Runs the corresponding test class that belongs to the current buffer,
in a buffer, piping output from the program to the buffer and
input from the buffer to the program."
(interactive)
(let ((vm (jde-run-get-vm)))
(oset vm :main-class (jde-run-get-test-class))
(jde-run-vm-launch vm)))

(defun jde-run-get-test-class()
"Gets the test class for the current buffer"
(let ((test-class (jde-run-get-main-class)))
(if (string-match ".*Tests?$" (jde-run-get-main-class))
(setq test-class (jde-run-get-main-class))
(setq test-class
(concat (jde-db-get-package)
(file-name-sans-extension
(file-name-nondirectory (buffer-file-name)))
"Test"
)))
test-class))

(defun jde-run-package-test-class()
"Runs the corresponding test class that belongs to the package of the current
buffer, piping output from the program to the buffer and
input from the buffer to the program."
(interactive)
(let ((vm (jde-run-get-vm)))
(oset vm :main-class (jde-run-get-package-test-class))
(jde-run-vm-launch vm)))

(defun jde-run-get-package-test-class()
"Gets the package test class for the current buffer"
(let ((package-test-class (concat (jde-db-get-package) "AllTests")))
package-test-class))




Reply via email to