Skip to content

Commit 252dd09

Browse files
committed
fix tests
1 parent b3b9e2f commit 252dd09

File tree

2 files changed

+64
-151
lines changed

2 files changed

+64
-151
lines changed

tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/CompilationTests.fs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ type Method =
1212

1313
let methodOptions (method: Method) =
1414
match method with
15-
| Method.Sequential -> []
16-
| Method.Graph -> [ "--test:GraphBasedChecking"; "--test:DumpCheckingGraph" ]
15+
| Method.Sequential -> ["--parallelcompilation-"]
16+
| Method.Graph -> ["--test:DumpCheckingGraph"]
1717

1818
let withMethod (method: Method) (cu: CompilationUnit) : CompilationUnit =
1919
match cu with
@@ -24,7 +24,7 @@ let withMethod (method: Method) (cu: CompilationUnit) : CompilationUnit =
2424
}
2525
| cu -> cu
2626

27-
let compileAValidScenario (scenario: Scenario) (method: Method) =
27+
let compileScenario (scenario: Scenario) (method: Method) =
2828
let cUnit =
2929
let files =
3030
scenario.Files
@@ -36,21 +36,44 @@ let compileAValidScenario (scenario: Scenario) (method: Method) =
3636
let f = fsFromString first |> FS
3737
f |> withAdditionalSourceFiles rest
3838

39+
let dir = TestFramework.createTemporaryDirectory()
40+
41+
printfn "Compiling scenario '%s' \nin directory %s" scenario.Name dir.FullName
42+
3943
cUnit
44+
|> withName scenario.Name
45+
|> withOutputDirectory (Some dir)
46+
|> ignoreWarnings
4047
|> withOutputType CompileOutput.Library
4148
|> withMethod method
4249
|> compile
43-
|> shouldSucceed
44-
|> ignore
4550

4651
let scenarios = scenarios |> List.map (fun c -> [| box c |])
4752

4853
[<Theory>]
4954
[<MemberData(nameof scenarios)>]
5055
let ``Compile a valid scenario using graph-based type-checking`` (scenario) =
51-
compileAValidScenario scenario Method.Graph
56+
compileScenario scenario Method.Graph
57+
|> shouldSucceed
58+
|> ignore
5259

5360
[<Theory>]
5461
[<MemberData(nameof scenarios)>]
5562
let ``Compile a valid scenario using sequential type-checking`` (scenario) =
56-
compileAValidScenario scenario Method.Sequential
63+
compileScenario scenario Method.Sequential
64+
|> shouldSucceed
65+
|> ignore
66+
67+
[<Fact>]
68+
let ``Compile misordered scenario using graph-based type-checking fails`` () =
69+
compileScenario misorderedScenario Method.Graph
70+
|> shouldFail
71+
|> withErrorCodes [238; 248]
72+
|> ignore
73+
74+
[<Fact>]
75+
let ``Compile misordered scenario using sequential type-checking fails`` () =
76+
compileScenario misorderedScenario Method.Sequential
77+
|> shouldFail
78+
|> withErrorCodes [238; 248]
79+
|> ignore

tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/Scenarios.fs

