簡體   English   中英

單元測試功能elisp

[英]unit testing function elisp

我正在嘗試創建自己的單元測試功能。

;;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)

但是當我運行這段代碼時,我得到了這個錯誤:

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)

一個問題是, multiply-2傳遞給test函數時,您沒有引用它。 將您的調用更改為

(test #'multiply-2 2 4)

接下來,使用funcall正確調用要測試的函數:

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

毛cup是elisp的測試驅動框架。 我認為這是一個更好的選擇。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM