dtostes
dtostes

Reputation: 113

unit testing function elisp

I am trying to create my own unit test function.

;;function
(defun multiply-2 (number)
   (* 2 number))


;;test function
(defun test (function parameters result)
(with-output-to-temp-buffer "tests"
     (progn
     (if (equal (#'function parameters) result) (print "teste ok") (print "fail"))
     )))

;;using test function
(test multiply-2 2 4)

But when i run this code i am getting this error:

Debugger entered--Lisp error: (void-variable multiply-2)
  (test multiply-2 2 4)
  eval((test multiply-2 2 4) nil)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)

Upvotes: 0

Views: 209

Answers (2)

Aborn Jiang
Aborn Jiang

Reputation: 1059

buttercup is test-driven framework for elisp. I think it's a better choice.

Upvotes: 0

Steve Vinoski
Steve Vinoski

Reputation: 20024

One problem is that you're not quoting multiply-2 when you pass it to the test function. Change your invocation to

(test #'multiply-2 2 4)

Next, use funcall to properly invoke the function to be tested:

(if (equal (funcall function parameters) result)
    (print "test ok")
  (print "fail"))

Upvotes: 1

Related Questions