Search code examples
emacselispemacs-buttercup

Generating tests in emacs buttercup


I have a emacs buttercup tests:

(describe
"Test"
(defun test-some (test-string actual expected)
  (let ((act actual) (exp expected))
    (it test-string
        (expect act
                :to-equal
                exp))))

(test-some
  "should be equal"
  1
  1))

However, it gives me

Test should be equal
error: (void-variable act)

when executed. The string is there, so at least the test-string is passed correctly. However, there seems to be a problem with the other arguments.

Relevant section in the manual: https://github.com/jorgenschaefer/emacs-buttercup/#its-just-functions


Solution

  • Example function:

    (cl-defun indent-and-compare (test-string file-name &key (uncompleted-indent 4))
      (lexical-let ((act (concat file-name "-actual.nim")) (exp (concat file-name "-expected.nim"))
                    (indent uncompleted-indent))
        (it test-string
            (setq nim-uncompleted-condition-indent indent)
            (insert-file-contents-literally act)
            (indent-region (point-min) (point-max))
    
            (expect (buffer-string)
                    :to-equal
                    (file-to-string exp)))))
    

    Via https://github.com/nim-lang/nim-mode/blob/ada2f827507397a8f20587af7c07d4de26e96394/tests/test-indent.el#L10-L20