Skip to content

Add tests for clojure.core/identity#907

Open
brandoncorrea wants to merge 1 commit into
jank-lang:mainfrom
brandoncorrea:identity
Open

Add tests for clojure.core/identity#907
brandoncorrea wants to merge 1 commit into
jank-lang:mainfrom
brandoncorrea:identity

Conversation

@brandoncorrea

Copy link
Copy Markdown

Closes #305.

is vs are

As commented in the code, some dialects seem to evaluate are parameters more than once, which is problematic for object equality. Test values are declared eagerly and tested using doseq / is instead.

##NaN

It turns out that most dialects don't consider ##NaN to be = or identical? to itself. This case is tested separately with NaN?.

@CLAassistant

CLAassistant commented Jun 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

(deftest test-identity
(is (NaN? (identity ##NaN)))
(doseq [value test-vals]
(is (identical? value (identity value))))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put the value or the type of value as the docstring for the assertion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on second thought, i don't know if that's required...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to add docstrings, but my hope is that failing assertion will document the value in the terminal output.

[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

; Values for tests are declared eagerly, instead of using
; clojure.test/are. Some dialects evaluate `are` params more

@jasalt jasalt Jun 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, where exactly closure.test/are behaves oddly like that? Questioning why that wouldn’t be considered a bug to fix in a dialect (ticket could be linked here).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it seems all supported dialects fail the same way in these scenarios: jvm, cljs, cljr, bb, lpy, and phel.

; fails with different object references
(deftest atoms-are=
  (are [x] (= x x)
    (atom nil)))

; fails with 3 instead of 1 (x referenced 3 times in do block)
(deftest increment-atom
  (let [counter (atom 0)]
    (are [x] (do x x x)
      (swap! counter inc))
    (is (= 1 @counter))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clojure.core/identity

4 participants