Skip to content

Commit a24d3ff

Browse files
committed
Avoid false positives when diffing bitstrings, closes #15204
1 parent b77e65d commit a24d3ff

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/ex_unit/lib/ex_unit/diff.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ defmodule ExUnit.Diff do
157157

158158
## diff_value
159159

160-
defp diff_value(literal, literal, env)
161-
when is_atom(literal) or is_number(literal) or is_reference(literal) or
162-
is_pid(literal) or is_function(literal) do
160+
defp diff_value(literal, literal, env) do
163161
{%__MODULE__{equivalent?: true, left: literal, right: literal}, env}
164162
end
165163

@@ -195,6 +193,9 @@ defmodule ExUnit.Diff do
195193
end
196194

197195
defp diff_value(left, right, env) when is_binary(left) and is_binary(right) do
196+
# We only differ over binaries because it is hard to diff over bitstrings
197+
# cause we don't know where the misaligned bit is. We could compare bit by bit
198+
# but it would be too verbose
198199
diff_string(left, right, ?", env)
199200
end
200201

lib/ex_unit/test/ex_unit/diff_test.exs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,13 @@ defmodule ExUnit.DiffTest do
10341034
)
10351035
end
10361036

1037-
test "strings" do
1037+
test "bitstrings" do
1038+
assert_diff(<<1::1>> == <<1::1>>, [])
1039+
refute_diff(<<1::1>> == <<1::2>>, "-<<1::size(1)>>", "+<<1::size(2)>>+")
1040+
refute_diff(<<1::1>> == <<0::1>>, "-<<1::size(1)>>", "+<<0::size(1)>>+")
1041+
end
1042+
1043+
test "binaries" do
10381044
assert_diff("" = "", [])
10391045
assert_diff("fox hops over the dog" = "fox hops over the dog", [])
10401046

0 commit comments

Comments
 (0)