2017-01-16 02:51:31 +03:00
|
|
|
port module NoDebugTest exposing (all)
|
|
|
|
|
|
|
|
import Expect
|
|
|
|
import Test exposing (describe, test, Test)
|
|
|
|
import NoDebug exposing (rule)
|
|
|
|
import Types exposing (Error)
|
|
|
|
|
|
|
|
|
|
|
|
error : String -> Error
|
|
|
|
error =
|
|
|
|
Error "NoDebug"
|
|
|
|
|
|
|
|
|
|
|
|
tests : List Test
|
|
|
|
tests =
|
|
|
|
[ test "should not report normal function calls" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule """
|
2017-01-16 02:51:31 +03:00
|
|
|
a = foo n
|
|
|
|
b = bar.foo n
|
|
|
|
c = debug
|
|
|
|
e = debug.log n
|
|
|
|
d = debug.log n
|
|
|
|
"""
|
|
|
|
|> Expect.equal []
|
|
|
|
, test "should report Debug.log use" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = Debug.log"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug.log calls" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = Debug.log z"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report multiple Debug.log calls" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule """
|
2017-01-16 02:51:31 +03:00
|
|
|
a = Debug.log z
|
|
|
|
b = Debug.log z
|
|
|
|
"""
|
|
|
|
|> Expect.equal
|
|
|
|
[ error "Forbidden use of Debug"
|
|
|
|
, error "Forbidden use of Debug"
|
|
|
|
]
|
|
|
|
, test "should report Debug.crash calls" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = Debug.crash 1"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report any Debug method" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = Debug.foo 1"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in a binary expression" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = (Debug.log z) + 2"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in a << binary expression" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = fn << Debug.log"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in a pipe expression" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = fn |> Debug.log z"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in an list expression" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = [Debug.log z y]"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in an record expression" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = { foo = Debug.log z y }"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
-- elm-ast doesn't handle record update expressions
|
|
|
|
-- , test "should report Debug in an record update expression" <|
|
|
|
|
-- \() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
-- rule "a = { model | foo = Debug.log z y }"
|
2017-01-16 02:51:31 +03:00
|
|
|
-- |> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in an lambda expression" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = (\\foo -> Debug.log z foo)"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in an if expression condition" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = if Debug.log a b then True else False"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in an if expression then" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = if True then Debug.log a b else False"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in an if expression else" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule "a = if True then True else Debug.log a b"
|
2017-01-16 02:51:31 +03:00
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in a case value" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule """
|
2017-01-16 02:51:31 +03:00
|
|
|
a = case Debug.log a b of
|
|
|
|
_ -> []
|
|
|
|
"""
|
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in a case pattern" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule """
|
2017-01-16 02:51:31 +03:00
|
|
|
a = case a of
|
|
|
|
Debug.log a b -> []
|
|
|
|
"""
|
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in a case body" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule """
|
2017-01-16 02:51:31 +03:00
|
|
|
a = case a of
|
|
|
|
_ -> Debug.log a b
|
|
|
|
"""
|
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in let declaration section" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule """
|
2017-01-16 02:51:31 +03:00
|
|
|
a = let b = Debug.log a b
|
|
|
|
in b
|
|
|
|
"""
|
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
, test "should report Debug in let body" <|
|
|
|
|
\() ->
|
2017-01-16 23:40:01 +03:00
|
|
|
rule """
|
2017-01-16 02:51:31 +03:00
|
|
|
a = let b = c
|
|
|
|
in Debug.log a b
|
|
|
|
"""
|
|
|
|
|> Expect.equal [ error "Forbidden use of Debug" ]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
all =
|
|
|
|
describe "NoDebug" tests
|