Skip to content

Commit c7d1ab9

Browse files
Adjustments to FSharp.Editor.Tests (#16258)
* * enable warning for unused values in FSharp.Editor.Tests * fix the code so it builds * reintroduce the parsing of options in CompletionProviderTests.fs / RoslynHelpers.fs despite the outcome seems a bit underwhelming
1 parent 590d596 commit c7d1ab9

File tree

7 files changed

+46
-20
lines changed

7 files changed

+46
-20
lines changed

vsintegration/tests/FSharp.Editor.Tests/BraceMatchingServiceTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type BraceMatchingServiceTests() =
3232
|> Async.RunImmediateExceptOnUI
3333
with
3434
| None -> ()
35-
| Some (left, right) -> failwith $"Found match for brace '{marker}'"
35+
| Some _ -> failwith $"Found match for brace '{marker}'"
3636

3737
member private this.VerifyBraceMatch(fileContents: string, startMarker: string, endMarker: string, ?langVersion: string) =
3838
let sourceText = SourceText.From(fileContents)

vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module CompletionProviderTests =
2929
let caretPosition = fileContents.IndexOf(marker) + marker.Length
3030

3131
let document =
32-
RoslynTestHelpers.CreateSolution(fileContents)
32+
RoslynTestHelpers.CreateSolution(fileContents, extraFSharpProjectOtherOptions = Array.ofSeq opts)
3333
|> RoslynTestHelpers.GetSingleDocument
3434

3535
let results =
@@ -77,7 +77,7 @@ module CompletionProviderTests =
7777
let caretPosition = fileContents.IndexOf(marker) + marker.Length
7878

7979
let document =
80-
RoslynTestHelpers.CreateSolution(fileContents)
80+
RoslynTestHelpers.CreateSolution(fileContents, extraFSharpProjectOtherOptions = Array.ofSeq opts)
8181
|> RoslynTestHelpers.GetSingleDocument
8282

8383
let actual =
@@ -1990,3 +1990,20 @@ match { A = 1; B = 2 } with
19901990
"""
19911991

19921992
VerifyCompletionList(fileContents, "| { f = ()", [ "A"; "B"; "C"; "D" ], [])
1993+
1994+
[<Fact>]
1995+
let ``issue #16260 [TO-BE-IMPROVED] operators are fumbling for now`` () =
1996+
let fileContents =
1997+
"""
1998+
module Ops =
1999+
let (|>>) a b = a + b
2000+
module Foo =
2001+
let (|>>) a b = a + b
2002+
Ops.Foo.()
2003+
Ops.Foo.(
2004+
Ops.(
2005+
Ops.()
2006+
"""
2007+
2008+
VerifyCompletionList(fileContents, "Ops.Foo.(", [], [ "|>>"; "(|>>)" ])
2009+
VerifyCompletionList(fileContents, "Ops.(", [], [ "|>>"; "(|>>)" ])

vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ type DocumentDiagnosticAnalyzerTests() =
1414
let startMarker = "(*start*)"
1515
let endMarker = "(*end*)"
1616

17-
let getDiagnostics (fileContents: string) =
17+
member private _.getDiagnostics(fileContents: string, ?additionalFlags) =
1818
let task =
1919
cancellableTask {
2020
let document =
21-
RoslynTestHelpers.CreateSolution(fileContents)
21+
RoslynTestHelpers.CreateSolution(fileContents, ?extraFSharpProjectOtherOptions = additionalFlags)
2222
|> RoslynTestHelpers.GetSingleDocument
2323

2424
let! syntacticDiagnostics = FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(document, DiagnosticsType.Syntax)
@@ -30,14 +30,14 @@ type DocumentDiagnosticAnalyzerTests() =
3030
task.Result
3131

3232
member private this.VerifyNoErrors(fileContents: string, ?additionalFlags: string[]) =
33-
let errors = getDiagnostics fileContents
33+
let errors = this.getDiagnostics (fileContents, ?additionalFlags = additionalFlags)
3434

3535
if not errors.IsEmpty then
3636
failwith $"There should be no errors generated: {errors}"
3737

3838
member private this.VerifyErrorAtMarker(fileContents: string, expectedMarker: string, ?expectedMessage: string) =
3939
let errors =
40-
getDiagnostics fileContents
40+
this.getDiagnostics fileContents
4141
|> Seq.filter (fun e -> e.Severity = DiagnosticSeverity.Error)
4242
|> Seq.toArray
4343

@@ -68,7 +68,7 @@ type DocumentDiagnosticAnalyzerTests() =
6868
expectedSeverity: DiagnosticSeverity
6969
) =
7070
let errors =
71-
getDiagnostics fileContents
71+
this.getDiagnostics fileContents
7272
|> Seq.filter (fun e -> e.Severity = expectedSeverity)
7373
|> Seq.toArray
7474

@@ -99,7 +99,7 @@ type DocumentDiagnosticAnalyzerTests() =
9999
) =
100100
// TODO: once workaround (https://github.com/dotnet/fsharp/pull/15982) will not be needed, this should be reverted back to normal method (see PR)
101101
let errors =
102-
getDiagnostics fileContents
102+
this.getDiagnostics fileContents
103103
|> Seq.filter (fun e -> e.Severity = expectedSeverity)
104104
|> Seq.toArray
105105

@@ -133,7 +133,7 @@ type DocumentDiagnosticAnalyzerTests() =
133133
?expectedMessage: string
134134
) =
135135
let errors =
136-
getDiagnostics fileContents
136+
this.getDiagnostics fileContents
137137
|> Seq.filter (fun e -> e.Severity = DiagnosticSeverity.Error)
138138
|> Seq.toArray
139139

vsintegration/tests/FSharp.Editor.Tests/EditorFormattingServiceTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let def =
3838
)marker4
3939
"""
4040

41-
let pasteTemplate =
41+
let _pasteTemplate =
4242
"""
4343
4444
let foo =

vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<GenerateProgramFile>false</GenerateProgramFile>
88
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
99
<NoWarn>$(NoWarn);FS3511</NoWarn> <!-- This state machine is not statically compilable. -->
10+
<OtherFlags>$(OtherFlags) --warnon:1182</OtherFlags>
11+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1012
</PropertyGroup>
1113

1214
<ItemGroup>

vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ type TestHostWorkspaceServices(hostServices: HostServices, workspace: Workspace)
188188
with _ ->
189189
Unchecked.defaultof<'T>
190190

191-
override _.FindLanguageServices(filter) = Seq.empty
191+
override _.FindLanguageServices(_filter) = Seq.empty
192192

193193
override _.GetLanguageServices(languageName) =
194194
match languageName with
@@ -275,7 +275,7 @@ type RoslynTestHelpers private () =
275275
static member SetEditorOptions (solution: Solution) options =
276276
solution.Workspace.Services.GetService<EditorOptions>().With(options)
277277

278-
static member CreateSolution(source, ?options: FSharpProjectOptions, ?editorOptions) =
278+
static member CreateSolution(source, ?options: FSharpProjectOptions, ?extraFSharpProjectOtherOptions: string array, ?editorOptions) =
279279
let projId = ProjectId.CreateNewId()
280280

281281
let docInfo = RoslynTestHelpers.CreateDocumentInfo projId "C:\\test.fs" source
@@ -284,9 +284,18 @@ type RoslynTestHelpers private () =
284284
let projInfo = RoslynTestHelpers.CreateProjectInfo projId projFilePath [ docInfo ]
285285
let solution = RoslynTestHelpers.CreateSolution [ projInfo ]
286286

287-
options
288-
|> Option.defaultValue RoslynTestHelpers.DefaultProjectOptions
289-
|> RoslynTestHelpers.SetProjectOptions projId solution
287+
let options =
288+
let options = options |> Option.defaultValue RoslynTestHelpers.DefaultProjectOptions
289+
290+
match extraFSharpProjectOtherOptions with
291+
| None
292+
| Some [||] -> options
293+
| Some otherOptions ->
294+
{ options with
295+
OtherOptions = Array.concat [| options.OtherOptions; otherOptions |]
296+
}
297+
298+
options |> RoslynTestHelpers.SetProjectOptions projId solution
290299

291300
if editorOptions.IsSome then
292301
RoslynTestHelpers.SetEditorOptions solution editorOptions.Value
@@ -352,9 +361,7 @@ type RoslynTestHelpers private () =
352361
}
353362

354363
let solution =
355-
match customEditorOptions with
356-
| Some o -> RoslynTestHelpers.CreateSolution(code, options, o)
357-
| None -> RoslynTestHelpers.CreateSolution(code, options)
364+
RoslynTestHelpers.CreateSolution(code, options, ?editorOptions = customEditorOptions)
358365

359366
solution |> RoslynTestHelpers.GetSingleDocument
360367

vsintegration/tests/FSharp.Editor.Tests/QuickInfoProviderTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module QuickInfoProviderTests =
8585
| QuickInfo _ -> QuickInfo(desc, docs)
8686
| _ -> Desc desc
8787

88-
| ToolTipElement.CompositionError (error) -> Error
88+
| ToolTipElement.CompositionError _ -> Error
8989

9090
let executeQuickInfoTest (programText: string) testCases =
9191
let document =

0 commit comments

Comments
 (0)