Skip to content

Commit

Permalink
try runtime-aided directory lookup instead of __SOURCE_DIRECTORY__
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Jan 29, 2023
1 parent ded6244 commit 392f30f
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let tests state =
// requires `fsi` and corresponding `fs` file (and a project!)
// -> cannot use untitled doc
// -> use existing files, but load with text specified in tests
let path = Path.Combine(__SOURCE_DIRECTORY__, @"../TestCases/CodeFixTests/RenameParamToMatchSignature/")
let path = Path.Combine(File.CurrentDir(), @"../TestCases/CodeFixTests/RenameParamToMatchSignature/")
let (fsiFile, fsFile) = ("Code.fsi", "Code.fs")

serverTestList (nameof RenameParamToMatchSignature) state defaultConfigDto (Some path) (fun server -> [
Expand Down
9 changes: 5 additions & 4 deletions test/FsAutoComplete.Tests.Lsp/CompletionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ open FsAutoComplete.Utils
open FsAutoComplete.Lsp
open FsToolkit.ErrorHandling
open Utils.Server
open Utils.Utils

let tests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "Completion")
let path = Path.Combine(File.CurrentDir(), "TestCases", "Completion")
let! (server, events) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing events
let path = Path.Combine(path, "Script.fsx")
Expand Down Expand Up @@ -212,7 +213,7 @@ let tests state =
let autocompleteTest state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "AutocompleteTest")
let path = Path.Combine(File.CurrentDir(), "TestCases", "AutocompleteTest")
let! (server, event) = serverInitialize path defaultConfigDto state
let projectPath = Path.Combine(path, "AutocompleteTest.fsproj")
do! waitForWorkspaceFinishedParsing event
Expand All @@ -226,7 +227,7 @@ let autocompleteTest state =

let scriptServer =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "AutocompleteScriptTest")
let path = Path.Combine(File.CurrentDir(), "TestCases", "AutocompleteScriptTest")
let! (server, event) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing event
let path = Path.Combine(path, "Script.fsx")
Expand Down Expand Up @@ -379,7 +380,7 @@ let autocompleteTest state =

let autoOpenTests state =
let dirPath =
Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "CompletionAutoOpenTests")
Path.Combine(File.CurrentDir(), "TestCases", "CompletionAutoOpenTests")

let serverFor (scriptPath: string) =
async {
Expand Down
10 changes: 5 additions & 5 deletions test/FsAutoComplete.Tests.Lsp/CoreTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let initTests createServer =

let p: InitializeParams =
{ ProcessId = Some 1
RootPath = Some __SOURCE_DIRECTORY__
RootPath = Some (File.CurrentDir())
RootUri = None
InitializationOptions = Some(Server.serialize defaultConfigDto)
Capabilities = Some clientCaps
Expand Down Expand Up @@ -105,7 +105,7 @@ let initTests createServer =
let documentSymbolTest state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "DocumentSymbolTest")
let path = Path.Combine(File.CurrentDir(), "TestCases", "DocumentSymbolTest")
let! (server, event) = serverInitialize path defaultConfigDto state
let path = Path.Combine(path, "Script.fsx")
let tdop: DidOpenTextDocumentParams = { TextDocument = loadDocument path }
Expand Down Expand Up @@ -139,7 +139,7 @@ let documentSymbolTest state =
let foldingTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "FoldingTests")
let path = Path.Combine(File.CurrentDir(), "TestCases", "FoldingTests")

let! (server, event) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing event
Expand Down Expand Up @@ -190,7 +190,7 @@ let tooltipTests state =

let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "Tooltips")
let path = Path.Combine(File.CurrentDir(), "TestCases", "Tooltips")
let scriptPath = Path.Combine(path, "Script.fsx")
let! (server, events) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing events
Expand Down Expand Up @@ -359,7 +359,7 @@ let tooltipTests state =

let closeTests state =
// Note: clear diagnostics also implies clear caches (-> remove file & project options from State).
let root = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "CloseTests")
let root = Path.Combine(File.CurrentDir(), "TestCases", "CloseTests")
let workspace = Path.Combine(root, "Workspace")

