19 Aug 2008 (Tue)

06:15:40 # Life Running a unittest in C, for emacs, the simplest way. I was looking at running a functional unittest for C, and there are so many tools available. I wrote a little emacs script which runs test_FILENAME.c via binfmtc in compile-mode, and running tests using good-old assert() macros. 'assert' macro output has the program name, which is the same as the C source file name when running binfmtc, and emacs compile mode doesn't like that. Hmmm.. and I found that auto-compile.el seems to do most of what I wanted, a little different manner.

./test_ilistcreate.c
test_ilistcreate.c: test_ilistcreate.c:15: main: Assertion `0' failed.
	

So, how does this look like?

(defun dancer-test-run-c () 
  "run test program for current buffer, for C language"
  (interactive)
  (let* ((compilation-error-regexp-alist
	  '(("\\([^:]+\\): \\([^:]+\\):\\([0-9]+\\):"
			   2 3 nil))))
    (compile (concat "./test_" (file-name-nondirectory buffer-file-name)))))

(add-hook
 'c-mode-hook
 '(lambda () 
    (progn (local-set-key "\C-c\C-c" 
			  'dancer-test-run-c))))
(add-hook
 'c++-mode-hook
 '(lambda () 
    (progn (local-set-key "\C-c\C-c" 
			  'dancer-test-run-c))))
	
Junichi Uekawa

$Id: dancer-diary.el,v 1.92 2007/08/30 21:46:09 dancer Exp $