From b846ac37aed19184eaf777af4ffb66a95d17f202 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 15 Apr 2024 09:48:50 -0400 Subject: [PATCH] fixup tests --- .../RenameParamToMatchSignatureTests.fs | 2 +- .../CodeFixTests/Tests.fs | 1 + .../CompletionTests.fs | 10 +++-- .../EmptyFileTests.fs | 3 +- test/FsAutoComplete.Tests.Lsp/Helpers.fs | 37 ++++++++++++++----- test/FsAutoComplete.Tests.Lsp/RenameTests.fs | 1 - .../FsAutoComplete.Tests.Lsp/SnapshotTests.fs | 10 ++--- 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/test/FsAutoComplete.Tests.Lsp/CodeFixTests/RenameParamToMatchSignatureTests.fs b/test/FsAutoComplete.Tests.Lsp/CodeFixTests/RenameParamToMatchSignatureTests.fs index e4f01db14..4f2adf744 100644 --- a/test/FsAutoComplete.Tests.Lsp/CodeFixTests/RenameParamToMatchSignatureTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CodeFixTests/RenameParamToMatchSignatureTests.fs @@ -33,7 +33,7 @@ let tests state = let! (fsiDoc, diags) = server |> Server.openDocumentWithText fsiFile fsiSource use _fsiDoc = fsiDoc - Expect.isEmpty diags "There should be no diagnostics in fsi doc" + Expect.isEmpty diags $"There should be no diagnostics in fsi doc %A{diags}" let! (fsDoc, diags) = server |> Server.openDocumentWithText fsFile fsSource use fsDoc = fsDoc diff --git a/test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs b/test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs index 456f73bce..2f0e6435a 100644 --- a/test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs @@ -3384,6 +3384,7 @@ let private removeUnnecessaryParenthesesTests state = """ ]) let tests textFactory state = + testSequenced <| testList "CodeFix-tests" [ HelpersTests.tests textFactory diff --git a/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs b/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs index 5fd468981..4dd5203f3 100644 --- a/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs @@ -716,7 +716,8 @@ let autocompleteTest state = Expect.exists res.Items (fun n -> n.Label = "Baz") "Autocomplete contains given symbol" }) ] - testList + testSequenced + <| testList "Autocomplete Tests" [ testList "Autocomplete within project files" (makeAutocompleteTestList server) testList "Autocomplete within script files" (makeAutocompleteTestList scriptServer) ] @@ -781,7 +782,9 @@ let autoOpenTests state = let (|ContainsOpenAction|_|) (codeActions: CodeAction[]) = codeActions - |> Array.tryFind (fun ca -> ca.Kind = Some "quickfix" && ca.Title.StartsWith("open ", StringComparison.Ordinal)) + |> Array.tryFind (fun ca -> + ca.Kind = Some "quickfix" + && ca.Title.StartsWith("open ", StringComparison.Ordinal)) match! server.TextDocumentCodeAction p with | Error e -> return failtestf "Quick fix Request failed: %A" e @@ -1093,7 +1096,8 @@ let fullNameExternalAutocompleteTest state = Expect.isSome n "Completion doesn't exist" Expect.equal n.Value.InsertText (Some "Result") "Autocomplete contains given symbol") ] - testList + testSequenced + <| testList "fullNameExternalAutocompleteTest Tests" [ testList "fullNameExternalAutocompleteTest within project files" (makeAutocompleteTestList server) testList "fullNameExternalAutocompleteTest within script files" (makeAutocompleteTestList scriptServer) ] diff --git a/test/FsAutoComplete.Tests.Lsp/EmptyFileTests.fs b/test/FsAutoComplete.Tests.Lsp/EmptyFileTests.fs index e5095e16e..1e13a6c35 100644 --- a/test/FsAutoComplete.Tests.Lsp/EmptyFileTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/EmptyFileTests.fs @@ -26,7 +26,8 @@ let tests state = let server1 = createServer() let server2 = createServer() - testList + testSequenced + <| testList "empty file features" [ testList "tests" diff --git a/test/FsAutoComplete.Tests.Lsp/Helpers.fs b/test/FsAutoComplete.Tests.Lsp/Helpers.fs index 9cc715411..84e3d95d9 100644 --- a/test/FsAutoComplete.Tests.Lsp/Helpers.fs +++ b/test/FsAutoComplete.Tests.Lsp/Helpers.fs @@ -57,7 +57,7 @@ module Expecto = let ptestCaseAsync = ptestCaseAsyncWithTimeout DEFAULT_TIMEOUT let ftestCaseAsync = ptestCaseAsyncWithTimeout DEFAULT_TIMEOUT -let rec private copyDirectory (sourceDir : DirectoryInfo) destDir = +let rec private copyDirectory (sourceDir: DirectoryInfo) destDir = // Get the subdirectories for the specified directory. // let dir = DirectoryInfo(sourceDir) @@ -82,18 +82,16 @@ let rec private copyDirectory (sourceDir : DirectoryInfo) destDir = copyDirectory dir tempPath) type DisposableDirectory(directory: string, deleteParentDir) = - static member Create(?name : string) = + static member Create(?name: string) = let tempPath, deleteParentDir = match name with - | Some name -> - IO.Path.GetTempPath() Guid.NewGuid().ToString("n") name, true - | None -> - IO.Path.Combine(IO.Path.GetTempPath(), Guid.NewGuid().ToString("n")), false + | Some name -> IO.Path.GetTempPath() Guid.NewGuid().ToString("n") name, true + | None -> IO.Path.Combine(IO.Path.GetTempPath(), Guid.NewGuid().ToString("n")), false // printfn "Creating directory %s" tempPath IO.Directory.CreateDirectory tempPath |> ignore new DisposableDirectory(tempPath, deleteParentDir) - static member From (sourceDir: DirectoryInfo) = + static member From(sourceDir: DirectoryInfo) = let self = DisposableDirectory.Create(sourceDir.Name) copyDirectory sourceDir self.DirectoryInfo.FullName self @@ -108,8 +106,21 @@ type DisposableDirectory(directory: string, deleteParentDir) = else x.DirectoryInfo - // printfn "Deleting directory %s" dirToDelete.FullName - IO.Directory.Delete(dirToDelete.FullName, true) + let mutable attempts = 5 + + while attempts > 0 do + try + // Handle odd cases with windows file locking + IO.Directory.Delete(dirToDelete.FullName, true) + attempts <- 0 + with _ -> + attempts <- attempts - 1 + if attempts = 0 then + reraise () + Thread.Sleep(15) + + + type Async = /// Behaves like AwaitObservable, but calls the specified guarding function @@ -700,7 +711,13 @@ let diagnosticsToResult = let waitForParseResultsForFile file = fileDiagnostics file >> diagnosticsToResult >> Async.AwaitObservable -let waitForDiagnosticErrorForFile file = fileDiagnostics file >> Observable.choose (function | [||] -> None | diags -> Some diags) >> diagnosticsToResult >> Async.AwaitObservable +let waitForDiagnosticErrorForFile file = + fileDiagnostics file + >> Observable.choose (function + | [||] -> None + | diags -> Some diags) + >> diagnosticsToResult + >> Async.AwaitObservable let waitForFsacDiagnosticsForFile file = fsacDiagnostics file >> diagnosticsToResult >> Async.AwaitObservable diff --git a/test/FsAutoComplete.Tests.Lsp/RenameTests.fs b/test/FsAutoComplete.Tests.Lsp/RenameTests.fs index e9ba9e8b7..671adcc2a 100644 --- a/test/FsAutoComplete.Tests.Lsp/RenameTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/RenameTests.fs @@ -291,7 +291,6 @@ let private crossProjectTests state = { TextDocument = { Uri = normalizePathCasing usageFile } Position = { Line = 6; Character = 28 } NewName = "sup" } - let! res = server.TextDocumentRename(renameHelloUsageInUsageFile) match res with diff --git a/test/FsAutoComplete.Tests.Lsp/SnapshotTests.fs b/test/FsAutoComplete.Tests.Lsp/SnapshotTests.fs index 86aeca94d..63fd20e9e 100644 --- a/test/FsAutoComplete.Tests.Lsp/SnapshotTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/SnapshotTests.fs @@ -98,7 +98,7 @@ let createProjectA (projects : FileInfo seq) (loader : IWorkspaceLoader) onLoadC loadedProjectsA - +let normalizeUntag = normalizePath >> UMX.untag let snapshotTests loaders toolsPath = @@ -283,8 +283,8 @@ let snapshotTests loaders toolsPath = Expect.equal ls1.ProjectId ls2.ProjectId "Project Id name should be the same" Expect.equal ls1.SourceFiles.Length 3 "Source files length should be 3" Expect.equal ls1.SourceFiles.Length ls2.SourceFiles.Length "Source files length should be the same" - let ls1File = ls1.SourceFiles |> Seq.find (fun x -> x.FileName = libraryFile.FullName) - let ls2File = ls2.SourceFiles |> Seq.find (fun x -> x.FileName = libraryFile.FullName) + let ls1File = ls1.SourceFiles |> Seq.find (fun x -> x.FileName = normalizeUntag libraryFile.FullName) + let ls2File = ls2.SourceFiles |> Seq.find (fun x -> x.FileName = normalizeUntag libraryFile.FullName) Expect.notEqual ls1File.Version ls2File.Version "Library source file version should not be the same" Expect.equal ls1.ReferencedProjects.Length ls2.ReferencedProjects.Length "Referenced projects length should be the same" Expect.equal ls1.ReferencedProjects.Length 0 "Referenced projects length should be 0" @@ -298,8 +298,8 @@ let snapshotTests loaders toolsPath = Expect.equal cs1.SourceFiles.Length 3 "Source files length should be 3" Expect.equal cs1.SourceFiles.Length cs2.SourceFiles.Length "Source files length should be the same" let consoleFile = Projects.MultiProjectScenario1.Console1.programFileIn dDir.DirectoryInfo - let cs1File = cs1.SourceFiles |> Seq.find (fun x -> x.FileName = consoleFile.FullName) - let cs2File = cs2.SourceFiles |> Seq.find (fun x -> x.FileName = consoleFile.FullName) + let cs1File = cs1.SourceFiles |> Seq.find (fun x -> x.FileName = normalizeUntag consoleFile.FullName) + let cs2File = cs2.SourceFiles |> Seq.find (fun x -> x.FileName = normalizeUntag consoleFile.FullName) Expect.equal cs1File.Version cs2File.Version "Console source file version should be the same" Expect.equal cs1.ReferencedProjects.Length cs2.ReferencedProjects.Length "Referenced projects length should be the same" Expect.equal cs1.ReferencedProjects.Length 1 "Referenced projects length should be 1"