@@ -13,6 +13,30 @@ let basePath = TestContext.CurrentContext.TestDirectory </> ".." </> ".." </> ".
1313let fsharpLintConsoleDll = basePath </> " src" </> " FSharpLint.Console" </> " bin" </> " Release" </> " net6.0" </> " dotnet-fsharplint.dll"
1414let fsharpConsoleOutputDir = Path.GetFullPath ( Path.GetDirectoryName( fsharpLintConsoleDll))
1515
16+ [<RequireQualifiedAccess>]
17+ type ToolStatus = | Available | NotAvailable
18+ type ToolLocationOverride ( toolStatus : ToolStatus ) =
19+ let tempFolder = Path.GetTempFileName()
20+
21+ do match toolStatus with
22+ | ToolStatus.Available -> Environment.SetEnvironmentVariable( " FSHARPLINT_SEARCH_PATH_OVERRIDE" , fsharpConsoleOutputDir)
23+ | ToolStatus.NotAvailable ->
24+ let path = Environment.GetEnvironmentVariable( " PATH" )
25+ // ensure bin dir is not in path
26+ if path.Contains( fsharpConsoleOutputDir, StringComparison.InvariantCultureIgnoreCase) then
27+ Assert.Inconclusive()
28+
29+ File.Delete( tempFolder)
30+ Directory.CreateDirectory( tempFolder) |> ignore
31+
32+ // set search path to an empty dir
33+ Environment.SetEnvironmentVariable( " FSHARPLINT_SEARCH_PATH_OVERRIDE" , tempFolder)
34+
35+ interface IDisposable with
36+ member this.Dispose () =
37+ if File.Exists tempFolder then
38+ File.Delete tempFolder
39+
1640let runVersionCall filePath ( service : FSharpLintService ) =
1741 async {
1842 let request =
@@ -24,55 +48,46 @@ let runVersionCall filePath (service: FSharpLintService) =
2448 }
2549 |> Async.RunSynchronously
2650
27- // ensure current FSharpLint.Console output is in PATH so it can use its daemon if needed
28- let ensureDaemonPath wantBuiltDaemon =
29- let path = Environment.GetEnvironmentVariable( " PATH" )
30- if wantBuiltDaemon then
31- if not <| path.Contains( fsharpConsoleOutputDir, StringComparison.InvariantCultureIgnoreCase) then
32- Environment.SetEnvironmentVariable( " PATH" , $" {fsharpConsoleOutputDir}:{path})" )
33- else if path.Contains( fsharpConsoleOutputDir, StringComparison.InvariantCultureIgnoreCase) then
34- Assert.Inconclusive()
35-
3651[<Test>]
3752let TestDaemonNotFound () =
38- ensureDaemonPath false
39-
40- let testHintsFile = basePath </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHints.fs"
41- let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
42- let versionResponse = runVersionCall testHintsFile fsharpLintService
53+ using ( new ToolLocationOverride( ToolStatus.NotAvailable)) <| fun _ ->
4354
44- Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.ToolNotFound, versionResponse.Code)
55+ let testHintsFile = basePath </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHints.fs"
56+ let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
57+ let versionResponse = runVersionCall testHintsFile fsharpLintService
58+
59+ Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.ToolNotFound, versionResponse.Code)
4560
4661[<Test>]
4762let TestDaemonVersion () =
48- ensureDaemonPath true
63+ using ( new ToolLocationOverride ( ToolStatus.Available )) <| fun _ ->
4964
50- let testHintsFile = basePath </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHints.fs"
51- let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
52- let versionResponse = runVersionCall testHintsFile fsharpLintService
65+ let testHintsFile = basePath </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHints.fs"
66+ let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
67+ let versionResponse = runVersionCall testHintsFile fsharpLintService
5368
54- match versionResponse.Result with
55- | Content result -> Assert.IsFalse ( String.IsNullOrWhiteSpace result)
56- // | _ -> Assert.Fail("Response should be a version number")
69+ match versionResponse.Result with
70+ | Content result -> Assert.IsFalse ( String.IsNullOrWhiteSpace result)
71+ // | _ -> Assert.Fail("Response should be a version number")
5772
58- Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.Version, versionResponse.Code)
73+ Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.Version, versionResponse.Code)
5974
6075[<Test>]
6176let TestFilePathShouldBeAbsolute () =
62- ensureDaemonPath true
77+ using ( new ToolLocationOverride ( ToolStatus.Available )) <| fun _ ->
6378
64- let testHintsFile = " .." </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHints.fs"
65- let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
66- let versionResponse = runVersionCall testHintsFile fsharpLintService
67-
68- Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.FilePathIsNotAbsolute, versionResponse.Code)
79+ let testHintsFile = " .." </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHints.fs"
80+ let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
81+ let versionResponse = runVersionCall testHintsFile fsharpLintService
82+
83+ Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.FilePathIsNotAbsolute, versionResponse.Code)
6984
7085[<Test>]
7186let TestFileShouldExists () =
72- ensureDaemonPath true
87+ using ( new ToolLocationOverride ( ToolStatus.Available )) <| fun _ ->
7388
74- let testHintsFile = basePath </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHintsOOOPS.fs"
75- let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
76- let versionResponse = runVersionCall testHintsFile fsharpLintService
77-
78- Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.FileNotFound, versionResponse.Code)
89+ let testHintsFile = basePath </> " tests" </> " FSharpLint.FunctionalTest.TestedProject" </> " FSharpLint.FunctionalTest.TestedProject.NetCore" </> " TestHintsOOOPS.fs"
90+ let fsharpLintService : FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
91+ let versionResponse = runVersionCall testHintsFile fsharpLintService
92+
93+ Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.FileNotFound, versionResponse.Code)
0 commit comments