serverTestList "close tests" state defaultConfigDto (Some workspace) (fun server ->
Expand Down
19 changes: 10 additions & 9 deletions test/FsAutoComplete.Tests.Lsp/DependentFileCheckingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ open Utils.Server
open System
open FSharp.Control.Reactive
open FSharpx.Control
open Utils.Utils

let tests state =
let root = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "DependentFileChecking", "SameProject")
let root = Path.Combine(File.CurrentDir(), "TestCases", "DependentFileChecking", "SameProject")
let aFile, bFile = "A.fs", "B.fs"
testList (nameof DependentFileChecking) [
// Separate server for each test
Expand All @@ -29,10 +30,10 @@ let tests state =
// make a change to A (that is clearly incorrect)
let! startAChange = Document.changeTextTo "farts" aDoc |> Async.StartChild
// start listening for new diagnostics for B
let! diagnosticsForBWaiter =
bDiagsStream
|> Observable.timeoutSpan (TimeSpan.FromSeconds 15.)
|> Async.AwaitObservable
let! diagnosticsForBWaiter =
bDiagsStream
|> Observable.timeoutSpan (TimeSpan.FromSeconds 15.)
|> Async.AwaitObservable
|> Async.StartChild
let! aDiags = startAChange
Expect.isNonEmpty aDiags $"Should have had some compilation errors for {aFile} after erroneous changes"
Expand All @@ -55,11 +56,11 @@ let tests state =
// make a change to A (that is clearly incorrect)
let! startAChange = Document.changeTextTo "farts" aDoc |> Async.StartChild
// start listening for new diagnostics for B
let! diagnosticsForBWaiter =
bDiagsStream
let! diagnosticsForBWaiter =
bDiagsStream
|> Observable.skip i
|> Observable.timeoutSpan (TimeSpan.FromSeconds 15.)
|> Async.AwaitObservable
|> Observable.timeoutSpan (TimeSpan.FromSeconds 15.)
|> Async.AwaitObservable
|> Async.StartChild
let! aDiags = startAChange
Expect.isNonEmpty aDiags $"Should have had some compilation errors for {aFile} after erroneous change #%d{i}"
Expand Down
3 changes: 2 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/DetectUnitTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ open FsAutoComplete
open FsAutoComplete.LspHelpers
open Helpers
open FsToolkit.ErrorHandling
open Utils.Utils

let tests state =
let geTestNotification projectFolder fileName =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", projectFolder)
let path = Path.Combine(File.CurrentDir(), "TestCases", projectFolder)
let! server, events = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing events
let path = Path.Combine(path, fileName)
Expand Down
12 changes: 6 additions & 6 deletions test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ open FsAutoComplete
open FsAutoComplete.LspHelpers
open Helpers
open FsAutoComplete.Lsp

open Utils.Utils

let fsdnTest state =

let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "FsdnTest")
let path = Path.Combine(File.CurrentDir(), "TestCases", "FsdnTest")
let! (server, event) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing event
return server
Expand Down Expand Up @@ -90,7 +90,7 @@ let uriTests =
let linterTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "LinterTest")
let path = Path.Combine(File.CurrentDir(), "TestCases", "LinterTest")
let! (server, events) = serverInitialize path { defaultConfigDto with Linter = Some true } state
let path = Path.Combine(path, "Script.fsx")
let tdop: DidOpenTextDocumentParams = { TextDocument = loadDocument path }
Expand Down Expand Up @@ -240,7 +240,7 @@ let linterTests state =
let formattingTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "Formatting")
let path = Path.Combine(File.CurrentDir(), "TestCases", "Formatting")
let! (server, events) = serverInitialize path defaultConfigDto state
do! dotnetToolRestore path // need to restore CLI tools in order to use fantomas
return server, events, path
Expand Down Expand Up @@ -298,7 +298,7 @@ let formattingTests state =
let analyzerTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "Analyzers")
let path = Path.Combine(File.CurrentDir(), "TestCases", "Analyzers")
// because the analyzer is a project this project has a reference, the analyzer can be
// found in alongside this project, so we can use the directory this project is in
let analyzerPath =
Expand Down Expand Up @@ -356,7 +356,7 @@ let analyzerTests state =
let signatureTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "Signature")
let path = Path.Combine(File.CurrentDir(), "TestCases", "Signature")
let scriptPath = Path.Combine(path, "Script.fsx")
let! (server, events) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing events
Expand Down
3 changes: 2 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/FindReferencesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ open System.IO
open FsAutoComplete
open Helpers
open Ionide.LanguageServerProtocol.Types
open Utils.Utils

let tests state =
testList
"Find All References tests"
[ let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "FindReferences")
let path = Path.Combine(File.CurrentDir(), "TestCases", "FindReferences")

let! (server, event) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing event
Expand Down
4 changes: 2 additions & 2 deletions test/FsAutoComplete.Tests.Lsp/GoToTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open Utils.TextEdit
let private gotoTest state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "GoToTests")
let path = Path.Combine(File.CurrentDir(), "TestCases", "GoToTests")

let! (server, event) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing event
Expand Down Expand Up @@ -489,7 +489,7 @@ let private gotoTest state =
let private scriptGotoTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "GoToTests")
let path = Path.Combine(File.CurrentDir(), "TestCases", "GoToTests")
let! (server, event) = serverInitialize path defaultConfigDto state
do! waitForWorkspaceFinishedParsing event
let scriptPath = Path.Combine(path, "Script.fsx")
Expand Down
3 changes: 2 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/HighlightingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ open Helpers
open FsAutoComplete.LspHelpers
open Ionide.LanguageServerProtocol.Types
open FsAutoComplete.Utils
open Utils.Utils

