2019-07-09 09:15:24 +03:00
|
|
|
module ErrorMessageTest exposing (all)
|
|
|
|
|
|
|
|
import Elm.Syntax.Range exposing (Range)
|
2019-07-11 19:42:39 +03:00
|
|
|
import Expect exposing (Expectation)
|
2019-09-29 00:47:02 +03:00
|
|
|
import Review.Fix as Fix
|
|
|
|
import Review.Rule as Rule exposing (Error)
|
|
|
|
import Review.Test.ErrorMessage as ErrorMessage exposing (ExpectedErrorData)
|
2019-07-09 09:15:24 +03:00
|
|
|
import Test exposing (Test, describe, test)
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
|
|
|
describe "Test.ErrorMessage"
|
2019-07-11 09:43:56 +03:00
|
|
|
[ parsingFailureTest
|
2019-07-09 09:15:24 +03:00
|
|
|
, didNotExpectErrorsTest
|
2019-07-11 09:43:56 +03:00
|
|
|
, messageMismatchTest
|
|
|
|
, underMismatchTest
|
2019-07-28 01:56:31 +03:00
|
|
|
, unexpectedDetailsTest
|
|
|
|
, emptyDetailsTest
|
2019-07-11 09:43:56 +03:00
|
|
|
, wrongLocationTest
|
2020-02-11 20:47:28 +03:00
|
|
|
, underMayNotBeEmptyTest
|
2020-02-11 20:12:51 +03:00
|
|
|
, locationNotFoundTest
|
2019-07-11 09:43:56 +03:00
|
|
|
, expectedMoreErrorsTest
|
2019-07-09 09:15:24 +03:00
|
|
|
, tooManyErrorsTest
|
2019-07-13 11:09:08 +03:00
|
|
|
, locationIsAmbiguousInSourceCodeTest
|
2020-01-05 20:44:16 +03:00
|
|
|
, needToUsedExpectErrorsForModulesTest
|
2020-01-04 15:18:31 +03:00
|
|
|
, duplicateModuleNameTest
|
2020-02-11 19:45:55 +03:00
|
|
|
, unknownModulesInExpectedErrorsTest
|
2019-08-05 01:04:27 +03:00
|
|
|
, missingFixesTest
|
|
|
|
, unexpectedFixesTest
|
|
|
|
, fixedCodeMismatchTest
|
2019-08-08 00:04:41 +03:00
|
|
|
, unchangedSourceAfterFixTest
|
|
|
|
, invalidSourceAfterFixTest
|
2019-08-19 00:32:30 +03:00
|
|
|
, hasCollisionsInFixRangesTest
|
2019-07-09 09:15:24 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-07-11 19:42:39 +03:00
|
|
|
expectMessageEqual : String -> String -> Expectation
|
|
|
|
expectMessageEqual expectedMessage =
|
|
|
|
Expect.all
|
|
|
|
[ Expect.equal <| String.trim expectedMessage
|
|
|
|
, \receivedMessage ->
|
|
|
|
Expect.all
|
|
|
|
(String.lines receivedMessage
|
|
|
|
|> List.map
|
|
|
|
(\line () ->
|
|
|
|
(String.length line <= 76)
|
|
|
|
|> Expect.true ("Message has line longer than 76 characters:\n\n" ++ line)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
()
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-07-11 09:43:56 +03:00
|
|
|
parsingFailureTest : Test
|
|
|
|
parsingFailureTest =
|
2020-01-05 13:04:20 +03:00
|
|
|
describe "parsingFailure"
|
|
|
|
[ test "when there is only one file" <|
|
|
|
|
\() ->
|
|
|
|
ErrorMessage.parsingFailure True { index = 0, source = "module MyModule exposing (.." }
|
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
TEST SOURCE CODE PARSING ERROR
|
2019-07-09 09:15:24 +03:00
|
|
|
|
2019-07-13 09:57:36 +03:00
|
|
|
I could not parse the test source code, because it was not valid Elm code.
|
2019-07-11 19:14:24 +03:00
|
|
|
|
|
|
|
Hint: Maybe you forgot to add the module definition at the top, like:
|
2019-07-09 09:15:24 +03:00
|
|
|
|
2019-07-11 19:42:39 +03:00
|
|
|
`module A exposing (..)`"""
|
2020-01-05 13:04:20 +03:00
|
|
|
, test "when there are multiple files" <|
|
|
|
|
\() ->
|
|
|
|
ErrorMessage.parsingFailure False { index = 32, source = "module MyModule exposing (.." }
|
|
|
|
|> expectMessageEqual """
|
|
|
|
TEST SOURCE CODE PARSING ERROR
|
|
|
|
|
|
|
|
I could not parse one of the test source codes, because it was not valid
|
|
|
|
Elm code.
|
|
|
|
|
|
|
|
The source code in question is the one at index 32 starting with:
|
|
|
|
|
|
|
|
`module MyModule exposing (..`
|
|
|
|
|
|
|
|
Hint: Maybe you forgot to add the module definition at the top, like:
|
|
|
|
|
|
|
|
`module A exposing (..)`"""
|
|
|
|
]
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
didNotExpectErrorsTest : Test
|
|
|
|
didNotExpectErrorsTest =
|
|
|
|
test "didNotExpectErrors" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
errors : List Error
|
|
|
|
errors =
|
2019-07-27 18:31:04 +03:00
|
|
|
[ Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
dummyRange
|
|
|
|
, Rule.error
|
|
|
|
{ message = "Some other error"
|
|
|
|
, details = [ "Some other details" ]
|
|
|
|
}
|
|
|
|
dummyRange
|
2019-07-09 09:15:24 +03:00
|
|
|
]
|
|
|
|
in
|
2020-01-15 18:16:40 +03:00
|
|
|
ErrorMessage.didNotExpectErrors "ModuleName" errors
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
DID NOT EXPECT ERRORS
|
|
|
|
|
2020-01-15 18:16:40 +03:00
|
|
|
I expected no errors for module `ModuleName` but found:
|
2019-07-09 09:15:24 +03:00
|
|
|
|
2019-07-13 10:53:35 +03:00
|
|
|
- `Some error`
|
2019-07-11 19:42:39 +03:00
|
|
|
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
2019-07-13 10:53:35 +03:00
|
|
|
- `Some other error`
|
2019-07-11 19:42:39 +03:00
|
|
|
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
|
2019-07-11 09:43:56 +03:00
|
|
|
messageMismatchTest : Test
|
|
|
|
messageMismatchTest =
|
|
|
|
test "messageMismatch" <|
|
2019-07-09 09:15:24 +03:00
|
|
|
\() ->
|
|
|
|
let
|
2019-07-11 09:43:56 +03:00
|
|
|
expectedError : ExpectedErrorData
|
2019-07-09 09:15:24 +03:00
|
|
|
expectedError =
|
2019-07-23 01:16:02 +03:00
|
|
|
{ message = "Remove the use of `Debug` before shipping to production"
|
2019-07-28 01:56:31 +03:00
|
|
|
, details = [ "Some details" ]
|
2019-07-11 09:43:56 +03:00
|
|
|
, under = "Debug.log"
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
2019-07-27 18:31:04 +03:00
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
dummyRange
|
2019-07-09 09:15:24 +03:00
|
|
|
in
|
2019-07-11 09:43:56 +03:00
|
|
|
ErrorMessage.messageMismatch expectedError error
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
UNEXPECTED ERROR MESSAGE
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
I was looking for the error with the following message:
|
|
|
|
|
2019-07-23 01:16:02 +03:00
|
|
|
`Remove the use of `Debug` before shipping to production`
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
but I found the following error message:
|
|
|
|
|
2019-07-27 18:31:04 +03:00
|
|
|
`Some error`"""
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
|
2019-07-11 09:43:56 +03:00
|
|
|
underMismatchTest : Test
|
|
|
|
underMismatchTest =
|
|
|
|
describe "underMismatch"
|
2019-07-09 09:15:24 +03:00
|
|
|
[ test "with single-line extracts" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
2019-07-27 18:31:04 +03:00
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
dummyRange
|
2019-07-09 09:15:24 +03:00
|
|
|
in
|
2019-07-11 09:43:56 +03:00
|
|
|
ErrorMessage.underMismatch
|
2019-07-09 09:15:24 +03:00
|
|
|
error
|
|
|
|
{ under = "abcd"
|
|
|
|
, codeAtLocation = "abcd = 1"
|
|
|
|
}
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
UNEXPECTED ERROR LOCATION
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
I found an error with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
which I was expecting, but I found it under:
|
|
|
|
|
|
|
|
`abcd = 1`
|
|
|
|
|
|
|
|
when I was expecting it under:
|
|
|
|
|
|
|
|
`abcd`
|
|
|
|
|
2019-07-11 19:14:24 +03:00
|
|
|
Hint: Maybe you're passing the `Range` of a wrong node when
|
2019-08-07 23:38:17 +03:00
|
|
|
calling `Rule.error`."""
|
2019-07-09 09:15:24 +03:00
|
|
|
, test "with multi-line extracts" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
2019-07-27 18:31:04 +03:00
|
|
|
Rule.error
|
|
|
|
{ message = "Some other error"
|
|
|
|
, details = [ "Some other details" ]
|
|
|
|
}
|
|
|
|
dummyRange
|
2019-07-09 09:15:24 +03:00
|
|
|
in
|
2019-07-11 09:43:56 +03:00
|
|
|
ErrorMessage.underMismatch
|
2019-07-09 09:15:24 +03:00
|
|
|
error
|
|
|
|
{ under = "abcd =\n 1\n + 2"
|
|
|
|
, codeAtLocation = "abcd =\n 1"
|
|
|
|
}
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
UNEXPECTED ERROR LOCATION
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
I found an error with the following message:
|
|
|
|
|
|
|
|
`Some other error`
|
|
|
|
|
|
|
|
which I was expecting, but I found it under:
|
|
|
|
|
|
|
|
```
|
|
|
|
abcd =
|
|
|
|
1
|
|
|
|
```
|
|
|
|
|
|
|
|
when I was expecting it under:
|
|
|
|
|
|
|
|
```
|
|
|
|
abcd =
|
|
|
|
1
|
|
|
|
+ 2
|
|
|
|
```
|
|
|
|
|
2019-07-11 19:14:24 +03:00
|
|
|
Hint: Maybe you're passing the `Range` of a wrong node when
|
2019-08-07 23:38:17 +03:00
|
|
|
calling `Rule.error`."""
|
2019-07-09 09:15:24 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-07-28 01:56:31 +03:00
|
|
|
unexpectedDetailsTest : Test
|
|
|
|
unexpectedDetailsTest =
|
|
|
|
describe "unexpectedDetails"
|
|
|
|
[ test "with single-line details" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
expectedDetails : List String
|
|
|
|
expectedDetails =
|
|
|
|
[ "Some details" ]
|
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some other details" ]
|
|
|
|
}
|
|
|
|
dummyRange
|
|
|
|
in
|
|
|
|
ErrorMessage.unexpectedDetails
|
|
|
|
expectedDetails
|
|
|
|
error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
UNEXPECTED ERROR DETAILS
|
|
|
|
|
|
|
|
I found an error with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
which I was expecting, but its details were:
|
|
|
|
|
|
|
|
`Some other details`
|
|
|
|
|
|
|
|
when I was expecting them to be:
|
|
|
|
|
|
|
|
`Some details`"""
|
|
|
|
, test "with multi-line details" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
expectedDetails : List String
|
|
|
|
expectedDetails =
|
|
|
|
[ "Some"
|
|
|
|
, "details"
|
|
|
|
]
|
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some other error"
|
|
|
|
, details =
|
|
|
|
[ "Some"
|
|
|
|
, "other"
|
|
|
|
, "details"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
dummyRange
|
|
|
|
in
|
|
|
|
ErrorMessage.unexpectedDetails
|
|
|
|
expectedDetails
|
|
|
|
error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
UNEXPECTED ERROR DETAILS
|
|
|
|
|
|
|
|
I found an error with the following message:
|
|
|
|
|
|
|
|
`Some other error`
|
|
|
|
|
|
|
|
which I was expecting, but its details were:
|
|
|
|
|
|
|
|
```
|
|
|
|
Some
|
|
|
|
|
|
|
|
other
|
|
|
|
|
|
|
|
details
|
|
|
|
```
|
|
|
|
|
|
|
|
when I was expecting them to be:
|
|
|
|
|
|
|
|
```
|
|
|
|
Some
|
|
|
|
|
|
|
|
details
|
|
|
|
```
|
|
|
|
"""
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
emptyDetailsTest : Test
|
|
|
|
emptyDetailsTest =
|
|
|
|
describe "emptyDetails"
|
|
|
|
[ test "with single-line details" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
dummyRange
|
|
|
|
in
|
|
|
|
ErrorMessage.emptyDetails
|
|
|
|
error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
EMPTY ERROR DETAILS
|
|
|
|
|
|
|
|
I found an error with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
2019-07-28 15:45:09 +03:00
|
|
|
but its details were empty. I require having details as I believe they will
|
2019-07-28 01:56:31 +03:00
|
|
|
help the user who encounters the problem.
|
|
|
|
|
|
|
|
The details could:
|
|
|
|
- explain what the problem is
|
|
|
|
- give suggestions on how to solve the problem or alternatives"""
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-07-11 09:43:56 +03:00
|
|
|
wrongLocationTest : Test
|
|
|
|
wrongLocationTest =
|
|
|
|
describe "wrongLocation"
|
2019-07-09 09:15:24 +03:00
|
|
|
[ test "with single-line extracts" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
2019-07-27 18:31:04 +03:00
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
in
|
2019-07-11 09:43:56 +03:00
|
|
|
ErrorMessage.wrongLocation
|
2019-07-09 09:15:24 +03:00
|
|
|
error
|
|
|
|
{ start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
|
|
|
"abcd"
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
UNEXPECTED ERROR LOCATION
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
I was looking for the error with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
under the following code:
|
|
|
|
|
|
|
|
`abcd`
|
|
|
|
|
2019-07-11 19:42:39 +03:00
|
|
|
and I found it, but the exact location you specified is not the one I found.
|
|
|
|
|
|
|
|
I was expecting the error at:
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
{ start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
|
|
|
|
|
|
|
but I found it at:
|
|
|
|
|
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
2019-07-11 19:42:39 +03:00
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
, test "with multi-line extracts" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
2019-07-27 18:31:04 +03:00
|
|
|
{ message = "Some other error"
|
|
|
|
, details = [ "Some other details" ]
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
{ start = { row = 4, column = 1 }, end = { row = 5, column = 3 } }
|
|
|
|
in
|
2019-07-11 09:43:56 +03:00
|
|
|
ErrorMessage.wrongLocation
|
2019-07-09 09:15:24 +03:00
|
|
|
error
|
|
|
|
{ start = { row = 2, column = 1 }, end = { row = 3, column = 3 } }
|
|
|
|
"abcd =\n 1"
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
UNEXPECTED ERROR LOCATION
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
I was looking for the error with the following message:
|
|
|
|
|
|
|
|
`Some other error`
|
|
|
|
|
|
|
|
under the following code:
|
|
|
|
|
|
|
|
```
|
|
|
|
abcd =
|
|
|
|
1
|
|
|
|
```
|
|
|
|
|
2019-07-11 19:42:39 +03:00
|
|
|
and I found it, but the exact location you specified is not the one I found.
|
|
|
|
|
|
|
|
I was expecting the error at:
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
{ start = { row = 2, column = 1 }, end = { row = 3, column = 3 } }
|
|
|
|
|
|
|
|
but I found it at:
|
|
|
|
|
|
|
|
{ start = { row = 4, column = 1 }, end = { row = 5, column = 3 } }
|
2019-07-11 19:42:39 +03:00
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-02-11 20:12:51 +03:00
|
|
|
locationNotFoundTest : Test
|
|
|
|
locationNotFoundTest =
|
|
|
|
test "locationNotFound" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
{ start = { row = 0, column = 0 }, end = { row = 0, column = 0 } }
|
|
|
|
in
|
|
|
|
ErrorMessage.locationNotFound error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
COULD NOT FIND LOCATION FOR ERROR
|
|
|
|
|
|
|
|
I was looking for the error with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
and I found it, but the code it points to does not lead to anything:
|
|
|
|
|
|
|
|
{ start = { row = 0, column = 0 }, end = { row = 0, column = 0 } }
|
|
|
|
|
|
|
|
Please try to have the error under the smallest region that makes sense.
|
|
|
|
This will be the most helpful for the person who reads the error message.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2020-02-11 20:47:28 +03:00
|
|
|
underMayNotBeEmptyTest : Test
|
|
|
|
underMayNotBeEmptyTest =
|
|
|
|
test "underMayNotBeEmpty" <|
|
|
|
|
\() ->
|
|
|
|
ErrorMessage.underMayNotBeEmpty
|
|
|
|
{ message = "Some error"
|
|
|
|
, codeAtLocation = "abcd = 1"
|
|
|
|
}
|
|
|
|
|> expectMessageEqual """
|
|
|
|
COULD NOT FIND LOCATION FOR ERROR
|
|
|
|
|
|
|
|
I was looking for the error with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
and I found it, but the expected error has an empty string for `under`. I
|
|
|
|
need to point somewhere, so as to best help the people who encounter this
|
|
|
|
error.
|
|
|
|
|
|
|
|
If this helps, this is where I found the error:
|
|
|
|
|
|
|
|
`abcd = 1`
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2019-07-11 09:43:56 +03:00
|
|
|
expectedMoreErrorsTest : Test
|
|
|
|
expectedMoreErrorsTest =
|
|
|
|
test "expectedMoreErrors" <|
|
2019-07-09 09:15:24 +03:00
|
|
|
\() ->
|
|
|
|
let
|
2019-07-11 09:43:56 +03:00
|
|
|
missingErrors : List ExpectedErrorData
|
2019-07-09 09:15:24 +03:00
|
|
|
missingErrors =
|
2019-07-23 01:16:02 +03:00
|
|
|
[ { message = "Remove the use of `Debug` before shipping to production"
|
2019-07-28 01:56:31 +03:00
|
|
|
, details = [ "Some details" ]
|
2019-07-11 09:43:56 +03:00
|
|
|
, under = "Debug.log"
|
|
|
|
}
|
2019-07-23 01:16:02 +03:00
|
|
|
, { message = "Remove the use of `Debug` before shipping to production"
|
2019-07-28 01:56:31 +03:00
|
|
|
, details = [ "Some details" ]
|
2019-07-11 09:43:56 +03:00
|
|
|
, under = "Debug.log"
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
]
|
|
|
|
in
|
2020-01-15 18:16:40 +03:00
|
|
|
ErrorMessage.expectedMoreErrors "MyModule" missingErrors
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
RULE REPORTED LESS ERRORS THAN EXPECTED
|
|
|
|
|
2020-01-15 18:16:40 +03:00
|
|
|
I expected to see 2 more errors for module `MyModule`:
|
2019-07-09 09:15:24 +03:00
|
|
|
|
2019-07-23 01:16:02 +03:00
|
|
|
- `Remove the use of `Debug` before shipping to production`
|
|
|
|
- `Remove the use of `Debug` before shipping to production`
|
2019-07-11 19:42:39 +03:00
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
tooManyErrorsTest : Test
|
|
|
|
tooManyErrorsTest =
|
|
|
|
describe "tooManyErrors"
|
|
|
|
[ test "with one extra error" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
extraErrors : List Rule.Error
|
|
|
|
extraErrors =
|
|
|
|
[ Rule.error
|
2019-07-27 18:31:04 +03:00
|
|
|
{ message = "Remove the use of `Debug` before shipping to production"
|
|
|
|
, details = [ "Some details about Debug" ]
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
{ start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
|
|
|
]
|
|
|
|
in
|
2020-01-15 18:16:40 +03:00
|
|
|
ErrorMessage.tooManyErrors "MyModule" extraErrors
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
RULE REPORTED MORE ERRORS THAN EXPECTED
|
|
|
|
|
2020-01-15 18:16:40 +03:00
|
|
|
I found 1 error too many for module `MyModule`:
|
2019-07-09 09:15:24 +03:00
|
|
|
|
2019-07-23 01:16:02 +03:00
|
|
|
- `Remove the use of `Debug` before shipping to production`
|
2019-07-11 19:42:39 +03:00
|
|
|
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
, test "with multiple extra errors" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
extraErrors : List Rule.Error
|
|
|
|
extraErrors =
|
|
|
|
[ Rule.error
|
2019-07-27 18:31:04 +03:00
|
|
|
{ message = "Remove the use of `Debug` before shipping to production"
|
|
|
|
, details = [ "Some details about Debug" ]
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
{ start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
|
|
|
, Rule.error
|
2019-07-27 18:31:04 +03:00
|
|
|
{ message = "Remove the use of `Debug` before shipping to production"
|
|
|
|
, details = [ "Some details about Debug" ]
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
]
|
|
|
|
in
|
2020-01-15 18:16:40 +03:00
|
|
|
ErrorMessage.tooManyErrors "MyOtherModule" extraErrors
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
RULE REPORTED MORE ERRORS THAN EXPECTED
|
|
|
|
|
2020-01-15 18:16:40 +03:00
|
|
|
I found 2 errors too many for module `MyOtherModule`:
|
2019-07-09 09:15:24 +03:00
|
|
|
|
2019-07-23 01:16:02 +03:00
|
|
|
- `Remove the use of `Debug` before shipping to production`
|
2019-07-11 19:42:39 +03:00
|
|
|
at { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
2019-07-23 01:16:02 +03:00
|
|
|
- `Remove the use of `Debug` before shipping to production`
|
2019-07-11 19:42:39 +03:00
|
|
|
at { start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-07-11 09:43:56 +03:00
|
|
|
locationIsAmbiguousInSourceCodeTest : Test
|
|
|
|
locationIsAmbiguousInSourceCodeTest =
|
|
|
|
describe "locationIsAmbiguousInSourceCode"
|
2019-07-09 09:15:24 +03:00
|
|
|
[ test "with single-line extracts" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
sourceCode : String
|
|
|
|
sourceCode =
|
|
|
|
"module A exposing (..)\nabcd\nabcd"
|
|
|
|
|
|
|
|
under : String
|
|
|
|
under =
|
|
|
|
"abcd"
|
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
2019-07-27 18:31:04 +03:00
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
in
|
2019-07-11 09:43:56 +03:00
|
|
|
ErrorMessage.locationIsAmbiguousInSourceCode
|
2019-07-09 09:15:24 +03:00
|
|
|
sourceCode
|
|
|
|
error
|
|
|
|
under
|
|
|
|
(String.indexes under sourceCode)
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
AMBIGUOUS ERROR LOCATION
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
Your test passes, but where the message appears is ambiguous.
|
|
|
|
|
|
|
|
You are looking for the following error message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
and expecting to see it under:
|
|
|
|
|
|
|
|
`abcd`
|
|
|
|
|
2019-09-29 00:47:02 +03:00
|
|
|
I found 2 locations where that code appeared. Please use
|
|
|
|
`Review.Rule.atExactly` to make the part you were targetting unambiguous.
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
Tip: I found them at:
|
|
|
|
- { start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|
|
|
|
- { start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
2019-07-11 19:42:39 +03:00
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
, test "with multi-line extracts" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
sourceCode : String
|
|
|
|
sourceCode =
|
|
|
|
"module A exposing (..)\nabcd =\n 1\nabcd =\n 1\nabcd =\n 1"
|
|
|
|
|
|
|
|
under : String
|
|
|
|
under =
|
|
|
|
"abcd =\n 1"
|
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
2019-07-27 18:31:04 +03:00
|
|
|
{ message = "Some other error"
|
|
|
|
, details = [ "Some other details" ]
|
|
|
|
}
|
2019-07-09 09:15:24 +03:00
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 4, column = 3 } }
|
|
|
|
in
|
2019-07-11 09:43:56 +03:00
|
|
|
ErrorMessage.locationIsAmbiguousInSourceCode
|
2019-07-09 09:15:24 +03:00
|
|
|
sourceCode
|
|
|
|
error
|
|
|
|
under
|
|
|
|
(String.indexes under sourceCode)
|
2019-07-11 19:42:39 +03:00
|
|
|
|> expectMessageEqual """
|
2019-07-11 19:14:24 +03:00
|
|
|
AMBIGUOUS ERROR LOCATION
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
Your test passes, but where the message appears is ambiguous.
|
|
|
|
|
|
|
|
You are looking for the following error message:
|
|
|
|
|
|
|
|
`Some other error`
|
|
|
|
|
|
|
|
and expecting to see it under:
|
|
|
|
|
|
|
|
```
|
|
|
|
abcd =
|
|
|
|
1
|
|
|
|
```
|
|
|
|
|
2019-09-29 00:47:02 +03:00
|
|
|
I found 3 locations where that code appeared. Please use
|
|
|
|
`Review.Rule.atExactly` to make the part you were targetting unambiguous.
|
2019-07-09 09:15:24 +03:00
|
|
|
|
|
|
|
Tip: I found them at:
|
|
|
|
- { start = { row = 2, column = 1 }, end = { row = 3, column = 4 } }
|
|
|
|
- { start = { row = 4, column = 1 }, end = { row = 5, column = 4 } }
|
|
|
|
- { start = { row = 6, column = 1 }, end = { row = 7, column = 4 } }
|
2019-07-11 19:42:39 +03:00
|
|
|
"""
|
2019-07-09 09:15:24 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-01-05 20:44:16 +03:00
|
|
|
needToUsedExpectErrorsForModulesTest : Test
|
|
|
|
needToUsedExpectErrorsForModulesTest =
|
|
|
|
test "needToUsedExpectErrorsForModules" <|
|
2020-01-04 14:40:11 +03:00
|
|
|
\() ->
|
2020-01-05 20:44:16 +03:00
|
|
|
ErrorMessage.needToUsedExpectErrorsForModules
|
2020-01-04 14:40:11 +03:00
|
|
|
|> expectMessageEqual """
|
2020-01-05 20:44:16 +03:00
|
|
|
AMBIGUOUS MODULE FOR ERROR
|
2020-01-04 14:40:11 +03:00
|
|
|
|
2020-01-05 20:44:16 +03:00
|
|
|
You gave me several modules, and you expect some errors. I need to know for
|
|
|
|
which module you expect these errors to be reported.
|
2020-01-04 14:40:11 +03:00
|
|
|
|
2020-01-05 20:44:16 +03:00
|
|
|
You should use `expectErrorsForModules` to do this:
|
2020-01-04 14:40:11 +03:00
|
|
|
|
|
|
|
test "..." <|
|
|
|
|
\\() ->
|
2020-01-05 20:44:16 +03:00
|
|
|
[ \"\"\"
|
|
|
|
module A exposing (..)
|
|
|
|
-- someCode
|
|
|
|
\"\"\", \"\"\"
|
|
|
|
module B exposing (..)
|
|
|
|
-- someCode
|
|
|
|
\"\"\" ]
|
2020-01-05 21:35:41 +03:00
|
|
|
|> Review.Test.runOnModules rule
|
2020-01-05 20:44:16 +03:00
|
|
|
|> Review.Test.expectErrorsForModules
|
|
|
|
[ ( "B", [ Review.Test.error someError ] )
|
|
|
|
]"""
|
2020-01-04 14:40:11 +03:00
|
|
|
|
|
|
|
|
2020-01-04 15:18:31 +03:00
|
|
|
duplicateModuleNameTest : Test
|
|
|
|
duplicateModuleNameTest =
|
|
|
|
test "duplicateModuleName" <|
|
|
|
|
\() ->
|
|
|
|
ErrorMessage.duplicateModuleName [ "My", "Module" ]
|
|
|
|
|> expectMessageEqual """
|
|
|
|
DUPLICATE MODULE NAMES
|
|
|
|
|
|
|
|
I found several modules named `My.Module` in the test source codes.
|
|
|
|
|
|
|
|
I expect all modules to be able to exist together in the same project,
|
|
|
|
but having several modules with the same name is not allowed by the Elm
|
|
|
|
compiler.
|
|
|
|
|
|
|
|
Please rename the modules so that they all have different names.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2020-02-11 19:45:55 +03:00
|
|
|
unknownModulesInExpectedErrorsTest : Test
|
|
|
|
unknownModulesInExpectedErrorsTest =
|
|
|
|
test "unknownModulesInExpectedErrors" <|
|
|
|
|
\() ->
|
|
|
|
ErrorMessage.unknownModulesInExpectedErrors "My.Module"
|
|
|
|
|> expectMessageEqual """
|
|
|
|
UNKNOWN MODULES IN EXPECTED ERRORS
|
|
|
|
|
|
|
|
I expected errors for a module named `My.Module` in the list passed to
|
|
|
|
`expectErrorsForModules`, but I couldn't find a module in the test source
|
|
|
|
codes named that way.
|
|
|
|
|
|
|
|
I assume that there was a mistake during the writing of the test. Please
|
|
|
|
match the names of the modules in the test source codes to the ones in the
|
|
|
|
expected errors list.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2019-08-05 01:04:27 +03:00
|
|
|
missingFixesTest : Test
|
|
|
|
missingFixesTest =
|
|
|
|
test "missingFixes" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
expectedError : ExpectedErrorData
|
|
|
|
expectedError =
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
, under = "Debug.log"
|
|
|
|
}
|
|
|
|
in
|
|
|
|
ErrorMessage.missingFixes expectedError
|
|
|
|
|> expectMessageEqual """
|
|
|
|
MISSING FIXES
|
|
|
|
|
|
|
|
I expected that the error with the following message
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
would provide some fixes, but I didn't find any.
|
|
|
|
|
2019-09-17 20:50:45 +03:00
|
|
|
Hint: Maybe you forgot to call `Rule.withFixes` on the error that you
|
|
|
|
created, or maybe the list of provided fixes was empty."""
|
2019-08-05 01:04:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
unexpectedFixesTest : Test
|
|
|
|
unexpectedFixesTest =
|
|
|
|
test "unexpectedFixes" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
range : Range
|
|
|
|
range =
|
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 4, column = 3 } }
|
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
range
|
|
|
|
|> Rule.withFixes [ Fix.removeRange range ]
|
|
|
|
in
|
|
|
|
ErrorMessage.unexpectedFixes error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
UNEXPECTED FIXES
|
|
|
|
|
|
|
|
I expected that the error with the following message
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
would not have any fixes, but it provided some.
|
|
|
|
|
2019-08-22 12:57:14 +03:00
|
|
|
Because the error provides fixes, I require providing the expected result
|
|
|
|
of the automatic fix. Otherwise, there is no way to know whether the fix
|
|
|
|
will result in a correct and in the intended result.
|
|
|
|
|
2019-09-29 00:47:02 +03:00
|
|
|
To fix this, you can call `Review.Test.whenFixed` on your error:
|
2019-08-22 12:57:14 +03:00
|
|
|
|
2019-09-29 00:47:02 +03:00
|
|
|
Review.Test.error
|
2019-08-22 12:57:14 +03:00
|
|
|
{ message = "<message>"
|
|
|
|
, details = "<details>"
|
|
|
|
, under = "<under>"
|
|
|
|
}
|
2019-09-29 00:47:02 +03:00
|
|
|
|> Review.Test.whenFixed "<source code>"
|
2019-08-22 12:57:14 +03:00
|
|
|
"""
|
2019-08-05 01:04:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
fixedCodeMismatchTest : Test
|
|
|
|
fixedCodeMismatchTest =
|
|
|
|
test "fixedCodeMismatch" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
sourceCode : String
|
|
|
|
sourceCode =
|
|
|
|
"""module A exposing (b)
|
|
|
|
abcd =
|
|
|
|
1"""
|
|
|
|
|
|
|
|
expectedSourceCode : String
|
|
|
|
expectedSourceCode =
|
|
|
|
"""module A exposing (b)
|
|
|
|
abcd =
|
|
|
|
2"""
|
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
in
|
|
|
|
ErrorMessage.fixedCodeMismatch
|
|
|
|
sourceCode
|
|
|
|
expectedSourceCode
|
|
|
|
error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
FIXED CODE MISMATCH
|
|
|
|
|
|
|
|
I found a different fixed source code than expected for the error with the
|
|
|
|
following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
I found the following result after the fixes have been applied:
|
|
|
|
|
|
|
|
```
|
|
|
|
module A exposing (b)
|
|
|
|
abcd =
|
|
|
|
1
|
|
|
|
```
|
|
|
|
|
|
|
|
but I was expecting:
|
|
|
|
|
|
|
|
```
|
|
|
|
module A exposing (b)
|
|
|
|
abcd =
|
|
|
|
2
|
|
|
|
```"""
|
|
|
|
|
|
|
|
|
2019-08-07 23:38:17 +03:00
|
|
|
unchangedSourceAfterFixTest : Test
|
|
|
|
unchangedSourceAfterFixTest =
|
|
|
|
test "unchangedSourceAfterFix" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
in
|
|
|
|
ErrorMessage.unchangedSourceAfterFix error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
UNCHANGED SOURCE AFTER FIX
|
|
|
|
|
|
|
|
I got something unexpected when applying the fixes provided by the error
|
|
|
|
with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
I expected the fix to make some changes to the source code, but it resulted
|
|
|
|
in the same source code as before the fixes.
|
|
|
|
|
|
|
|
This is problematic because I will tell the user that this rule provides an
|
|
|
|
automatic fix, but I will have to disappoint them when I later find out it
|
|
|
|
doesn't do anything.
|
|
|
|
|
|
|
|
Hint: Maybe you inserted an empty string into the source code."""
|
|
|
|
|
|
|
|
|
2019-08-08 00:04:41 +03:00
|
|
|
invalidSourceAfterFixTest : Test
|
|
|
|
invalidSourceAfterFixTest =
|
|
|
|
test "invalidSourceAfterFix" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
sourceCode : String
|
|
|
|
sourceCode =
|
|
|
|
"""ule A exposing (b)
|
|
|
|
abcd =
|
|
|
|
1"""
|
|
|
|
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
in
|
|
|
|
ErrorMessage.invalidSourceAfterFix
|
|
|
|
error
|
|
|
|
sourceCode
|
|
|
|
|> expectMessageEqual """
|
|
|
|
INVALID SOURCE AFTER FIX
|
|
|
|
|
|
|
|
I got something unexpected when applying the fixes provided by the error
|
|
|
|
with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
I was unable to parse the source code after applying the fixes. Here is
|
|
|
|
the result of the automatic fixing:
|
|
|
|
|
|
|
|
```
|
|
|
|
ule A exposing (b)
|
|
|
|
abcd =
|
|
|
|
1
|
|
|
|
```
|
|
|
|
|
|
|
|
This is problematic because fixes are meant to help the user, and applying
|
|
|
|
this fix will give them more work to do. After the fix has been applied,
|
|
|
|
the problem should be solved and the user should not have to think about it
|
|
|
|
anymore. If a fix can not be applied fully, it should not be applied at
|
|
|
|
all."""
|
|
|
|
|
|
|
|
|
2019-08-19 00:32:30 +03:00
|
|
|
hasCollisionsInFixRangesTest : Test
|
|
|
|
hasCollisionsInFixRangesTest =
|
|
|
|
test "hasCollisionsInFixRanges" <|
|
|
|
|
\() ->
|
|
|
|
let
|
|
|
|
error : Error
|
|
|
|
error =
|
|
|
|
Rule.error
|
|
|
|
{ message = "Some error"
|
|
|
|
, details = [ "Some details" ]
|
|
|
|
}
|
|
|
|
{ start = { row = 3, column = 1 }, end = { row = 3, column = 5 } }
|
|
|
|
in
|
|
|
|
ErrorMessage.hasCollisionsInFixRanges error
|
|
|
|
|> expectMessageEqual """
|
|
|
|
FOUND COLLISIONS IN FIX RANGES
|
|
|
|
|
|
|
|
I got something unexpected when applying the fixes provided by the error
|
|
|
|
with the following message:
|
|
|
|
|
|
|
|
`Some error`
|
|
|
|
|
|
|
|
I found that some fixes were targeting (partially or completely) the same
|
|
|
|
section of code. The problem with that is that I can't determine which fix
|
|
|
|
to apply first, and the result will be different and potentially invalid
|
|
|
|
based on the order in which I apply these fixes.
|
|
|
|
|
|
|
|
For this reason, I require that the ranges (for replacing and removing) and
|
|
|
|
the positions (for inserting) of every fix to be mutually exclusive.
|
|
|
|
|
|
|
|
Hint: Maybe you duplicated a fix, or you targetted the wrong node for one
|
|
|
|
of your fixes."""
|
|
|
|
|
|
|
|
|
2019-07-09 09:15:24 +03:00
|
|
|
dummyRange : Range
|
|
|
|
dummyRange =
|
|
|
|
{ start = { row = 2, column = 1 }, end = { row = 2, column = 5 } }
|