Skip to content

Commit 6ef7410

Browse files
authored
Merge pull request cloverage#299 from jameslintaylor/master
Fix multiple evaluations of coll during instrumentation
2 parents 03363d1 + 98de21b commit 6ef7410

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cloverage/src/cloverage/instrument.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
(throw+ (str "Can't construct empty " (class form))))
262262
`(into ~(empty form) [] ~(vec wrappee))))]
263263
(d/tprn ":wrapped" (class form) (class wrapped) wrapped)
264-
(f line (add-original form wrapped))))
264+
(f line (vary-meta wrapped merge (meta form)))))
265265

266266
(defn wrap-fn-body [f line form]
267267
(let [fn-sym (first form)

cloverage/test/cloverage/instrument_test.clj

+9
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@
180180
form))]
181181
(t/is (:preserved? (meta instrumented)))))
182182

183+
(def test-coll-is-evaluated-once-count
184+
"This needs to be reachable from global scope."
185+
(atom 0))
186+
187+
(t/deftest test-coll-is-evaluated-once
188+
(reset! test-coll-is-evaluated-once-count 0)
189+
(inst/instrument-form #'inst/no-instr nil `{:foo (swap! test-coll-is-evaluated-once-count inc)})
190+
(t/is (= 1 @test-coll-is-evaluated-once-count)))
191+
183192
(t/deftest fail-gracefully-when-instrumenting
184193
(t/testing "If instrumenting a form fails we should log an Exception and continue instead of failing entirely."
185194
(let [form '(this-function-does-not-exist 100)

0 commit comments

Comments
 (0)