mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-25 10:41:47 +03:00
Explain in which module we are getting an unexpected test result
This commit is contained in:
parent
c4fbda59c4
commit
a2a5831e0b
@ -126,13 +126,14 @@ import Set exposing (Set)
|
|||||||
-}
|
-}
|
||||||
type ReviewResult
|
type ReviewResult
|
||||||
= FailedRun String
|
= FailedRun String
|
||||||
| SuccessfulRun
|
| SuccessfulRun (List SuccessfulRunResult)
|
||||||
(List
|
|
||||||
{ moduleName : String
|
|
||||||
, inspector : CodeInspector
|
type alias SuccessfulRunResult =
|
||||||
, errors : List Error
|
{ moduleName : String
|
||||||
}
|
, inspector : CodeInspector
|
||||||
)
|
, errors : List Error
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias CodeInspector =
|
type alias CodeInspector =
|
||||||
@ -500,13 +501,13 @@ expectNoErrors reviewResult =
|
|||||||
Expect.fail errorMessage
|
Expect.fail errorMessage
|
||||||
|
|
||||||
SuccessfulRun runResults ->
|
SuccessfulRun runResults ->
|
||||||
let
|
runResults
|
||||||
errors : List Error
|
|> List.map
|
||||||
errors =
|
(\{ errors, moduleName } () ->
|
||||||
List.concatMap .errors runResults
|
List.isEmpty errors
|
||||||
in
|
|> Expect.true (ErrorMessage.didNotExpectErrors moduleName errors)
|
||||||
List.isEmpty errors
|
)
|
||||||
|> Expect.true (ErrorMessage.didNotExpectErrors errors)
|
|> (\expectations -> Expect.all expectations ())
|
||||||
|
|
||||||
|
|
||||||
{-| Assert that the rule reported some errors, by specifying which one.
|
{-| Assert that the rule reported some errors, by specifying which one.
|
||||||
@ -548,8 +549,8 @@ expectErrors expectedErrors reviewResult =
|
|||||||
FailedRun errorMessage ->
|
FailedRun errorMessage ->
|
||||||
Expect.fail errorMessage
|
Expect.fail errorMessage
|
||||||
|
|
||||||
SuccessfulRun ({ inspector, errors, moduleName } :: []) ->
|
SuccessfulRun (runResult :: []) ->
|
||||||
checkAllErrorsMatch inspector expectedErrors errors
|
checkAllErrorsMatch runResult expectedErrors
|
||||||
|
|
||||||
SuccessfulRun _ ->
|
SuccessfulRun _ ->
|
||||||
Expect.fail ErrorMessage.needToUsedExpectErrorsForModules
|
Expect.fail ErrorMessage.needToUsedExpectErrorsForModules
|
||||||
@ -611,16 +612,16 @@ expectErrorsForModules expectedErrorsList reviewResult =
|
|||||||
-- TODO Fail if there are some unknown modules in expectedErrorsList
|
-- TODO Fail if there are some unknown modules in expectedErrorsList
|
||||||
runResults
|
runResults
|
||||||
|> List.map
|
|> List.map
|
||||||
(\{ inspector, errors, moduleName } ->
|
(\runResult ->
|
||||||
let
|
let
|
||||||
expectedErrors : List ExpectedError
|
expectedErrors : List ExpectedError
|
||||||
expectedErrors =
|
expectedErrors =
|
||||||
expectedErrorsList
|
expectedErrorsList
|
||||||
|> ListExtra.find (\( moduleName_, _ ) -> moduleName_ == moduleName)
|
|> ListExtra.find (\( moduleName_, _ ) -> moduleName_ == runResult.moduleName)
|
||||||
|> Maybe.map Tuple.second
|
|> Maybe.map Tuple.second
|
||||||
|> Maybe.withDefault []
|
|> Maybe.withDefault []
|
||||||
in
|
in
|
||||||
\() -> checkAllErrorsMatch inspector expectedErrors errors
|
\() -> checkAllErrorsMatch runResult expectedErrors
|
||||||
)
|
)
|
||||||
|> (\expectations -> Expect.all expectations ())
|
|> (\expectations -> Expect.all expectations ())
|
||||||
|
|
||||||
@ -801,28 +802,28 @@ checkIfLocationIsAmbiguousInSourceCode sourceCode error_ under =
|
|||||||
-- RUNNING THE CHECKS
|
-- RUNNING THE CHECKS
|
||||||
|
|
||||||
|
|
||||||
checkAllErrorsMatch : CodeInspector -> List ExpectedError -> List Error -> Expectation
|
checkAllErrorsMatch : SuccessfulRunResult -> List ExpectedError -> Expectation
|
||||||
checkAllErrorsMatch codeInspector expectedErrors errors =
|
checkAllErrorsMatch runResult expectedErrors =
|
||||||
checkErrorsMatch codeInspector expectedErrors errors
|
checkErrorsMatch runResult expectedErrors runResult.errors
|
||||||
|> List.reverse
|
|> List.reverse
|
||||||
|> (\expectations -> Expect.all expectations ())
|
|> (\expectations -> Expect.all expectations ())
|
||||||
|
|
||||||
|
|
||||||
checkErrorsMatch : CodeInspector -> List ExpectedError -> List Error -> List (() -> Expectation)
|
checkErrorsMatch : SuccessfulRunResult -> List ExpectedError -> List Error -> List (() -> Expectation)
|
||||||
checkErrorsMatch codeInspector expectedErrors errors =
|
checkErrorsMatch runResult expectedErrors errors =
|
||||||
case ( expectedErrors, errors ) of
|
case ( expectedErrors, errors ) of
|
||||||
( [], [] ) ->
|
( [], [] ) ->
|
||||||
[ always Expect.pass ]
|
[ always Expect.pass ]
|
||||||
|
|
||||||
( expected :: restOfExpectedErrors, error_ :: restOfErrors ) ->
|
( expected :: restOfExpectedErrors, error_ :: restOfErrors ) ->
|
||||||
checkErrorMatch codeInspector expected error_
|
checkErrorMatch runResult.inspector expected error_
|
||||||
:: checkErrorsMatch codeInspector restOfExpectedErrors restOfErrors
|
:: checkErrorsMatch runResult restOfExpectedErrors restOfErrors
|
||||||
|
|
||||||
( expected :: restOfExpectedErrors, [] ) ->
|
( expected :: restOfExpectedErrors, [] ) ->
|
||||||
[ always <| Expect.fail <| ErrorMessage.expectedMoreErrors <| List.map extractExpectedErrorData (expected :: restOfExpectedErrors) ]
|
[ always <| Expect.fail <| ErrorMessage.expectedMoreErrors runResult.moduleName <| List.map extractExpectedErrorData (expected :: restOfExpectedErrors) ]
|
||||||
|
|
||||||
( [], error_ :: restOfErrors ) ->
|
( [], error_ :: restOfErrors ) ->
|
||||||
[ always <| Expect.fail <| ErrorMessage.tooManyErrors (error_ :: restOfErrors) ]
|
[ always <| Expect.fail <| ErrorMessage.tooManyErrors runResult.moduleName (error_ :: restOfErrors) ]
|
||||||
|
|
||||||
|
|
||||||
checkErrorMatch : CodeInspector -> ExpectedError -> Error -> (() -> Expectation)
|
checkErrorMatch : CodeInspector -> ExpectedError -> Error -> (() -> Expectation)
|
||||||
|
@ -43,11 +43,11 @@ type alias SourceCode =
|
|||||||
-- ERROR MESSAGES
|
-- ERROR MESSAGES
|
||||||
|
|
||||||
|
|
||||||
didNotExpectErrors : List Error -> String
|
didNotExpectErrors : String -> List Error -> String
|
||||||
didNotExpectErrors errors =
|
didNotExpectErrors moduleName errors =
|
||||||
"""DID NOT EXPECT ERRORS
|
"""DID NOT EXPECT ERRORS
|
||||||
|
|
||||||
I expected no errors but found:
|
I expected no errors for module `""" ++ moduleName ++ """` but found:
|
||||||
|
|
||||||
""" ++ listErrorMessagesAndPositions errors
|
""" ++ listErrorMessagesAndPositions errors
|
||||||
|
|
||||||
@ -187,8 +187,8 @@ but I found it at:
|
|||||||
""" ++ rangeAsString (Rule.errorRange error)
|
""" ++ rangeAsString (Rule.errorRange error)
|
||||||
|
|
||||||
|
|
||||||
expectedMoreErrors : List ExpectedErrorData -> String
|
expectedMoreErrors : String -> List ExpectedErrorData -> String
|
||||||
expectedMoreErrors missingExpectedErrors =
|
expectedMoreErrors moduleName missingExpectedErrors =
|
||||||
let
|
let
|
||||||
numberOfErrors : Int
|
numberOfErrors : Int
|
||||||
numberOfErrors =
|
numberOfErrors =
|
||||||
@ -197,15 +197,15 @@ expectedMoreErrors missingExpectedErrors =
|
|||||||
"""RULE REPORTED LESS ERRORS THAN EXPECTED
|
"""RULE REPORTED LESS ERRORS THAN EXPECTED
|
||||||
|
|
||||||
I expected to see """
|
I expected to see """
|
||||||
++ (String.fromInt numberOfErrors ++ " more " ++ pluralizeErrors numberOfErrors ++ ":\n\n")
|
++ (String.fromInt numberOfErrors ++ " more " ++ pluralizeErrors numberOfErrors ++ " for module `" ++ moduleName ++ "`:\n\n")
|
||||||
++ (missingExpectedErrors
|
++ (missingExpectedErrors
|
||||||
|> List.map expectedErrorToString
|
|> List.map expectedErrorToString
|
||||||
|> String.join "\n"
|
|> String.join "\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
tooManyErrors : List Error -> String
|
tooManyErrors : String -> List Error -> String
|
||||||
tooManyErrors extraErrors =
|
tooManyErrors moduleName extraErrors =
|
||||||
let
|
let
|
||||||
numberOfErrors : Int
|
numberOfErrors : Int
|
||||||
numberOfErrors =
|
numberOfErrors =
|
||||||
@ -214,7 +214,7 @@ tooManyErrors extraErrors =
|
|||||||
"""RULE REPORTED MORE ERRORS THAN EXPECTED
|
"""RULE REPORTED MORE ERRORS THAN EXPECTED
|
||||||
|
|
||||||
I found """
|
I found """
|
||||||
++ (String.fromInt numberOfErrors ++ " " ++ pluralizeErrors numberOfErrors ++ " too many:\n\n")
|
++ (String.fromInt numberOfErrors ++ " " ++ pluralizeErrors numberOfErrors ++ " too many for module `" ++ moduleName ++ "`:\n\n")
|
||||||
++ listErrorMessagesAndPositions extraErrors
|
++ listErrorMessagesAndPositions extraErrors
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,11 +101,11 @@ didNotExpectErrorsTest =
|
|||||||
dummyRange
|
dummyRange
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
ErrorMessage.didNotExpectErrors errors
|
ErrorMessage.didNotExpectErrors "ModuleName" errors
|
||||||
|> expectMessageEqual """
|
|> expectMessageEqual """
|
||||||
DID NOT EXPECT ERRORS
|
DID NOT EXPECT ERRORS
|
||||||
|
|
||||||
I expected no errors but found:
|
I expected no errors for module `ModuleName` but found:
|
||||||
|
|
||||||
- `Some error`
|
- `Some error`
|
||||||
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
||||||
@ -443,11 +443,11 @@ expectedMoreErrorsTest =
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
ErrorMessage.expectedMoreErrors missingErrors
|
ErrorMessage.expectedMoreErrors "MyModule" missingErrors
|
||||||
|> expectMessageEqual """
|
|> expectMessageEqual """
|
||||||
RULE REPORTED LESS ERRORS THAN EXPECTED
|
RULE REPORTED LESS ERRORS THAN EXPECTED
|
||||||
|
|
||||||
I expected to see 2 more errors:
|
I expected to see 2 more errors for module `MyModule`:
|
||||||
|
|
||||||
- `Remove the use of `Debug` before shipping to production`
|
- `Remove the use of `Debug` before shipping to production`
|
||||||
- `Remove the use of `Debug` before shipping to production`
|
- `Remove the use of `Debug` before shipping to production`
|
||||||
@ -469,11 +469,11 @@ tooManyErrorsTest =
|
|||||||
{ start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
{ start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
ErrorMessage.tooManyErrors extraErrors
|
ErrorMessage.tooManyErrors "MyModule" extraErrors
|
||||||
|> expectMessageEqual """
|
|> expectMessageEqual """
|
||||||
RULE REPORTED MORE ERRORS THAN EXPECTED
|
RULE REPORTED MORE ERRORS THAN EXPECTED
|
||||||
|
|
||||||
I found 1 error too many:
|
I found 1 error too many for module `MyModule`:
|
||||||
|
|
||||||
- `Remove the use of `Debug` before shipping to production`
|
- `Remove the use of `Debug` before shipping to production`
|
||||||
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
||||||
@ -495,11 +495,11 @@ I found 1 error too many:
|
|||||||
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
ErrorMessage.tooManyErrors extraErrors
|
ErrorMessage.tooManyErrors "MyOtherModule" extraErrors
|
||||||
|> expectMessageEqual """
|
|> expectMessageEqual """
|
||||||
RULE REPORTED MORE ERRORS THAN EXPECTED
|
RULE REPORTED MORE ERRORS THAN EXPECTED
|
||||||
|
|
||||||
I found 2 errors too many:
|
I found 2 errors too many for module `MyOtherModule`:
|
||||||
|
|
||||||
- `Remove the use of `Debug` before shipping to production`
|
- `Remove the use of `Debug` before shipping to production`
|
||||||
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
||||||
|
Loading…
Reference in New Issue
Block a user