Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing a function returning boolean

Tags:

clojure

I have possibly the most simple test failing with a rather confusing message for Clojure newbie.

(ns leiningen.booltest
  (:use clojure.test))

(with-test
  (defn bool-function [] 
    (true))

  (is (= (bool-function) true))
)

ERROR in (bool-function) (booltest.clj:10)
expected: (= (bool-function) true)
  actual: java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.IFn
like image 439
Yuriy Zubarev Avatar asked Feb 27 '26 03:02

Yuriy Zubarev


1 Answers

You are calling true as a function: (true) on line 3 of your with-test expression. It should simply be true, without the surrounding parentheses.

You can further simplify your expression, since bool-function already returns true:

 (with-test
      (defn bool-function [] 
        true)
      (is (bool-function)))
like image 97
Michiel Borkent Avatar answered Mar 05 '26 01:03

Michiel Borkent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!