/
NoTestValuesInProductionCodeTest.elm
93 lines (86 loc) · 4.08 KB
/
NoTestValuesInProductionCodeTest.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
module NoTestValuesInProductionCodeTest exposing (all)
import NoTestValuesInProductionCode exposing (rule)
import Review.Test
import Test exposing (Test, describe, test)
all : Test
all =
describe "NoTestValuesInProductionCode"
[ endsWithTest
, startsWithTest
]
endsWithTest : Test
endsWithTest =
describe "endsWith"
[ test "should report an error when using a function or value that ends with the specified suffix" <|
\() ->
"""module A exposing (..)
listTESTS_ONLY = []
value = List.map foo listTESTS_ONLY
"""
|> Review.Test.run (rule (NoTestValuesInProductionCode.endsWith "TESTS_ONLY"))
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Forbidden use of test-only value `listTESTS_ONLY` in production source code"
, details =
[ "This value was marked as being meant to only be used in test-related code, but I found it being used in code that will go to production."
, "You should either stop using it or rename it to not end with `TESTS_ONLY`."
]
, under = "listTESTS_ONLY"
}
|> Review.Test.atExactly { start = { row = 3, column = 22 }, end = { row = 3, column = 36 } }
]
, test "should not report an error when using a function or value that does not end with the specified suffix" <|
\() ->
"""module A exposing (..)
list = []
value = List.map foo list
"""
|> Review.Test.run (rule (NoTestValuesInProductionCode.endsWith "TESTS_ONLY"))
|> Review.Test.expectNoErrors
, test "should not report an error when using a test value inside another test value" <|
\() ->
"""module A exposing (..)
listTESTS_ONLY = []
valueTESTS_ONLY = List.map foo listTESTS_ONLY
"""
|> Review.Test.run (rule (NoTestValuesInProductionCode.endsWith "TESTS_ONLY"))
|> Review.Test.expectNoErrors
]
startsWithTest : Test
startsWithTest =
describe "startsWith"
[ test "should report an error when using a function or value that starts with the specified suffix" <|
\() ->
"""module A exposing (..)
tests__list = []
value = List.map foo tests__list
"""
|> Review.Test.run (rule (NoTestValuesInProductionCode.startsWith "tests__"))
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Forbidden use of test-only value `tests__list` in production source code"
, details =
[ "This value was marked as being meant to only be used in test-related code, but I found it being used in code that will go to production."
, "You should either stop using it or rename it to not start with `tests__`."
]
, under = "tests__list"
}
|> Review.Test.atExactly { start = { row = 3, column = 22 }, end = { row = 3, column = 33 } }
]
, test "should not report an error when using a function or value that does not start with the specified suffix" <|
\() ->
"""module A exposing (..)
list = []
value = List.map foo list
"""
|> Review.Test.run (rule (NoTestValuesInProductionCode.startsWith "tests__"))
|> Review.Test.expectNoErrors
, test "should not report an error when using a test value inside another test value" <|
\() ->
"""module A exposing (..)
tests__list = []
tests__value = List.map foo tests__list
"""
|> Review.Test.run (rule (NoTestValuesInProductionCode.startsWith "TESTS_ONLY"))
|> Review.Test.expectNoErrors
]