diff --git a/lib/mix/lib/mix/tasks/xref.ex b/lib/mix/lib/mix/tasks/xref.ex index 07d516cc92..b54f912979 100644 --- a/lib/mix/lib/mix/tasks/xref.ex +++ b/lib/mix/lib/mix/tasks/xref.ex @@ -1213,7 +1213,7 @@ defmodule Mix.Tasks.Xref do cycles = if min = opts[:min_cycle_size] do - Enum.filter(cycles, &(elem(&1, 0) > min)) + Enum.filter(cycles, &(elem(&1, 0) >= min)) else cycles end diff --git a/lib/mix/test/mix/tasks/xref_test.exs b/lib/mix/test/mix/tasks/xref_test.exs index 7c1ac6ebf2..7ffcdbf779 100644 --- a/lib/mix/test/mix/tasks/xref_test.exs +++ b/lib/mix/test/mix/tasks/xref_test.exs @@ -539,17 +539,28 @@ defmodule Mix.Tasks.XrefTest do assert_graph(["--format", "cycles", "--fail-above", "0"], """ 1 cycles found. Showing them in decreasing size: - Cycle of length 3: + Cycle of length 2: - lib/b.ex - lib/a.ex + lib/a.ex (compile) lib/b.ex """) end end - test "cycles with min cycle size" do + test "cycles with min_cycle_size matching actual length" do + assert_graph(["--format", "cycles", "--min-cycle-size", "2"], """ + 1 cycles found. Showing them in decreasing size: + + Cycle of length 2: + + lib/a.ex (compile) + lib/b.ex + + """) + end + + test "cycles with min_cycle_size greater than actual length" do assert_graph(["--format", "cycles", "--min-cycle-size", "3"], """ No cycles found """)