Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Apr 15, 2024
1 parent 4efc41a commit b846ac3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,7 @@ let private removeUnnecessaryParenthesesTests state =
""" ])

let tests textFactory state =
testSequenced <|
testList
"CodeFix-tests"
[ HelpersTests.tests textFactory
Expand Down
10 changes: 7 additions & 3 deletions test/FsAutoComplete.Tests.Lsp/CompletionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) ]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) ]
3 changes: 2 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/EmptyFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ let tests state =
let server1 = createServer()
let server2 = createServer()

testList
testSequenced
<| testList
"empty file features"
[ testList
"tests"
Expand Down
37 changes: 27 additions & 10 deletions test/FsAutoComplete.Tests.Lsp/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/RenameTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/FsAutoComplete.Tests.Lsp/SnapshotTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ let createProjectA (projects : FileInfo seq) (loader : IWorkspaceLoader) onLoadC

loadedProjectsA


let normalizeUntag = normalizePath >> UMX.untag


let snapshotTests loaders toolsPath =
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit b846ac3

Please sign in to comment.