Add error message when the number of lists of errors is unexpected

This commit is contained in:
Jeroen Engels 2020-01-04 12:40:11 +01:00
parent c1616c82bb
commit 7b786d9a2d
3 changed files with 66 additions and 10 deletions

View File

@ -422,6 +422,10 @@ expectErrorsForFiles expectedErrorsList reviewResult =
Expect.fail ErrorMessage.parsingFailure
SuccessfulRun runResults ->
if List.length runResults /= List.length expectedErrorsList then
Expect.fail <| ErrorMessage.errorListLengthMismatch (List.length runResults) (List.length expectedErrorsList)
else
-- TODO Add expectation that we have as many elements in expectedErrorsList as runResults
List.map2
(\{ inspector, errors } expectedErrors () ->

View File

@ -1,7 +1,7 @@
module Review.Test.ErrorMessage exposing
( ExpectedErrorData
, parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
, underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode
, underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode, errorListLengthMismatch
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
, impossibleState
)
@ -13,7 +13,7 @@ module Review.Test.ErrorMessage exposing
@docs ExpectedErrorData
@docs parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationIsAmbiguousInSourceCode, errorListLengthMismatch
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
@docs impossibleState
@ -215,6 +215,29 @@ Tip: I found them at:
""" ++ listOccurrencesAsLocations sourceCode under occurrencesInSourceCode
errorListLengthMismatch : Int -> Int -> String
errorListLengthMismatch expectedListLength actualListLength =
"""MISMATCH BETWEEN NUMBER OF MODULES AND NUMBER OF LISTS OF ERRORS
You passed a list of """ ++ String.fromInt expectedListLength ++ """ modules to this test, but a list of """ ++ String.fromInt actualListLength ++ """ lists
of errors.
I expect each item in the list of expected errors to correspond to the
module at the same position in the module list. Since the two lists have
different sizes, I'm not sure how to associate the last modules or errors.
If you expect no errors to be reported for a module, use an empty list:
test "..." <|
\\() ->
[ sourceCode1, sourceCode2 ]
|> Review.Test.runMulti rule
|> Review.Test.expectErrorsForFiles
[ [] -- Expect no errors reported in `sourceCode1`
, [ Review.Test.error theErrorForSourceCode2 ]
]"""
impossibleState : String
impossibleState =
"""ELM-REVIEW IMPOSSIBLE STATE

View File

@ -21,6 +21,7 @@ all =
, expectedMoreErrorsTest
, tooManyErrorsTest
, locationIsAmbiguousInSourceCodeTest
, errorListLengthMismatchTest
, missingFixesTest
, unexpectedFixesTest
, fixedCodeMismatchTest
@ -587,6 +588,34 @@ Tip: I found them at:
]
errorListLengthMismatchTest : Test
errorListLengthMismatchTest =
test "errorListLengthMismatch" <|
\() ->
ErrorMessage.errorListLengthMismatch 1417 1418
|> expectMessageEqual """
MISMATCH BETWEEN NUMBER OF MODULES AND NUMBER OF LISTS OF ERRORS
You passed a list of 1417 modules to this test, but a list of 1418 lists
of errors.
I expect each item in the list of expected errors to correspond to the
module at the same position in the module list. Since the two lists have
different sizes, I'm not sure how to associate the last modules or errors.
If you expect no errors to be reported for a module, use an empty list:
test "..." <|
\\() ->
[ sourceCode1, sourceCode2 ]
|> Review.Test.runMulti rule
|> Review.Test.expectErrorsForFiles
[ [] -- Expect no errors reported in `sourceCode1`
, [ Review.Test.error theErrorForSourceCode2 ]
]
"""
missingFixesTest : Test
missingFixesTest =
test "missingFixes" <|