Add test to make sure files only have access to the files they requested

This commit is contained in:
Jeroen Engels 2023-06-02 16:50:35 +02:00
parent 7935afd767
commit 6614d677b6

View File

@ -55,6 +55,37 @@ a = 1
, details = [ "foo/some-file.css" ]
}
]
, test "visitors should only have access to files they requested" <|
\() ->
let
project : Project
project =
createProject
[ { path = "a.txt", content = "A" }
, { path = "b.txt", content = "B" }
, { path = "c.txt", content = "C" }
]
rule : Rule
rule =
createRule
(Rule.withArbitraryFilesModuleVisitor [ "a.txt", "c.txt" ] (reportsFileNames "A")
>> Rule.withArbitraryFilesModuleVisitor [ "b.txt" ] (reportsFileNames "B")
)
in
"""module A exposing (a)
a = 1
"""
|> Review.Test.runWithProjectData project rule
|> Review.Test.expectGlobalErrors
[ { message = "Found these files"
, details =
[ "Visitor B saw file b.txt"
, "Visitor A saw file a.txt"
, "Visitor A saw file c.txt"
]
}
]
]
@ -76,6 +107,11 @@ arbitraryFilesModuleVisitor files context =
List.map .path files ++ context
reportsFileNames : String -> List { path : String, content : String } -> Context -> Context
reportsFileNames prefix files context =
List.map (\file -> "Visitor " ++ prefix ++ " saw file " ++ file.path) files ++ context
finalEvaluation : Context -> List (Error scope)
finalEvaluation context =
[ Rule.globalError