-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathDependentFileCheckingTests.fs
115 lines (112 loc) · 5.5 KB
/
DependentFileCheckingTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module rec FsAutoComplete.Tests.DependentFileChecking
open Expecto
open Utils.ServerTests
open Helpers
open System.IO
open Utils.Tests
open Utils.Server
open System
open FSharp.Control.Reactive
open FSharpx.Control
open Helpers.Expecto.ShadowedTimeouts
let (</>) (path1 : string) path2 = Path.Join(path1, path2)
let tests state =
let sameProjectRoot = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "DependentFileChecking", "SameProject")
let crossProjectRoot tfm = Path.Combine(__SOURCE_DIRECTORY__, "TestCases", "DependentFileChecking", $"CrossProject-{tfm}")
let tfms = [
#if NET8_0_OR_GREATER
"net8.0"
#endif
#if NET9_0_OR_GREATER
"net9.0"
#endif
]
let aFile, bFile = "A.fs", "B.fs"
testList (nameof DependentFileChecking) [
testList "SameProject" [
// Separate server for each test
// Otherwise share diag stream -> second test must skip diags of first tests. But only when first test runs (-> running all tests vs. running test alone)
serverTestList "single" state defaultConfigDto (Some sameProjectRoot) (fun server -> [
testCaseAsync "When A is modified B is re-checked" (async {
// open the files as they are on-disk and verify things are good
let! (aDoc, aDiags) = Server.openDocument aFile server
let! (bDoc, bDiags) = Server.openDocument bFile server
use aDoc = aDoc
use bDoc = bDoc
Expect.isEmpty aDiags $"There should be no diagnostics in {aFile}"
Expect.isEmpty bDiags $"There should be no diagnostics in {bFile}"
let bDiagsStream = bDoc.CompilerDiagnostics
// make a change to A (that is clearly incorrect)
let! startAChange = Document.saveText "farts" aDoc |> Async.StartChild
// start listening for new diagnostics for B
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"
// observe that compilation errors are reported for B
let! bDiags = diagnosticsForBWaiter
Expect.isNonEmpty bDiags $"Should have some compilation errors for {bFile} after erroneous change to {aFile}"
})
])
serverTestList "multi" state defaultConfigDto (Some sameProjectRoot) (fun server -> [
testCaseAsync "When A is modified repeatedly, B is re-checked after each modification" (async {
// open the files as they are on-disk and verify things are good
let! (aDoc, aDiags) = Server.openDocument aFile server
let! (bDoc, bDiags) = Server.openDocument bFile server
use aDoc = aDoc
use bDoc = bDoc
Expect.isEmpty aDiags $"There should be no diagnostics in {aFile}"
Expect.isEmpty bDiags $"There should be no diagnostics in {bFile}"
let bDiagsStream = bDoc.CompilerDiagnostics
for i in 0..10 do
// make a change to A (that is clearly incorrect)
let! startAChange = Document.saveText "farts" aDoc |> Async.StartChild
// start listening for new diagnostics for B
let! diagnosticsForBWaiter =
bDiagsStream
|> Observable.skip i
|> 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}"
// observe that compilation errors are reported for B
let! bDiags = diagnosticsForBWaiter
Expect.isNonEmpty bDiags $"Should have some compilation errors for {bFile} after erroneous change #%d{i} to {aFile}"
})
])
]
for tfm in tfms do
let crossProject = crossProjectRoot tfm
let aFile, bFile = Path.Join("Library1" </> "A.fs"), ("App" </> "B.fs")
testList $"CrossProject-{tfm}" [
serverTestList "single" state defaultConfigDto (Some crossProject) (fun server -> [
testCaseAsync "When A is modified B is re-checked" (async {
// open the files as they are on-disk and verify things are good
let! (aDoc, aDiags) = Server.openDocument aFile server
let! (bDoc, bDiags) = Server.openDocument bFile server
use aDoc = aDoc
use bDoc = bDoc
Expect.isEmpty aDiags $"There should be no diagnostics in {aFile}"
Expect.isEmpty bDiags $"There should be no diagnostics in {bFile}"
let bDiagsStream = bDoc.CompilerDiagnostics
// make a change to A (that is clearly incorrect)
let! startAChange = Document.saveText "farts" aDoc |> Async.StartChild
// start listening for new diagnostics for B
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"
// observe that compilation errors are reported for B
let! bDiags = diagnosticsForBWaiter
Expect.isNonEmpty bDiags $"Should have some compilation errors for {bFile} after erroneous change to {aFile}"
})
])
]
]