From 721e7d0a32ad30d5b8b9fe114a60c8b19c0524a7 Mon Sep 17 00:00:00 2001 From: ikappaki Date: Thu, 24 Aug 2023 19:49:07 +0100 Subject: [PATCH] Evalue (is (= exp act)) only once when failing the equality test --- CHANGELOG.md | 1 + src/basilisp/test.lpy | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06dbd58f3..99069bf6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix incompatibility with `(str nil)` returning "nil" (#706). * Fix `sort-by` support for maps and boolean comparator fns (#709). * Fix `sort` support for maps and boolean comparator fns (#711). + * Fix `(is (= exp act))` should only evaluate its args once on failure (#712). ## [v0.1.0a2] ### Added diff --git a/src/basilisp/test.lpy b/src/basilisp/test.lpy index 5d7d1af9f..13ff13963 100644 --- a/src/basilisp/test.lpy +++ b/src/basilisp/test.lpy @@ -78,17 +78,19 @@ (defmethod gen-assert '= [expr msg line-num] - `(when-not ~expr - (vswap! *test-failures* - conj - {:test-name *test-name* - :test-section *test-section* - :message ~msg - :expr (quote ~expr) - :actual ~(nth expr 2) - :expected ~(second expr) - :line ~line-num - :type :failure}))) + `(let [actual# ~(nth expr 2) + expected# ~(second expr)] + (when-not (= expected# actual#) + (vswap! *test-failures* + conj + {:test-name *test-name* + :test-section *test-section* + :message ~msg + :expr (quote ~expr) + :actual actual# + :expected expected# + :line ~line-num + :type :failure})))) (defmethod gen-assert 'thrown? [expr msg line-num]