Skip to content

Commit f6a6eef

Browse files
leifericfclaude
andcommitted
Allow cross-platform tolerance in visual regression tests
Java2D anti-aliasing produces slightly different results on macOS vs Linux (1-2 channel diff, <0.1% of pixels). Allow max 2 channel diff and <0.1% differing pixels instead of requiring pixel-perfect identity. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f8f5579 commit f6a6eef

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

test/eido/visual_test.clj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@
139139

140140
;; --- tests ---
141141

142+
;; Allow small tolerance for cross-platform anti-aliasing differences.
143+
;; Java2D produces slightly different results on macOS vs Linux due to
144+
;; FPU behavior and font rendering. Max 2 channel diff, <0.1% of pixels.
145+
(def ^:private max-channel-tolerance 2)
146+
(def ^:private max-pixel-diff-pct 0.1)
147+
142148
(deftest visual-regression-test
143149
(doseq [[scene-name scene-fn] test-scenes]
144150
(testing (str "visual regression: " scene-name)
@@ -148,9 +154,15 @@
148154
(str "Reference image missing: " ref-file
149155
". Run (eido.visual-test/regenerate-refs!) to generate."))
150156
(when ref-img
151-
(let [actual (render-scene scene-fn)
152-
result (image-diff ref-img actual)]
153-
(is (:identical? result)
157+
(let [actual (render-scene scene-fn)
158+
result (image-diff ref-img actual)
159+
diff-pct (when (:total-pixels result)
160+
(* 100.0 (/ (:differing-pixels result 0)
161+
(double (:total-pixels result)))))]
162+
(is (or (:identical? result)
163+
(and (<= (:max-channel-diff result) max-channel-tolerance)
164+
(<= diff-pct max-pixel-diff-pct)))
154165
(str scene-name " differs from reference: "
155-
(:differing-pixels result) " pixels differ, "
166+
(:differing-pixels result) " pixels differ ("
167+
(format "%.2f" (or diff-pct 0.0)) "%), "
156168
"max channel diff = " (:max-channel-diff result)))))))))

0 commit comments

Comments
 (0)