Skip to content

Commit 3c3637c

Browse files
authored
Make --min-cycle-size in mix xref graph inclusive (#14475)
Updates cycle filtering logic to include cycles matching the minimum size. Improves test cases to ensure accurate handling of `min_cycle_size` scenarios. Closes #14474
1 parent eb119df commit 3c3637c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/mix/lib/mix/tasks/xref.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ defmodule Mix.Tasks.Xref do
12131213

12141214
cycles =
12151215
if min = opts[:min_cycle_size] do
1216-
Enum.filter(cycles, &(elem(&1, 0) > min))
1216+
Enum.filter(cycles, &(elem(&1, 0) >= min))
12171217
else
12181218
cycles
12191219
end

lib/mix/test/mix/tasks/xref_test.exs

+15-4
Original file line numberDiff line numberDiff line change
@@ -539,17 +539,28 @@ defmodule Mix.Tasks.XrefTest do
539539
assert_graph(["--format", "cycles", "--fail-above", "0"], """
540540
1 cycles found. Showing them in decreasing size:
541541
542-
Cycle of length 3:
542+
Cycle of length 2:
543543
544-
lib/b.ex
545-
lib/a.ex
544+
lib/a.ex (compile)
546545
lib/b.ex
547546
548547
""")
549548
end
550549
end
551550

552-
test "cycles with min cycle size" do
551+
test "cycles with min_cycle_size matching actual length" do
552+
assert_graph(["--format", "cycles", "--min-cycle-size", "2"], """
553+
1 cycles found. Showing them in decreasing size:
554+
555+
Cycle of length 2:
556+
557+
lib/a.ex (compile)
558+
lib/b.ex
559+
560+
""")
561+
end
562+
563+
test "cycles with min_cycle_size greater than actual length" do
553564
assert_graph(["--format", "cycles", "--min-cycle-size", "3"], """
554565
No cycles found
555566
""")

0 commit comments

Comments
 (0)