mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 23:05: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 -> Error -> (() -> Expectation)
|
||||||
checkErrorMatch codeInspector ((ExpectedError expectedError_) as expectedError) error_ =
|
checkErrorMatch codeInspector ((ExpectedError expectedError_) as expectedError) error_ =
|
||||||
Expect.all
|
Expect.all
|
||||||
[ (expectedError_.message == Rule.errorMessage error_)
|
[ \() ->
|
||||||
|> Expect.true
|
(expectedError_.message == Rule.errorMessage error_)
|
||||||
(ErrorMessage.messageMismatch
|
|> Expect.true
|
||||||
(extractExpectedErrorData expectedError)
|
(ErrorMessage.messageMismatch
|
||||||
error_
|
(extractExpectedErrorData expectedError)
|
||||||
)
|
error_
|
||||||
|> always
|
)
|
||||||
, checkMessageAppearsUnder codeInspector error_ expectedError
|
, checkMessageAppearsUnder codeInspector error_ expectedError
|
||||||
, checkDetailsAreCorrect 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
|
case expectedError.under of
|
||||||
Under under ->
|
Under under ->
|
||||||
Expect.all
|
Expect.all
|
||||||
[ (codeAtLocation == under)
|
[ \() ->
|
||||||
|> Expect.true (ErrorMessage.underMismatch error_ { under = under, codeAtLocation = codeAtLocation })
|
case under of
|
||||||
|> always
|
"" ->
|
||||||
, codeInspector.checkIfLocationIsAmbiguous error_ under
|
ErrorMessage.underMayNotBeEmpty
|
||||||
|> always
|
{ message = expectedError.message
|
||||||
|
, codeAtLocation = codeAtLocation
|
||||||
|
}
|
||||||
|
|> Expect.fail
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Expect.pass
|
||||||
|
, \() ->
|
||||||
|
(codeAtLocation == under)
|
||||||
|
|> Expect.true (ErrorMessage.underMismatch error_ { under = under, codeAtLocation = codeAtLocation })
|
||||||
|
, \() -> codeInspector.checkIfLocationIsAmbiguous error_ under
|
||||||
]
|
]
|
||||||
|
|
||||||
UnderExactly under range ->
|
UnderExactly under range ->
|
||||||
Expect.all
|
Expect.all
|
||||||
[ (codeAtLocation == under)
|
[ \() ->
|
||||||
|> Expect.true (ErrorMessage.underMismatch error_ { under = under, codeAtLocation = codeAtLocation })
|
(codeAtLocation == under)
|
||||||
|> always
|
|> Expect.true (ErrorMessage.underMismatch error_ { under = under, codeAtLocation = codeAtLocation })
|
||||||
, (Rule.errorRange error_ == range)
|
, \() ->
|
||||||
|> Expect.true (ErrorMessage.wrongLocation error_ range under)
|
(Rule.errorRange error_ == range)
|
||||||
|> always
|
|> Expect.true (ErrorMessage.wrongLocation error_ range under)
|
||||||
]
|
]
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
ErrorMessage.locationNotFound error_
|
\() ->
|
||||||
|> Expect.fail
|
ErrorMessage.locationNotFound error_
|
||||||
|> always
|
|> Expect.fail
|
||||||
|
|
||||||
|
|
||||||
checkDetailsAreCorrect : Error -> ExpectedError -> (() -> Expectation)
|
checkDetailsAreCorrect : Error -> ExpectedError -> (() -> Expectation)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
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, locationNotFound, locationIsAmbiguousInSourceCode
|
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
|
||||||
, needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
, needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||||
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
||||||
)
|
)
|
||||||
@ -13,7 +13,7 @@ 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, locationNotFound, locationIsAmbiguousInSourceCode
|
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
|
||||||
@docs needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
@docs needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
|
||||||
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
|
@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."""
|
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 -> String -> List Int -> String
|
||||||
locationIsAmbiguousInSourceCode sourceCode error under occurrencesInSourceCode =
|
locationIsAmbiguousInSourceCode sourceCode error under occurrencesInSourceCode =
|
||||||
"""AMBIGUOUS ERROR LOCATION
|
"""AMBIGUOUS ERROR LOCATION
|
||||||
|
@ -18,6 +18,7 @@ all =
|
|||||||
, unexpectedDetailsTest
|
, unexpectedDetailsTest
|
||||||
, emptyDetailsTest
|
, emptyDetailsTest
|
||||||
, wrongLocationTest
|
, wrongLocationTest
|
||||||
|
, underMayNotBeEmptyTest
|
||||||
, locationNotFoundTest
|
, locationNotFoundTest
|
||||||
, expectedMoreErrorsTest
|
, expectedMoreErrorsTest
|
||||||
, tooManyErrorsTest
|
, 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
|
||||||
expectedMoreErrorsTest =
|
expectedMoreErrorsTest =
|
||||||
test "expectedMoreErrors" <|
|
test "expectedMoreErrors" <|
|
||||||
|
Loading…
Reference in New Issue
Block a user