mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-25 10:41:47 +03:00
Improve how tests fail when a global error occurs in the test source code
This commit is contained in:
parent
6bfc9f0757
commit
2016640367
@ -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,11 +362,16 @@ runOnModulesWithProjectData project rule sources =
|
||||
|> Rule.review [ rule ]
|
||||
|> Tuple.first
|
||||
in
|
||||
List.concat
|
||||
[ List.map (moduleToRunResult errors) modules
|
||||
, elmJsonRunResult errors projectWithModules
|
||||
]
|
||||
|> SuccessfulRun
|
||||
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
|
||||
]
|
||||
|> SuccessfulRun
|
||||
|
||||
|
||||
moduleToRunResult : List Error -> ProjectModule -> SuccessfulRunResult
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user