From 22f68ab542f1620876b39874f25b0562320cedc7 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Mon, 1 Mar 2021 22:25:29 +0100 Subject: [PATCH] Add Review.Test.expectGlobalErrors function --- src/Review/Test.elm | 8 +++++++- tests/NoUnsafeRegexFromLiteralTest.elm | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Review/Test.elm b/src/Review/Test.elm index 73d5d3fd..bb14f3c0 100644 --- a/src/Review/Test.elm +++ b/src/Review/Test.elm @@ -1,6 +1,7 @@ module Review.Test exposing ( ReviewResult, run, runWithProjectData, runOnModules, runOnModulesWithProjectData , ExpectedError, expectNoErrors, expectErrors, error, atExactly, whenFixed, expectErrorsForModules, expectErrorsForElmJson, expectErrorsForReadme + , expectGlobalErrors ) {-| Module that helps you test your rules, using [`elm-test`](https://package.elm-lang.org/packages/elm-explorations/test/latest/). @@ -668,7 +669,7 @@ expectErrorsForModules expectedErrorsList reviewResult = maybeUnknownModule = Set.diff (expectedErrorsList |> List.map Tuple.first |> Set.fromList) - (runResults |> List.map .moduleName |> Set.fromList) + (Set.fromList ("GLOBAL ERROR" :: List.map .moduleName runResults)) |> Set.toList |> List.head in @@ -731,6 +732,11 @@ expectErrorsForElmJson expectedErrors reviewResult = expectErrorsForModules [ ( "elm.json", expectedErrors ) ] reviewResult +expectGlobalErrors : List ExpectedError -> ReviewResult -> Expectation +expectGlobalErrors expectedErrors reviewResult = + expectErrorsForModules [ ( "GLOBAL ERROR", expectedErrors ) ] reviewResult + + {-| Assert that the rule reported some errors for the `README.md` file, by specifying which ones. test "report an error when a module is unused" <| diff --git a/tests/NoUnsafeRegexFromLiteralTest.elm b/tests/NoUnsafeRegexFromLiteralTest.elm index d680118a..2ea1170e 100644 --- a/tests/NoUnsafeRegexFromLiteralTest.elm +++ b/tests/NoUnsafeRegexFromLiteralTest.elm @@ -165,7 +165,7 @@ import SomeModule.Regex a = SomeModule.Regex.fromLiteralFunc "^abc$" """ |> Review.Test.runWithProjectData project (rule configuration) - |> Review.Test.expectErrorsForElmJson + |> Review.Test.expectGlobalErrors [ Review.Test.error { message = "Could not find SomeModule.Regex" , details =