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

View File

@ -1,6 +1,6 @@
module Review.Test.ErrorMessage exposing
( ExpectedErrorData
, parsingFailure, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
, parsingFailure, globalErrorInTest, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
, needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
@ -12,7 +12,7 @@ module Review.Test.ErrorMessage exposing
# Error messages
@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 needToUsedExpectErrorsForModules, duplicateModuleName, unknownModulesInExpectedErrors
@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
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 expectedError error =
"""UNEXPECTED ERROR MESSAGE