Skip to content

Commit 773bd12

Browse files
committed
Forward test logs
1 parent ae1abb6 commit 773bd12

File tree

6 files changed

+39
-36
lines changed

6 files changed

+39
-36
lines changed

src/FsAutoComplete.Core/TestServer.fs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,36 @@ module VSTestWrapper =
1212

1313
type TestProjectDll = string
1414

15-
type private TestDiscoveryHandler(notifyIncrementalUpdate: TestCase list -> unit) =
15+
type private TestDiscoveryHandler(notifyDiscoveryProgress: TestCase list -> unit) =
1616

1717
member val DiscoveredTests: TestCase ResizeArray = ResizeArray() with get, set
1818

1919
interface ITestDiscoveryEventsHandler with
2020
member this.HandleDiscoveredTests(discoveredTestCases: System.Collections.Generic.IEnumerable<TestCase>) : unit =
2121
if (not << isNull) discoveredTestCases then
2222
this.DiscoveredTests.AddRange(discoveredTestCases)
23-
notifyIncrementalUpdate (discoveredTestCases |> List.ofSeq)
23+
notifyDiscoveryProgress (discoveredTestCases |> List.ofSeq)
2424

2525
member this.HandleDiscoveryComplete
2626
(_totalTests: int64, lastChunk: System.Collections.Generic.IEnumerable<TestCase>, _isAborted: bool)
2727
: unit =
2828
if (not << isNull) lastChunk then
2929
this.DiscoveredTests.AddRange(lastChunk)
30-
notifyIncrementalUpdate (lastChunk |> List.ofSeq)
30+
notifyDiscoveryProgress (lastChunk |> List.ofSeq)
3131

3232
member this.HandleLogMessage(_level: TestMessageLevel, _message: string) : unit = ()
3333

3434
member this.HandleRawMessage(_rawMessage: string) : unit = ()
3535

3636
let discoverTestsAsync
3737
(vstestPath: string)
38-
(incrementalUpdateHandler: TestCase list -> unit)
38+
(onDiscoveryProgress: TestCase list -> unit)
3939
(sources: TestProjectDll list)
4040
: Async<TestCase list> =
4141
async {
4242
let consoleParams = ConsoleParameters()
4343
let vstest = new VsTestConsoleWrapper(vstestPath, consoleParams)
44-
let discoveryHandler = TestDiscoveryHandler(incrementalUpdateHandler)
44+
let discoveryHandler = TestDiscoveryHandler(onDiscoveryProgress)
4545

4646
use! _onCancel = Async.OnCancel(fun () -> vstest.CancelDiscovery())
4747

@@ -52,14 +52,17 @@ module VSTestWrapper =
5252
type ProcessId = int
5353
type DidDebuggerAttach = bool
5454

55-
type TestRunUpdate = Progress of TestRunChangedEventArgs
55+
type TestRunUpdate =
56+
| Progress of TestRunChangedEventArgs
57+
| LogMessage of string
5658

57-
type TestRunHandler(notifyIncrementalUpdate: TestRunUpdate -> unit) =
59+
type TestRunHandler(notifyTestRunProgress: TestRunUpdate -> unit) =
5860

5961
member val TestResults: TestResult ResizeArray = ResizeArray() with get, set
6062

6163
interface ITestRunEventsHandler with
62-
member _.HandleLogMessage(_level: TestMessageLevel, _message: string) : unit = ()
64+
member _.HandleLogMessage(level: TestMessageLevel, message: string) : unit =
65+
notifyTestRunProgress (LogMessage $"[{level}] {message}")
6366

6467
member _.HandleRawMessage(_rawMessage: string) : unit = ()
6568

@@ -72,15 +75,15 @@ module VSTestWrapper =
7275
) : unit =
7376
if ((not << isNull) lastChunkArgs && (not << isNull) lastChunkArgs.NewTestResults) then
7477
this.TestResults.AddRange(lastChunkArgs.NewTestResults)
75-
notifyIncrementalUpdate (Progress lastChunkArgs)
78+
notifyTestRunProgress (Progress lastChunkArgs)
7679

