From 6614d677b686c610aa209d8a9ca38d3baf87fcdb Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 2 Jun 2023 16:50:35 +0200 Subject: [PATCH] Add test to make sure files only have access to the files they requested --- .../Rule/WithArbitraryFilesVisitorTest.elm | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/Review/Rule/WithArbitraryFilesVisitorTest.elm b/tests/Review/Rule/WithArbitraryFilesVisitorTest.elm index 1ca47119..1ca33a1a 100644 --- a/tests/Review/Rule/WithArbitraryFilesVisitorTest.elm +++ b/tests/Review/Rule/WithArbitraryFilesVisitorTest.elm @@ -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