mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 23:05:35 +03:00
Fix tests
This commit is contained in:
parent
66f73b625c
commit
f911819796
4
elm.json
4
elm.json
@ -16,5 +16,7 @@
|
||||
"elm/regex": "1.0.0 <= v < 2.0.0",
|
||||
"stil4m/elm-syntax": "7.0.2 <= v < 8.0.0"
|
||||
},
|
||||
"test-dependencies": {}
|
||||
"test-dependencies": {
|
||||
"elm-explorations/test": "1.1.0 <= v < 2.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -62,9 +62,15 @@ expressionToVisitors node =
|
||||
FunctionOrValue _ _ ->
|
||||
[]
|
||||
|
||||
RecordExpr fields ->
|
||||
List.map (value >> (\( name, expr ) -> expr)) fields
|
||||
|
||||
RecordUpdateExpression name setters ->
|
||||
List.map (value >> (\( field, expr ) -> expr)) setters
|
||||
|
||||
ParenthesizedExpression expr ->
|
||||
[ expr ]
|
||||
|
||||
OperatorApplication operator direction left right ->
|
||||
case direction of
|
||||
Left ->
|
||||
|
@ -1,213 +0,0 @@
|
||||
module ElmTest.NoDuplicateTestBodiesTest exposing (all)
|
||||
|
||||
import Lint.Rules.ElmTest.NoDuplicateTestBodies exposing (rule)
|
||||
import Lint.Types exposing (LintError, LintResult, LintRule)
|
||||
import Test exposing (Test, describe, test)
|
||||
import TestUtil exposing (expectErrors, ruleTester)
|
||||
|
||||
|
||||
testRule : String -> LintResult
|
||||
testRule =
|
||||
ruleTester rule
|
||||
|
||||
|
||||
error : String -> LintError
|
||||
error =
|
||||
LintError "ElmTest.NoDuplicateTestBodies"
|
||||
|
||||
|
||||
tests : List Test
|
||||
tests =
|
||||
[ test "should not report non-tests" <|
|
||||
\() ->
|
||||
testRule """
|
||||
foo = [ 1, 1 ]
|
||||
bar = [ foo 2 <| 1, foo 2 <| 1 ]
|
||||
tests =
|
||||
[ fn "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, fn "bar" <|
|
||||
\\() -> 1 + 2
|
||||
|> Expect.equal 3
|
||||
]
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should not report tests that have distinct bodies" <|
|
||||
\() ->
|
||||
testRule """
|
||||
tests =
|
||||
[ test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, test "bar" <|
|
||||
\\() -> 1 + 2
|
||||
|> Expect.equal 3
|
||||
]
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should not report tests that have the same body when Test is not imported and used in list" <|
|
||||
\() ->
|
||||
testRule """
|
||||
tests =
|
||||
[ test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should report tests that have the same body when using test and exposing (test)" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test exposing (test, foo)
|
||||
tests =
|
||||
[ test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, test "baz" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors
|
||||
[ error "Test `bar` has the same body as test `foo`"
|
||||
, error "Test `baz` has the same body as test `foo`"
|
||||
]
|
||||
, test "should report tests that have the same body when using Test.test and exposing (test)" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test exposing (test, foo)
|
||||
tests =
|
||||
[ Test.test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, Test.test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors [ error "Test `bar` has the same body as test `foo`" ]
|
||||
, test "should report tests that have the same body when using test and exposing (..)" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test exposing (..)
|
||||
tests =
|
||||
[ test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors [ error "Test `bar` has the same body as test `foo`" ]
|
||||
, test "should report tests that have the same body when using Test.test and exposing (..)" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test exposing (..)
|
||||
tests =
|
||||
[ Test.test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, Test.test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors [ error "Test `bar` has the same body as test `foo`" ]
|
||||
, test "should report tests that have the same body when using Foo.test, aliasing as Foo and exposing (..)" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test as Foo exposing (..)
|
||||
tests =
|
||||
[ Foo.test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, Foo.test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors [ error "Test `bar` has the same body as test `foo`" ]
|
||||
, test "should report tests that have the same body when using Test.test without exposing anything" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test
|
||||
tests =
|
||||
[ Test.test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, Test.test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors [ error "Test `bar` has the same body as test `foo`" ]
|
||||
, test "should report tests that have the same body when using Foo.test aliasing as Foo and without exposing anything" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test as Foo
|
||||
tests =
|
||||
[ Foo.test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, Foo.test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors [ error "Test `bar` has the same body as test `foo`" ]
|
||||
, test "should not report tests that have the same body when using test and not exposing (test)" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test exposing (foo)
|
||||
tests =
|
||||
[ test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should not report tests that have the same body when using test without exposing anything" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test
|
||||
tests =
|
||||
[ test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should not report tests that have the same body when using test and aliasing as Foo without exposing anything" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Test as Foo
|
||||
tests =
|
||||
[ Test.test "foo" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
, Test.test "bar" <|
|
||||
\\() -> 1 + 1
|
||||
|> Expect.equal 2
|
||||
]
|
||||
"""
|
||||
|> expectErrors []
|
||||
]
|
||||
|
||||
|
||||
all : Test
|
||||
all =
|
||||
describe "ElmTest.NoDuplicateTestBodies" tests
|
@ -1,134 +1,137 @@
|
||||
module NoDebugTest exposing (all)
|
||||
|
||||
import Elm.Syntax.Range exposing (Location, Range)
|
||||
import Lint.Rules.NoDebug exposing (rule)
|
||||
import Lint.Types exposing (LintError, LintResult, LintRule)
|
||||
import Test exposing (Test, describe, test)
|
||||
import Test exposing (Test, describe, only, test)
|
||||
import TestUtil exposing (expectErrors, ruleTester)
|
||||
|
||||
|
||||
testRule : String -> LintResult
|
||||
testRule =
|
||||
ruleTester rule
|
||||
testRule string =
|
||||
"module A exposing (..)\n\n"
|
||||
++ string
|
||||
|> ruleTester rule
|
||||
|
||||
|
||||
error : String -> LintError
|
||||
error : String -> Range -> LintError
|
||||
error =
|
||||
LintError "NoDebug"
|
||||
|
||||
|
||||
location : Int -> Int -> Int -> Range
|
||||
location row columnStart columnEnd =
|
||||
{ start = { row = row, column = columnStart }
|
||||
, end = { row = row, column = columnEnd }
|
||||
}
|
||||
|
||||
|
||||
tests : List Test
|
||||
tests =
|
||||
[ test "should not report normal function calls" <|
|
||||
\() ->
|
||||
testRule """
|
||||
a = foo n
|
||||
b = bar.foo n
|
||||
c = debug
|
||||
e = debug.log n
|
||||
d = debug.log n
|
||||
a = foo n
|
||||
b = bar.foo n
|
||||
c = debug
|
||||
e = debug.log n
|
||||
d = debug.log n
|
||||
"""
|
||||
|> expectErrors []
|
||||
, test "should report Debug.log use" <|
|
||||
\() ->
|
||||
testRule "a = Debug.log"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 5 14) ]
|
||||
, test "should report Debug.log calls" <|
|
||||
\() ->
|
||||
testRule "a = Debug.log z"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 5 14) ]
|
||||
, test "should report multiple Debug.log calls" <|
|
||||
\() ->
|
||||
testRule """
|
||||
a = Debug.log z
|
||||
b = Debug.log z
|
||||
a = Debug.log z
|
||||
b = Debug.log z
|
||||
"""
|
||||
|> expectErrors
|
||||
[ error "Forbidden use of Debug"
|
||||
, error "Forbidden use of Debug"
|
||||
[ error "Forbidden use of Debug" (location 4 5 14)
|
||||
, error "Forbidden use of Debug" (location 5 5 14)
|
||||
]
|
||||
, test "should report Debug.crash calls" <|
|
||||
\() ->
|
||||
testRule "a = Debug.crash 1"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 5 16) ]
|
||||
, test "should report any Debug method" <|
|
||||
\() ->
|
||||
testRule "a = Debug.foo 1"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 5 14) ]
|
||||
, test "should report Debug in a binary expression" <|
|
||||
\() ->
|
||||
testRule "a = (Debug.log z) + 2"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 6 15) ]
|
||||
, test "should report Debug in a << binary expression" <|
|
||||
\() ->
|
||||
testRule "a = fn << Debug.log"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 11 20) ]
|
||||
, test "should report Debug in a pipe expression" <|
|
||||
\() ->
|
||||
testRule "a = fn |> Debug.log z"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 11 20) ]
|
||||
, test "should report Debug in an list expression" <|
|
||||
\() ->
|
||||
testRule "a = [Debug.log z y]"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 6 15) ]
|
||||
, test "should report Debug in an record expression" <|
|
||||
\() ->
|
||||
testRule "a = { foo = Debug.log z y }"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 13 22) ]
|
||||
, test "should report Debug in an record update expression" <|
|
||||
\() ->
|
||||
testRule "a = { model | foo = Debug.log z y }"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 21 30) ]
|
||||
, test "should report Debug in an lambda expression" <|
|
||||
\() ->
|
||||
testRule "a = (\\foo -> Debug.log z foo)"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 14 23) ]
|
||||
, test "should report Debug in an if expression condition" <|
|
||||
\() ->
|
||||
testRule "a = if Debug.log a b then True else False"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
, test "should report Debug in an if expression then" <|
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 8 17) ]
|
||||
, test "should report Debug in an if expression then branch" <|
|
||||
\() ->
|
||||
testRule "a = if True then Debug.log a b else False"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
, test "should report Debug in an if expression else" <|
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 18 27) ]
|
||||
, test "should report Debug in an if expression else branch" <|
|
||||
\() ->
|
||||
testRule "a = if True then True else Debug.log a b"
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 3 28 37) ]
|
||||
, test "should report Debug in a case value" <|
|
||||
\() ->
|
||||
testRule """
|
||||
a = case Debug.log a b of
|
||||
_ -> []
|
||||
a = case Debug.log a b of
|
||||
_ -> []
|
||||
"""
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
, test "should report Debug in a case pattern" <|
|
||||
\() ->
|
||||
testRule """
|
||||
a = case a of
|
||||
Debug.log a b -> []
|
||||
"""
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 4 10 19) ]
|
||||
, test "should report Debug in a case body" <|
|
||||
\() ->
|
||||
testRule """
|
||||
a = case a of
|
||||
_ -> Debug.log a b
|
||||
a = case a of
|
||||
_ -> Debug.log a b
|
||||
"""
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 5 8 17) ]
|
||||
, test "should report Debug in let declaration section" <|
|
||||
\() ->
|
||||
testRule """
|
||||
a = let b = Debug.log a b
|
||||
in b
|
||||
a = let b = Debug.log a b
|
||||
in b
|
||||
"""
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 4 13 22) ]
|
||||
, test "should report Debug in let body" <|
|
||||
\() ->
|
||||
testRule """
|
||||
a = let b = c
|
||||
in Debug.log a b
|
||||
a = let b = c
|
||||
in Debug.log a b
|
||||
"""
|
||||
|> expectErrors [ error "Forbidden use of Debug" ]
|
||||
|> expectErrors [ error "Forbidden use of Debug" (location 5 8 17) ]
|
||||
]
|
||||
|
||||
|
||||
|
@ -3,27 +3,19 @@ module TestUtil exposing (expectErrors, ruleTester)
|
||||
import Expect
|
||||
import Lint exposing (parseSource)
|
||||
import Lint.Types exposing (LintError, LintResult, LintRule)
|
||||
import Regex
|
||||
|
||||
|
||||
spacesRegex : Regex.Regex
|
||||
spacesRegex =
|
||||
Regex.regex "\n "
|
||||
|
||||
|
||||
ruleTester : LintRule -> String -> LintResult
|
||||
ruleTester rule str =
|
||||
str
|
||||
|> Regex.replace Regex.All spacesRegex (\_ -> "\n")
|
||||
|> parseSource
|
||||
parseSource str
|
||||
|> Result.map rule
|
||||
|
||||
|
||||
expectErrors : List LintError -> LintResult -> Expect.Expectation
|
||||
expectErrors expectedErrors result =
|
||||
case result of
|
||||
Err _ ->
|
||||
Expect.fail "Parsing failure"
|
||||
Err errors ->
|
||||
Expect.fail <| String.join "\n" errors
|
||||
|
||||
Ok errors ->
|
||||
Expect.equal expectedErrors errors
|
||||
|
@ -1,30 +0,0 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"../src",
|
||||
"."
|
||||
],
|
||||
"elm-version": "0.19.0",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/core": "1.0.0",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/regex": "1.0.0",
|
||||
"elm-community/list-extra": "8.1.0",
|
||||
"elm-explorations/test": "1.1.0",
|
||||
"Bogdanp/elm-ast": "8.0.3",
|
||||
"eeue56/elm-html-test": "4.1.0",
|
||||
"elm-community/parser-combinators": "1.1.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/json": "1.0.0",
|
||||
"elm/random": "1.0.0",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user