@@ -13,6 +13,30 @@ let basePath = TestContext.CurrentContext.TestDirectory </> ".." </> ".." </> ".
13
13
let fsharpLintConsoleDll = basePath </> " src" </> " FSharpLint.Console" </> " bin" </> " Release" </> " net6.0" </> " dotnet-fsharplint.dll"
14
14
let fsharpConsoleOutputDir = Path.GetFullPath ( Path.GetDirectoryName( fsharpLintConsoleDll))
15
15
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
+
16
40
let runVersionCall filePath ( service : FSharpLintService ) =
17
41
async {
18
42
let request =
@@ -24,55 +48,46 @@ let runVersionCall filePath (service: FSharpLintService) =
24
48
}
25
49
|> Async.RunSynchronously
26
50
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
-
36
51
[<Test>]
37
52
let 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 _ ->
43
54
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)
45
60
46
61
[<Test>]
47
62
let TestDaemonVersion () =
48
- ensureDaemonPath true
63
+ using ( new ToolLocationOverride ( ToolStatus.Available )) <| fun _ ->
49
64
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
53
68
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")
57
72
58
- Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.Version, versionResponse.Code)
73
+ Assert.AreEqual( LanguagePrimitives.EnumToValue FSharpLintResponseCode.Version, versionResponse.Code)
59
74
60
75
[<Test>]
61
76
let TestFilePathShouldBeAbsolute () =
62
- ensureDaemonPath true
77
+ using ( new ToolLocationOverride ( ToolStatus.Available )) <| fun _ ->
63
78
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)
69
84
70
85
[<Test>]
71
86
let TestFileShouldExists () =
72
- ensureDaemonPath true
87
+ using ( new ToolLocationOverride ( ToolStatus.Available )) <| fun _ ->
73
88
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