Improve how tests fail when a global error occurs in the test source code

This commit is contained in:
Jeroen Engels 2020-02-15 00:14:03 +01:00
parent 6bfc9f0757
commit 2016640367
2 changed files with 27 additions and 8 deletions

View File

@ -355,7 +355,6 @@ runOnModulesWithProjectData project rule sources =
FailedRun <| ErrorMessage.duplicateModuleName moduleName FailedRun <| ErrorMessage.duplicateModuleName moduleName
Nothing -> Nothing ->
-- TODO Fail if there is a global error
let let
errors : List Error errors : List Error
errors = errors =
@ -363,11 +362,16 @@ runOnModulesWithProjectData project rule sources =
|> Rule.review [ rule ] |> Rule.review [ rule ]
|> Tuple.first |> Tuple.first
in in
List.concat case ListExtra.find (\err_ -> Rule.errorFilePath err_ == "GLOBAL ERROR") errors of
[ List.map (moduleToRunResult errors) modules Just globalError ->
, elmJsonRunResult errors projectWithModules FailedRun <| ErrorMessage.globalErrorInTest globalError
]
|> SuccessfulRun Nothing ->
List.concat
[ List.map (moduleToRunResult errors) modules
, elmJsonRunResult errors projectWithModules
]
|> SuccessfulRun
moduleToRunResult : List Error -> ProjectModule -> SuccessfulRunResult moduleToRunResult : List Error -> ProjectModule -> SuccessfulRunResult

View File

@ -1,6 +1,6 @@
module Review.Test.ErrorMessage exposing module Review.Test.ErrorMessage exposing
( ExpectedErrorData ( ExpectedErrorData
, parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors , parsingFailure, globalErrorInTest, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, 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
@ -12,7 +12,7 @@ module Review.Test.ErrorMessage exposing
# Error messages # Error messages
@docs ExpectedErrorData @docs ExpectedErrorData
@docs parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors @docs parsingFailure, globalErrorInTest, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, 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
@ -83,6 +83,21 @@ The source code in question is the one at index """
title ++ "\n\n" ++ details ++ "\n\n" ++ hint title ++ "\n\n" ++ details ++ "\n\n" ++ hint
globalErrorInTest : Error -> String
globalErrorInTest error =
"""GLOBAL ERROR IN SOURCE CODE
I found a global error in the project you provided for this test:
""" ++ wrapInQuotes (Rule.errorMessage error) ++ """
""" ++ formatDetails (Rule.errorDetails error) ++ """
`elm-review` would fail with this error if the project to be reviewed had
the same issue. Please fix this issue in your test.
"""
messageMismatch : ExpectedErrorData -> Error -> String messageMismatch : ExpectedErrorData -> Error -> String
messageMismatch expectedError error = messageMismatch expectedError error =
"""UNEXPECTED ERROR MESSAGE """UNEXPECTED ERROR MESSAGE