mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-25 10:41:47 +03:00
Give a nicer error message in tests when the location could not be found
This commit is contained in:
parent
e00ab39cd7
commit
b72326085b
@ -879,11 +879,8 @@ checkMessageAppearsUnder codeInspector error_ (ExpectedError expectedError) =
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
-- TODO Fail with a more precise error message
|
||||
-- This is actually quite easy to create. We can enter this here by
|
||||
-- having the location be
|
||||
-- { start = { row = 0, column = 0 }, end = { row = 0, column = 0 } }
|
||||
Expect.fail ErrorMessage.impossibleState
|
||||
ErrorMessage.locationNotFound error_
|
||||
|> Expect.fail
|
||||
|> always
|
||||
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
module Review.Test.ErrorMessage exposing
|
||||
( ExpectedErrorData
|
||||
, parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
||||
, underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode
|
||||
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, locationIsAmbiguousInSourceCode
|
||||
, needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||
, impossibleState
|
||||
)
|
||||
|
||||
{-| Error messages for the `Review.Test` module.
|
||||
@ -14,10 +13,9 @@ module Review.Test.ErrorMessage exposing
|
||||
|
||||
@docs ExpectedErrorData
|
||||
@docs parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
||||
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode
|
||||
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, locationIsAmbiguousInSourceCode
|
||||
@docs needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||
@docs impossibleState
|
||||
|
||||
-}
|
||||
|
||||
@ -218,6 +216,22 @@ I found """
|
||||
++ listErrorMessagesAndPositions extraErrors
|
||||
|
||||
|
||||
locationNotFound : Error -> String
|
||||
locationNotFound error =
|
||||
"""COULD NOT FIND LOCATION FOR ERROR
|
||||
|
||||
I was looking for the error with the following message:
|
||||
|
||||
""" ++ wrapInQuotes (Rule.errorMessage error) ++ """
|
||||
|
||||
and I found it, but the code it points to does not lead to anything:
|
||||
|
||||
""" ++ rangeAsString (Rule.errorRange error) ++ """
|
||||
|
||||
Please try to have the error under the smallest region that makes sense.
|
||||
This will be the most helpful for the person who reads the error message."""
|
||||
|
||||
|
||||
locationIsAmbiguousInSourceCode : SourceCode -> Error -> String -> List Int -> String
|
||||
locationIsAmbiguousInSourceCode sourceCode error under occurrencesInSourceCode =
|
||||
"""AMBIGUOUS ERROR LOCATION
|
||||
@ -289,13 +303,6 @@ match the names of the modules in the test source codes to the ones in the
|
||||
expected errors list."""
|
||||
|
||||
|
||||
impossibleState : String
|
||||
impossibleState =
|
||||
"""ELM-REVIEW IMPOSSIBLE STATE
|
||||
|
||||
Oh no! I'm in an impossible state! I found an error at a location that I could not trace back. Please let me know and give me an SSCCE (http://sscce.org/) here: https://github.com/jfmengels/elm-review/issues."""
|
||||
|
||||
|
||||
missingFixes : ExpectedErrorData -> String
|
||||
missingFixes expectedError =
|
||||
"""MISSING FIXES
|
||||
|
@ -18,6 +18,7 @@ all =
|
||||
, unexpectedDetailsTest
|
||||
, emptyDetailsTest
|
||||
, wrongLocationTest
|
||||
, locationNotFoundTest
|
||||
, expectedMoreErrorsTest
|
||||
, tooManyErrorsTest
|
||||
, locationIsAmbiguousInSourceCodeTest
|
||||
@ -427,6 +428,36 @@ but I found it at:
|
||||
]
|
||||
|
||||
|
||||
locationNotFoundTest : Test
|
||||
locationNotFoundTest =
|
||||
test "locationNotFound" <|
|
||||
\() ->
|
||||
let
|
||||
error : Error
|
||||
error =
|
||||
Rule.error
|
||||
{ message = "Some error"
|
||||
, details = [ "Some details" ]
|
||||
}
|
||||
{ start = { row = 0, column = 0 }, end = { row = 0, column = 0 } }
|
||||
in
|
||||
ErrorMessage.locationNotFound error
|
||||
|> expectMessageEqual """
|
||||
COULD NOT FIND LOCATION FOR ERROR
|
||||
|
||||
I was looking for the error with the following message:
|
||||
|
||||
`Some error`
|
||||
|
||||
and I found it, but the code it points to does not lead to anything:
|
||||
|
||||
{ start = { row = 0, column = 0 }, end = { row = 0, column = 0 } }
|
||||
|
||||
Please try to have the error under the smallest region that makes sense.
|
||||
This will be the most helpful for the person who reads the error message.
|
||||
"""
|
||||
|
||||
|
||||
expectedMoreErrorsTest : Test
|
||||
expectedMoreErrorsTest =
|
||||
test "expectedMoreErrors" <|
|
||||
|
Loading…
Reference in New Issue
Block a user