Skip to content

Commit

Permalink
Add test reproducing #953
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Feb 24, 2022
1 parent 673656b commit 29859a1
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_enum_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedEnumOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
Enum.map(values, &(&1 + 1))
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_file_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedFileOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
File.stat(values)
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_keyword_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ defmodule Credo.Check.Warning.UnusedKeywordOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
Keyword.take(values, 2)
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_list_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedListOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
List.delete_at(values, 2)
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_path_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ defmodule Credo.Check.Warning.UnusedPathOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
Path.join(values)
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_regex_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedRegexOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
Regex.delete_at(values, 2)
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_string_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ defmodule Credo.Check.Warning.UnusedStringOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
String.to_atom(values)
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/warning/unused_tuple_operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedTupleOperationTest do
|> refute_issues()
end

test "it should NOT report a violation when inside a catch" do
"""
defmodule CredoSampleModule do
defp category_body(nil) do
throw [1, 2, 3, 4]
catch
values ->
Tuple.delete_at(values, 2)
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> refute_issues()
end

test "it should NOT report a violation when inside of assignment" do
"""
defmodule CredoSampleModule do
Expand Down

0 comments on commit 29859a1

Please sign in to comment.