Lines changed: 34 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,148 +1085,38 @@ module Y = global.Z.N
10851085
"""
10861086
(set [| 0 |])
10871087
]
1088-
// New scenario: signature file erroneously follows implementation
1089-
// We add a backward link from implementation to signature, to correctly trigger
1090-
// FS0238 (implementation already given).
10911088

1092-
scenario
1093-
"Signature file follows implementation"
1094-
[
1095-
sourceFile
1096-
"A.fs"
1097-
"""
1098-
module A
1099-
1100-
let a x = x + 1
1101-
"""
1102-
Set.empty
1103-
sourceFile
1104-
"B.fs"
1105-
"""
1106-
module B
1107-
1108-
let b = A.a 42
1109-
"""
1110-
(set [| 0 |])
1111-
sourceFile
1112-
"A.fsi"
1113-
"""
1114-
module A
1115-
1116-
val a: int -> int
1117-
"""
1118-
(set [| 0 |])
1119-
]
1120-
1121-
// The .fsx script is placed in-between files to enforce a linear graph up to the script.
1122-
// After the script, normal dependency resolution resumes.
1123-
1124-
scenario
1125-
"Script file uses modules across signatures (script in-between)"
1126-
[
1127-
// 0
1128-
sourceFile
1129-
"A.fsi"
1130-
"""
1131-
module A
1132-
1133-
type AType = class end
1134-
"""
1135-
Set.empty
1136-
1137-
// 1
1138-
sourceFile
1139-
"A.fs"
1140-
"""
1141-
module A
1142-
1143-
type AType = class end
1144-
"""
1145-
(set [| 0 |]) // sequential: depends on previous file due to script later
1146-
1147-
// 2
1148-
sourceFile
1149-
"B.fsi"
1150-
"""
1151-
module B
1152-
1153-
open A
1154-
1155-
val b: AType -> unit
1156-
"""
1157-
(set [| 1 |]) // sequential
1158-
1159-
// 3
1160-
sourceFile
1161-
"B.fs"
1162-
"""
1163-
module B
1164-
1165-
open A
1166-
1167-
let b (a: AType) = ()
1168-
"""
1169-
(set [| 2 |]) // sequential
1170-
1171-
// 4 (script in-between)
1172-
sourceFile
1173-
"Script.fsx"
1174-
"""
1175-
open A
1176-
open B
1177-
1178-
let run (a: A.AType) =
1179-
B.b a
1180-
"""
1181-
(set [| 3 |]) // sequential
1182-
1183-
// 5
1184-
sourceFile
1185-
"C.fsi"
1186-
"""
1187-
module C
1188-
1189-
type CType = class end
1190-
"""
1191-
Set.empty
1192-
1193-
// 6
1194-
sourceFile
1195-
"C.fs"
1196-
"""
1197-
module C
1198-
1199-
type CType = class end
1200-
"""
1201-
(set [| 5 |]) // normal deps: impl to own signature
1202-
1203-
// 7
1204-
sourceFile
1205-
"D.fsi"
1206-
"""
1207-
module D
1208-
1209-
open A
1210-
open C
1211-
1212-
val d: CType -> unit
1213-
"""
1214-
(set [| 0; 5 |]) // normal deps: opens A (A.fsi=0) and C (C.fsi=5)
1215-
1216-
// 8
1217-
sourceFile
1218-
"D.fs"
1219-
"""
1220-
module D
1221-
1222-
open A
1223-
open B
1224-
open C
1225-
1226-
let d (c: CType) =
1227-
let a: AType = failwith "todo"
1228-
b a
1229-
"""
1230-
(set [| 0; 2; 5; 7 |]) // normal deps: A.fsi=0, B.fsi=2, C.fsi=5, plus own D.fsi=7
1231-
]
1232-
]
1089+
]
1090+
1091+
let internal misorderedScenario =
1092+
// New scenario: signature file erroneously follows implementation
1093+
// We add a backward link from implementation to signature, to correctly trigger
1094+
// FS0238 (implementation already given).
1095+
scenario
1096+
"Signature file follows implementation"
1097+
[
1098+
sourceFile
1099+
"A.fs"
1100+
"""
1101+
module A
1102+
1103+
let a x = x + 1
1104+
"""
1105+
Set.empty
1106+
sourceFile
1107+
"B.fs"
1108+
"""
1109+
module B
1110+
1111+
let b = A.a 42
1112+
"""
1113+
(set [| 0 |])
1114+
sourceFile
1115+
"A.fsi"
1116+
"""
1117+
module A
1118+
1119+
val a: int -> int
1120+
"""
1121+
(set [| 0 |])
1122+
]

0 commit comments

Comments
 (0)