mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-24 18:23:09 +03:00
Make a specific error for too many global errors
This commit is contained in:
parent
791a84410f
commit
f46f3216bb
@ -1153,8 +1153,13 @@ checkErrorsMatch runResult expectedErrors expectedNumberOfErrors errors =
|
||||
|
||||
( [], error_ :: restOfErrors ) ->
|
||||
[ \() ->
|
||||
FailureMessage.tooManyErrors runResult.moduleName (error_ :: restOfErrors)
|
||||
|> Expect.fail
|
||||
if runResult.moduleName == "GLOBAL ERROR" then
|
||||
FailureMessage.tooManyGlobalErrors (error_ :: restOfErrors)
|
||||
|> Expect.fail
|
||||
|
||||
else
|
||||
FailureMessage.tooManyErrors runResult.moduleName (error_ :: restOfErrors)
|
||||
|> Expect.fail
|
||||
]
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@ module Review.Test.FailureMessage exposing
|
||||
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
|
||||
, needToUsedExpectErrorsForModules, missingSources, duplicateModuleName, unknownModulesInExpectedErrors
|
||||
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||
, didNotExpectGlobalErrors, fixedCodeWhitespaceMismatch
|
||||
, didNotExpectGlobalErrors, fixedCodeWhitespaceMismatch, tooManyGlobalErrors
|
||||
)
|
||||
|
||||
{-| Failure messages for the `Review.Test` module.
|
||||
@ -247,6 +247,20 @@ tooManyErrors moduleName extraErrors =
|
||||
)
|
||||
|
||||
|
||||
tooManyGlobalErrors : List ReviewError -> String
|
||||
tooManyGlobalErrors extraErrors =
|
||||
let
|
||||
numberOfErrors : Int
|
||||
numberOfErrors =
|
||||
List.length extraErrors
|
||||
in
|
||||
failureMessage "RULE REPORTED MORE GLOBAL ERRORS THAN EXPECTED"
|
||||
("I found "
|
||||
++ (String.fromInt numberOfErrors ++ " global " ++ pluralizeErrors numberOfErrors ++ " too many:\n\n")
|
||||
++ listErrorMessages extraErrors
|
||||
)
|
||||
|
||||
|
||||
locationNotFound : ReviewError -> String
|
||||
locationNotFound error =
|
||||
failureMessage "COULD NOT FIND LOCATION FOR ERROR"
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Review.Test.FailureMessageTest exposing (all)
|
||||
|
||||
import Elm.Syntax.Range exposing (Range)
|
||||
import Elm.Syntax.Range as Range exposing (Range)
|
||||
import Expect exposing (Expectation)
|
||||
import Review.Error exposing (ReviewError)
|
||||
import Review.Fix as Fix
|
||||
@ -23,6 +23,7 @@ all =
|
||||
, locationNotFoundTest
|
||||
, expectedMoreErrorsTest
|
||||
, tooManyErrorsTest
|
||||
, tooManyGlobalErrorsTest
|
||||
, locationIsAmbiguousInSourceCodeTest
|
||||
, needToUsedExpectErrorsForModulesTest
|
||||
, missingSourcesTest
|
||||
@ -622,6 +623,58 @@ I found 2 errors too many for module `MyOtherModule`:
|
||||
]
|
||||
|
||||
|
||||
tooManyGlobalErrorsTest : Test
|
||||
tooManyGlobalErrorsTest =
|
||||
describe "tooManyGlobalErrors"
|
||||
[ test "with one extra error" <|
|
||||
\() ->
|
||||
let
|
||||
extraErrors : List ReviewError
|
||||
extraErrors =
|
||||
[ Review.Error.error
|
||||
{ message = "Remove the use of `Debug` before shipping to production"
|
||||
, details = [ "Some details about Debug" ]
|
||||
}
|
||||
Range.emptyRange
|
||||
]
|
||||
in
|
||||
FailureMessage.tooManyGlobalErrors extraErrors
|
||||
|> expectMessageEqual """
|
||||
\u{001B}[31m\u{001B}[1mRULE REPORTED MORE GLOBAL ERRORS THAN EXPECTED\u{001B}[22m\u{001B}[39m
|
||||
|
||||
I found 1 global error too many:
|
||||
|
||||
- `Remove the use of `Debug` before shipping to production`
|
||||
"""
|
||||
, test "with multiple extra errors" <|
|
||||
\() ->
|
||||
let
|
||||
extraErrors : List ReviewError
|
||||
extraErrors =
|
||||
[ Review.Error.error
|
||||
{ message = "Remove the use of `Debug` before shipping to production"
|
||||
, details = [ "Some details about Debug" ]
|
||||
}
|
||||
Range.emptyRange
|
||||
, Review.Error.error
|
||||
{ message = "Remove the use of `Debug` before shipping to production"
|
||||
, details = [ "Some details about Debug" ]
|
||||
}
|
||||
Range.emptyRange
|
||||
]
|
||||
in
|
||||
FailureMessage.tooManyGlobalErrors extraErrors
|
||||
|> expectMessageEqual """
|
||||
\u{001B}[31m\u{001B}[1mRULE REPORTED MORE GLOBAL ERRORS THAN EXPECTED\u{001B}[22m\u{001B}[39m
|
||||
|
||||
I found 2 global errors too many:
|
||||
|
||||
- `Remove the use of `Debug` before shipping to production`
|
||||
- `Remove the use of `Debug` before shipping to production`
|
||||
"""
|
||||
]
|
||||
|
||||
|
||||
locationIsAmbiguousInSourceCodeTest : Test
|
||||
locationIsAmbiguousInSourceCodeTest =
|
||||
describe "locationIsAmbiguousInSourceCode"
|
||||
|
Loading…
Reference in New Issue
Block a user