7780
member this.HandleTestRunStatsChange(testRunChangedArgs: TestRunChangedEventArgs) : unit =
7881
if
7982
((not << isNull) testRunChangedArgs
8083
&& (not << isNull) testRunChangedArgs.NewTestResults)
8184
then
8285
this.TestResults.AddRange(testRunChangedArgs.NewTestResults)
83-
notifyIncrementalUpdate (Progress testRunChangedArgs)
86+
notifyTestRunProgress (Progress testRunChangedArgs)
8487

8588
member _.LaunchProcessWithDebuggerAttached(_testProcessStartInfo: TestProcessStartInfo) : int =
8689
raise (System.NotImplementedException())
@@ -116,7 +119,7 @@ module VSTestWrapper =
116119
/// attachDebugger assumes that the debugger is attached when the method returns. The test project will continue execution as soon as attachDebugger returns
117120
let runTestsAsync
118121
(vstestPath: string)
119-
(incrementalUpdateHandler: TestRunUpdate -> unit)
122+
(onTestRunProgress: TestRunUpdate -> unit)
120123
(onAttachDebugger: ProcessId -> DidDebuggerAttach)
121124
(sources: TestProjectDll list)
122125
(testCaseFilter: string option)
@@ -125,7 +128,7 @@ module VSTestWrapper =
125128
async {
126129
let consoleParams = ConsoleParameters()
127130
let vstest = new VsTestConsoleWrapper(vstestPath, consoleParams)
128-
let runHandler = TestRunHandler(incrementalUpdateHandler)
131+
let runHandler = TestRunHandler(onTestRunProgress)
129132

130133
let options = new TestPlatformOptions()
131134
testCaseFilter |> Option.iter (TestPlatformOptions.withTestCaseFilter options)

src/FsAutoComplete/LspHelpers.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,10 @@ type TestRunRequest =
619619
type TestDiscoveryUpdateNotification = { Tests: TestServer.TestItem array }
620620

621621
type TestRunProgress =
622-
{ TestResults: TestServer.TestResult array
622+
{ TestLogs: string array
623+
TestResults: TestServer.TestResult array
623624
ActiveTests: TestServer.TestItem array }
624625

625-
type TestRunUpdateNotification = Progress of TestRunProgress
626-
627626
type ProjectParms =
628627
{
629628
/// Project file to compile

src/FsAutoComplete/LspHelpers.fsi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ type TestRunRequest =
205205
type TestDiscoveryUpdateNotification = { Tests: TestServer.TestItem array }
206206

207207
type TestRunProgress =
208-
{ TestResults: TestServer.TestResult array
208+
{ TestLogs: string array
209+
TestResults: TestServer.TestResult array
209210
ActiveTests: TestServer.TestItem array }
210211

211-
type TestRunUpdateNotification = Progress of TestRunProgress
212-
213212
type ProjectParms =
214213
{
215214
/// Project file to compile

src/FsAutoComplete/LspServers/AdaptiveServerState.fs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,12 +2588,12 @@ type AdaptiveState
25882588
testCases
25892589
|> List.choose (TestServer.TestItem.tryTestCaseToDTO projectLookup.TryFind)
25902590

2591-
let incrementalUpdateHandler (tests: Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase list) =
2591+
let onDiscoveryProgress (tests: Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase list) =
25922592
lspClient.NotifyTestDiscoveryUpdate({ Tests = tests |> tryTestCasesToDTOs |> Array.ofList })
25932593
|> Async.RunSynchronously
25942594

25952595
let! testCases =
2596-
TestServer.VSTestWrapper.discoverTestsAsync vstestBinary.FullName incrementalUpdateHandler testProjectBinaries
2596+
TestServer.VSTestWrapper.discoverTestsAsync vstestBinary.FullName onDiscoveryProgress testProjectBinaries
25972597

25982598
let testDTOs: TestServer.TestItem list = testCases |> tryTestCasesToDTOs
25992599

@@ -2625,20 +2625,24 @@ type AdaptiveState
26252625

26262626
use! _onCancel = Async.OnCancel(fun _ -> tokenSource.Cancel())
26272627

2628-
let incrementalUpdateHandler (runUpdate: TestServer.VSTestWrapper.TestRunUpdate) =
2628+
let onTestRunProgress (runUpdate: TestServer.VSTestWrapper.TestRunUpdate) =
26292629
let dto =
26302630
match runUpdate with
26312631
| TestServer.VSTestWrapper.TestRunUpdate.Progress progress ->
2632-
TestRunUpdateNotification.Progress
2633-
{ TestResults = progress.NewTestResults |> List.ofSeq |> tryTestResultsToDTOs |> Array.ofSeq
2634-
ActiveTests =
2635-
progress.ActiveTests
2636-
|> Seq.choose (TestServer.TestItem.tryTestCaseToDTO projectLookup.TryFind)
2637-
|> Array.ofSeq }
2632+
{ TestLogs = [||]
2633+
TestResults = progress.NewTestResults |> List.ofSeq |> tryTestResultsToDTOs |> Array.ofSeq
2634+
ActiveTests =
2635+
progress.ActiveTests
2636+
|> Seq.choose (TestServer.TestItem.tryTestCaseToDTO projectLookup.TryFind)
2637+
|> Array.ofSeq }
2638+
| TestServer.VSTestWrapper.TestRunUpdate.LogMessage message ->
2639+
{ TestLogs = [| message |]
2640+
TestResults = [||]
2641+
ActiveTests = [||] }
26382642

26392643
Async.RunSynchronously(async { do! lspClient.NotifyTestRunUpdate(dto) }, cancellationToken = tokenSource.Token)
26402644

2641-
let attachDebugger (processId: int) : bool =
2645+
let onAttachDebugger (processId: int) : bool =
26422646
let result =
26432647
Async.RunSynchronously(lspClient.AttachDebuggerForTestRun(processId), cancellationToken = tokenSource.Token)
26442648

@@ -2655,8 +2659,8 @@ type AdaptiveState
26552659
let! testResults =
26562660
TestServer.VSTestWrapper.runTestsAsync
26572661
vstestBinary.FullName
2658-
incrementalUpdateHandler
2659-
attachDebugger
2662+
onTestRunProgress
2663+
onAttachDebugger
26602664
testProjectBinaries
26612665
testCaseFilter
26622666
shouldDebug

src/FsAutoComplete/LspServers/FSharpLspClient.fs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ type FSharpLspClient(sendServerNotification: ClientNotificationSender, sendServe
6666
sendServerNotification "test/testDiscoveryUpdate" (box { Content = JsonSerializer.writeJson p })
6767
|> Async.Ignore
6868

69-
member __.NotifyTestRunUpdate(p: TestRunUpdateNotification) =
70-
match p with
71-
| Progress progress ->
72-
sendServerNotification "test/testRunProgressUpdate" (box { Content = JsonSerializer.writeJson progress })
73-
|> Async.Ignore
69+
member __.NotifyTestRunUpdate(p: TestRunProgress) =
70+
sendServerNotification "test/testRunProgressUpdate" (box { Content = JsonSerializer.writeJson p })
71+
|> Async.Ignore
7472

7573
member __.AttachDebuggerForTestRun(processId: int) : AsyncLspResult<bool> =
7674
sendServerRequest.Send "test/processWaitingForDebugger" (box { Content = string processId })

src/FsAutoComplete/LspServers/FSharpLspClient.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type FSharpLspClient =
3333
member NotifyDocumentAnalyzed: p: DocumentAnalyzedNotification -> Async<unit>
3434
member NotifyTestDetected: p: TestDetectedNotification -> Async<unit>
3535
member NotifyTestDiscoveryUpdate: p: TestDiscoveryUpdateNotification -> Async<unit>
36-
member NotifyTestRunUpdate: p: TestRunUpdateNotification -> Async<unit>
36+
member NotifyTestRunUpdate: p: TestRunProgress -> Async<unit>
3737
member AttachDebuggerForTestRun: processId: int -> AsyncLspResult<bool>
3838
member CodeLensRefresh: unit -> Async<unit>
3939
override WindowWorkDoneProgressCreate: WorkDoneProgressCreateParams -> AsyncLspResult<unit>

0 commit comments

Comments
 (0)