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 ->
|
Nothing ->
|
||||||
-- TODO Fail with a more precise error message
|
ErrorMessage.locationNotFound error_
|
||||||
-- This is actually quite easy to create. We can enter this here by
|
|> Expect.fail
|
||||||
-- having the location be
|
|
||||||
-- { start = { row = 0, column = 0 }, end = { row = 0, column = 0 } }
|
|
||||||
Expect.fail ErrorMessage.impossibleState
|
|
||||||
|> always
|
|> always
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
module Review.Test.ErrorMessage exposing
|
module Review.Test.ErrorMessage exposing
|
||||||
( ExpectedErrorData
|
( ExpectedErrorData
|
||||||
, parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
, parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
||||||
, underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode
|
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, locationIsAmbiguousInSourceCode
|
||||||
, needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
, needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||||
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||||
, impossibleState
|
|
||||||
)
|
)
|
||||||
|
|
||||||
{-| Error messages for the `Review.Test` module.
|
{-| Error messages for the `Review.Test` module.
|
||||||
@ -14,10 +13,9 @@ module Review.Test.ErrorMessage exposing
|
|||||||
|
|
||||||
@docs ExpectedErrorData
|
@docs ExpectedErrorData
|
||||||
@docs parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
@docs parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
||||||
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode
|
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, locationIsAmbiguousInSourceCode
|
||||||
@docs needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
@docs needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||||
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||||
@docs impossibleState
|
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
@ -218,6 +216,22 @@ I found """
|
|||||||
++ listErrorMessagesAndPositions extraErrors
|
++ 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 -> String -> List Int -> String
|
||||||
locationIsAmbiguousInSourceCode sourceCode error under occurrencesInSourceCode =
|
locationIsAmbiguousInSourceCode sourceCode error under occurrencesInSourceCode =
|
||||||
"""AMBIGUOUS ERROR LOCATION
|
"""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."""
|
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 : ExpectedErrorData -> String
|
||||||
missingFixes expectedError =
|
missingFixes expectedError =
|
||||||
"""MISSING FIXES
|
"""MISSING FIXES
|
||||||
|
@ -18,6 +18,7 @@ all =
|
|||||||
, unexpectedDetailsTest
|
, unexpectedDetailsTest
|
||||||
, emptyDetailsTest
|
, emptyDetailsTest
|
||||||
, wrongLocationTest
|
, wrongLocationTest
|
||||||
|
, locationNotFoundTest
|
||||||
, expectedMoreErrorsTest
|
, expectedMoreErrorsTest
|
||||||
, tooManyErrorsTest
|
, tooManyErrorsTest
|
||||||
, locationIsAmbiguousInSourceCodeTest
|
, 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
|
||||||
expectedMoreErrorsTest =
|
expectedMoreErrorsTest =
|
||||||
test "expectedMoreErrors" <|
|
test "expectedMoreErrors" <|
|
||||||
|
Loading…
Reference in New Issue
Block a user