Skip to content

Commit

Permalink
Simplify SARIF test
Browse files Browse the repository at this point in the history
This test was running Credo on Credo and asserting what the first result
was, which is not a good test design as completely unrelated changes to
the code can make the SARIF test fail.

The new design is only slightly better, as it is not yet testing the
structure of the result, but at least it is no longer dependent on
everything else in the project.
  • Loading branch information
rrrene committed Dec 21, 2023
1 parent 5500c28 commit 06168c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 50 deletions.
41 changes: 20 additions & 21 deletions test/fixtures/integration_test_config/.sarif.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@
configs: [
%{
name: "default",
files: %{
included: ["**/space_around_operators.ex"]
},
plugins: [],
requires: [],
strict: false,
parse_timeout: 5000,
color: false,
checks: [
{
Credo.Check.Consistency.ExceptionNames,
files: %{included: "**/*.ex", excluded: "**/clean.ex"}, tags: [:__initial__, :my_tag]
},
{
Credo.Check.Readability.ModuleDoc,
files: %{included: "**/*.ex", excluded: "**/*_redux.ex"}
},
{Credo.Check.Readability.TrailingWhiteSpace,
[
category: :warning,
exit_status: 23,
files: %{excluded: "**/*.ex"},
priority: :high,
tags: [:__initial__, :my_tag]
]}
]
checks: %{
enabled: [
{
Credo.Check.Consistency.ExceptionNames,
files: %{included: "**/*.ex", excluded: "**/clean.ex"}, tags: [:__initial__, :my_tag]
},
{
Credo.Check.Readability.ModuleDoc,
files: %{included: "**/*.ex", excluded: "**/*_redux.ex"}
},
{Credo.Check.Readability.TrailingWhiteSpace,
[
category: :warning,
exit_status: 23,
files: %{excluded: "**/*.ex"},
priority: :high,
tags: [:__initial__, :my_tag]
]}
]
}
}
]
}
34 changes: 5 additions & 29 deletions test/integration/sarif_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ defmodule Credo.SarifTest do

@moduletag timeout: 300_000

@fixture_integration_test_config "test/fixtures/integration_test_config"

test "it should report issues using suggest command (using --format sarif)" do
exec =
IntegrationTest.run([
"suggest",
"--config-file",
"#{@fixture_integration_test_config}/.sarif.exs",
"--format",
"sarif"
])
IntegrationTest.run(
~w[suggest --config-file test/fixtures/integration_test_config/.sarif.exs --format sarif]
)

issues = Credo.Execution.get_issues(exec)

Expand All @@ -38,25 +32,7 @@ defmodule Credo.SarifTest do
rules = first_run["tool"]["driver"]["rules"]
results = first_run["results"]

first_rule = List.first(rules)

assert first_rule["id"] == "EX2004"
assert first_rule["name"] == "Credo.Check.Design.TagFIXME"

assert first_rule["helpUri"] ==
"https://hexdocs.pm/credo/Credo.Check.Design.TagFIXME.html"

assert length(rules) == 4
assert length(results) == 6

first_result = List.first(results)
assert first_result["level"] == "error"
assert first_result["rank"] == 24
assert first_result["ruleId"] == "EX4030"

last_result = Enum.at(results, Enum.count(results) - 1)
assert last_result["level"] == "error"
assert last_result["rank"] == 23
assert last_result["ruleId"] == "EX2004"
assert rules != []
assert results != []
end
end

0 comments on commit 06168c1

Please sign in to comment.