let tests state =
let testPath = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "HighlightingTest")
let testPath = Path.Combine(File.CurrentDir(), "TestCases", "HighlightingTest")
let scriptPath = Path.Combine(testPath, "Script.fsx")

let server =
Expand Down
3 changes: 2 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/InfoPanelTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ open Ionide.LanguageServerProtocol.Types
open FsAutoComplete
open Helpers
open FsToolkit.ErrorHandling
open Utils.Utils

let docFormattingTest state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "FormattedDocumentation")
let path = Path.Combine(File.CurrentDir(), "TestCases", "FormattedDocumentation")
let config = defaultConfigDto
let! (server, events) = serverInitialize path config state
let path = Path.Combine(path, "Script.fsx")
Expand Down
6 changes: 3 additions & 3 deletions test/FsAutoComplete.Tests.Lsp/RenameTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let private normalizePathCasing =
let tests state =
let sameProjectTests =
let testDir =
Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "RenameTest", "SameProject")
Path.Combine(File.CurrentDir(), "TestCases", "RenameTest", "SameProject")

serverTestList "Within Same Project" state defaultConfigDto (Some testDir) (fun server ->
[ testCaseAsync
Expand Down Expand Up @@ -141,7 +141,7 @@ let tests state =
NewName = newName
}
let! res = doc.Server.Server.TextDocumentRename p
let edits =
let edits =
match res with
| Result.Error e -> failtestf "Request failed: %A" e
| Result.Ok None -> failtest "Request none"
Expand Down Expand Up @@ -219,7 +219,7 @@ let tests state =
let server =
async {
let testDir =
Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "RenameTest", "CrossProject")
Path.Combine(File.CurrentDir(), "TestCases", "RenameTest", "CrossProject")

let! (server, event) = serverInitialize testDir defaultConfigDto state
do! waitForWorkspaceFinishedParsing event
Expand Down
9 changes: 5 additions & 4 deletions test/FsAutoComplete.Tests.Lsp/ScriptTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ open FsToolkit.ErrorHandling
open FSharpx.Control.Observable
open FSharp.Control.Reactive
open System
open Utils.Utils

let scriptPreviewTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "PreviewScriptFeatures")
let path = Path.Combine(File.CurrentDir(), "TestCases", "PreviewScriptFeatures")

let scriptPath = Path.Combine(path, "Script.fsx")

Expand Down Expand Up @@ -45,7 +46,7 @@ let scriptPreviewTests state =
let scriptEvictionTests state =
let server =
async {
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "ScriptEviction")
let path = Path.Combine(File.CurrentDir(), "TestCases", "ScriptEviction")

let scriptPath = Path.Combine(path, "Script.fsx")
let! (server, events) = serverInitialize path defaultConfigDto state
Expand Down Expand Up @@ -94,7 +95,7 @@ let dependencyManagerTests state =
let server =
async {
let workingDir =
Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "DependencyManagement")
Path.Combine(File.CurrentDir(), "TestCases", "DependencyManagement")

let dependencyManagerAssemblyDir =
Path.Combine(
Expand Down Expand Up @@ -152,7 +153,7 @@ let scriptProjectOptionsCacheTests state =
let server =
async {
let workingDir =
Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "ScriptProjectOptsCache")
Path.Combine(File.CurrentDir(), "TestCases", "ScriptProjectOptsCache")

let previewEnabledConfig =
{ defaultConfigDto with FSIExtraParameters = Some [| "--langversion:preview" |] }
Expand Down
2 changes: 1 addition & 1 deletion test/FsAutoComplete.Tests.Lsp/UnsedDeclarationsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ let private scriptTests state =
])

let private projectTests state =
let path = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "UnusedDeclarations")
let path = Path.Combine(File.CurrentDir(), "TestCases", "UnusedDeclarations")
let file = Existing "Library.fs"

let config = {
Expand Down
4 changes: 2 additions & 2 deletions test/FsAutoComplete.Tests.Lsp/Utils/Server.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ let tests state = testList (nameof(Server)) [

testList "with root path" [
let inTestCases name =
System.IO.Path.Combine(__SOURCE_DIRECTORY__, "..", "TestCases", "ServerTests", name)
System.IO.Path.Combine(File.CurrentDir(), "..", "TestCases", "ServerTests", name)
|> Some

let noAnalyzersConfig =
Expand Down Expand Up @@ -592,7 +592,7 @@ f2 "bar" |> ignore
serverTestList "no root path without analyzers" state defaultConfigDto None (fun server -> [
testCaseAsync "can create Document by absolute path without root path" <| async {
let relativePath = "../TestCases/ServerTests/JustScript/Script.fsx"
let absolutePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(__SOURCE_DIRECTORY__, relativePath))
let absolutePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(File.CurrentDir(), relativePath))
let! (doc, _) = server |> Server.openDocument absolutePath
use doc = doc
()
Expand Down
Loading

0 comments on commit 392f30f

Please sign in to comment.