mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 14:55:35 +03:00
Give a nicer error message when under is passed empty
This commit is contained in:
parent
b72326085b
commit
f28b7698d7
@ -841,16 +841,16 @@ checkErrorsMatch runResult expectedErrors errors =
|
||||
checkErrorMatch : CodeInspector -> ExpectedError -> Error -> (() -> Expectation)
|
||||
checkErrorMatch codeInspector ((ExpectedError expectedError_) as expectedError) error_ =
|
||||
Expect.all
|
||||
[ (expectedError_.message == Rule.errorMessage error_)
|
||||
[ \() ->
|
||||
(expectedError_.message == Rule.errorMessage error_)
|
||||
|> Expect.true
|
||||
(ErrorMessage.messageMismatch
|
||||
(extractExpectedErrorData expectedError)
|
||||
error_
|
||||
)
|
||||
|> always
|
||||
, checkMessageAppearsUnder codeInspector error_ expectedError
|
||||
, checkDetailsAreCorrect error_ expectedError
|
||||
, always <| checkFixesAreCorrect codeInspector error_ expectedError
|
||||
, \() -> checkFixesAreCorrect codeInspector error_ expectedError
|
||||
]
|
||||
|
||||
|
||||
@ -861,27 +861,37 @@ checkMessageAppearsUnder codeInspector error_ (ExpectedError expectedError) =
|
||||
case expectedError.under of
|
||||
Under under ->
|
||||
Expect.all
|
||||
[ (codeAtLocation == under)
|
||||
[ \() ->
|
||||
case under of
|
||||
"" ->
|
||||
ErrorMessage.underMayNotBeEmpty
|
||||
{ message = expectedError.message
|
||||
, codeAtLocation = codeAtLocation
|
||||
}
|
||||
|> Expect.fail
|
||||
|
||||
_ ->
|
||||
Expect.pass
|
||||
, \() ->
|
||||
(codeAtLocation == under)
|
||||
|> Expect.true (ErrorMessage.underMismatch error_ { under = under, codeAtLocation = codeAtLocation })
|
||||
|> always
|
||||
, codeInspector.checkIfLocationIsAmbiguous error_ under
|
||||
|> always
|
||||
, \() -> codeInspector.checkIfLocationIsAmbiguous error_ under
|
||||
]
|
||||
|
||||
UnderExactly under range ->
|
||||
Expect.all
|
||||
[ (codeAtLocation == under)
|
||||
[ \() ->
|
||||
(codeAtLocation == under)
|
||||
|> Expect.true (ErrorMessage.underMismatch error_ { under = under, codeAtLocation = codeAtLocation })
|
||||
|> always
|
||||
, (Rule.errorRange error_ == range)
|
||||
, \() ->
|
||||
(Rule.errorRange error_ == range)
|
||||
|> Expect.true (ErrorMessage.wrongLocation error_ range under)
|
||||
|> always
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
\() ->
|
||||
ErrorMessage.locationNotFound error_
|
||||
|> Expect.fail
|
||||
|> always
|
||||
|
||||
|
||||
checkDetailsAreCorrect : Error -> ExpectedError -> (() -> Expectation)
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Review.Test.ErrorMessage exposing
|
||||
( ExpectedErrorData
|
||||
, parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
||||
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, locationIsAmbiguousInSourceCode
|
||||
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
|
||||
, needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||
)
|
||||
@ -13,7 +13,7 @@ module Review.Test.ErrorMessage exposing
|
||||
|
||||
@docs ExpectedErrorData
|
||||
@docs parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
|
||||
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, locationIsAmbiguousInSourceCode
|
||||
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
|
||||
@docs needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||
|
||||
@ -232,6 +232,23 @@ 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."""
|
||||
|
||||
|
||||
underMayNotBeEmpty : { message : String, codeAtLocation : String } -> String
|
||||
underMayNotBeEmpty { message, codeAtLocation } =
|
||||
"""COULD NOT FIND LOCATION FOR ERROR
|
||||
|
||||
I was looking for the error with the following message:
|
||||
|
||||
""" ++ wrapInQuotes message ++ """
|
||||
|
||||
and I found it, but the expected error has an empty string for `under`. I
|
||||
need to point somewhere, so as to best help the people who encounter this
|
||||
error.
|
||||
|
||||
If this helps, this is where I found the error:
|
||||
|
||||
""" ++ formatSourceCode codeAtLocation
|
||||
|
||||
|
||||
locationIsAmbiguousInSourceCode : SourceCode -> Error -> String -> List Int -> String
|
||||
locationIsAmbiguousInSourceCode sourceCode error under occurrencesInSourceCode =
|
||||
"""AMBIGUOUS ERROR LOCATION
|
||||
|
@ -18,6 +18,7 @@ all =
|
||||
, unexpectedDetailsTest
|
||||
, emptyDetailsTest
|
||||
, wrongLocationTest
|
||||
, underMayNotBeEmptyTest
|
||||
, locationNotFoundTest
|
||||
, expectedMoreErrorsTest
|
||||
, tooManyErrorsTest
|
||||
@ -458,6 +459,31 @@ This will be the most helpful for the person who reads the error message.
|
||||
"""
|
||||
|
||||
|
||||
underMayNotBeEmptyTest : Test
|
||||
underMayNotBeEmptyTest =
|
||||
test "underMayNotBeEmpty" <|
|
||||
\() ->
|
||||
ErrorMessage.underMayNotBeEmpty
|
||||
{ message = "Some error"
|
||||
, codeAtLocation = "abcd = 1"
|
||||
}
|
||||
|> 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 expected error has an empty string for `under`. I
|
||||
need to point somewhere, so as to best help the people who encounter this
|
||||
error.
|
||||
|
||||
If this helps, this is where I found the error:
|
||||
|
||||
`abcd = 1`
|
||||
"""
|
||||
|
||||
|
||||
expectedMoreErrorsTest : Test
|
||||
expectedMoreErrorsTest =
|
||||
test "expectedMoreErrors" <|
|
||||
|
Loading…
Reference in New Issue
Block a user