Skip to content

Commit 311e7dd

Browse files
committed
Finish unit test cleanup
1 parent 6d3d3cc commit 311e7dd

File tree

14 files changed

+211
-259
lines changed

14 files changed

+211
-259
lines changed

src/Compiler/Driver/ParseAndCheckInputs.fsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ val CheckOneInput':
194194
Cancellable<TcState -> PartialResult * TcState>
195195

196196

197+
val CheckMultipleInputsInParallel :
198+
(CompilationThreadToken * (unit -> bool) * TcConfig * TcImports * TcGlobals * LongIdent option * TcState * (PhasedDiagnostic -> PhasedDiagnostic) * ParsedInput list)
199+
-> PartialResult list * TcState
200+
197201
/// Finish the checking of multiple inputs
198202
val CheckMultipleInputsFinish:
199203
(TcEnv * TopAttribs * 'T option * 'U) list * TcState -> (TcEnv * TopAttribs * 'T list * 'U list) * TcState

tests/FSharp.Test.Utilities/Compiler.fs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,18 @@ module rec Compiler =
463463
| CS cs -> CS { cs with LangVersion = ver }
464464
| _ -> failwith "Only supported in C#"
465465

466-
let asLibrary (cUnit: CompilationUnit) : CompilationUnit =
467-
match cUnit with
468-
| FS fs -> FS { fs with OutputType = CompileOutput.Library }
469-
| _ -> failwith "TODO: Implement asLibrary where applicable."
470-
471-
let asExe (cUnit: CompilationUnit) : CompilationUnit =
466+
let withOutputType (outputType : CompileOutput) (cUnit: CompilationUnit) : CompilationUnit =
472467
match cUnit with
473-
| FS x -> FS { x with OutputType = Exe }
474-
| CS x -> CS { x with OutputType = Exe }
468+
| FS x -> FS { x with OutputType = outputType }
469+
| CS x -> CS { x with OutputType = outputType }
475470
| _ -> failwith "TODO: Implement where applicable."
476471

472+
let asLibrary (cUnit: CompilationUnit) : CompilationUnit =
473+
withOutputType CompileOutput.Library cUnit
474+
475+
let asExe (cUnit: CompilationUnit) : CompilationUnit =
476+
withOutputType CompileOutput.Exe cUnit
477+
477478
let withPlatform (platform:ExecutionPlatform) (cUnit: CompilationUnit) : CompilationUnit =
478479
match cUnit with
479480
| FS _ ->

tests/ParallelTypeCheckingTests/Big.fs

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/ParallelTypeCheckingTests/ParallelTypeCheckingTests.fsproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@
3939
<Compile Include="Code/ParallelTypeChecking.fs" />
4040
<Compile Include="Tests\TestASTVisit.fs" />
4141
<Compile Include="Tests\TestDepResolving.fs" />
42-
<Compile Include="Tests\RunCompiler.fs" />
4342
<Compile Include="Tests\Utils.fs" />
44-
<Compile Include="Tests\ParallelCheckingWithSignatureFilesTests.fs" />
45-
<Compile Include="Tests\Diamonds.fs" />
43+
<Compile Include="Tests\GraphResolvingAndProcessing.fs" />
44+
<Compile Include="Tests\CompilationTests.fs" />
4645
<Content Include="Tests\DiamondArgs.txt" />
4746
<Content Include="Tests\FCSArgs.txt" />
47+
<Compile Include="Tests\CompilationFromArgsTests.fs" />
48+
<Compile Include="Tests\Setup.fs" />
4849
<Compile Include="Program.fs" />
49-
<None Include="Big.fs">
50-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
51-
</None>
5250
<Content Include="Docs.md" />
5351
</ItemGroup>
5452
<ItemGroup>
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
module FSharp.Compiler.Service.Tests2.Program
1+
module ParallelTypeCheckingTests.Program
22
#nowarn "1182"
3-
open System
4-
open FSharp.Compiler
5-
open FSharp.Compiler.Service.Tests
6-
open ParallelTypeCheckingTests.Tests.Utils
3+
open ParallelTypeCheckingTests.Utils
74

8-
let parse (argv: string[]): Args =
5+
let _parse (argv: string[]): Args =
96
let parseMode (mode : string) =
107
match mode.ToLower() with
118
| "sequential" -> Method.Sequential
@@ -30,32 +27,6 @@ let parse (argv: string[]): Args =
3027
WorkingDir = workingDir
3128
}
3229

33-
let setupArgsMethod (method: Method) (args: string[]): string[] =
34-
printfn $"Method: {method}"
35-
match method with
36-
| Method.Sequential ->
37-
args
38-
| Method.ParallelFs ->
39-
Array.append args [|"--test:ParallelCheckingWithSignatureFilesOn"|]
40-
| Method.Graph ->
41-
ParseAndCheckInputs.CheckMultipleInputsInParallel2 <- ParallelTypeChecking.Real.CheckMultipleInputsInParallel
42-
Array.append args [|"--test:ParallelCheckingWithSignatureFilesOn"|]
43-
| Method.Nojaf ->
44-
ParseAndCheckInputs.CheckMultipleInputsInParallel2 <- ParallelTypeChecking.Nojaf.CheckMultipleInputsInParallel
45-
Array.append args [|"--test:ParallelCheckingWithSignatureFilesOn"|]
46-
47-
let setupParsed config =
48-
let {Path = path; Mode = mode; WorkingDir = workingDir} = config
49-
let args = System.IO.File.ReadAllLines(path)
50-
printfn $"WorkingDir = {workingDir}"
51-
let args = setupArgsMethod mode args
52-
workingDir |> Option.iter (fun dir -> Environment.CurrentDirectory <- dir)
53-
args
54-
5530
[<EntryPoint>]
56-
let main argv =
57-
//let args = System.IO.File.ReadAllLines(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.Service.Tests2\DiamondArgs.txt")
58-
let config = parse argv
59-
let args = setupParsed config
60-
use tracerProvider = setupOtel()
61-
CommandLineMain.main args
31+
let main _argv =
32+
0
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module ParallelTypeCheckingTests.CompilationFromArgsTests
2+
3+
open NUnit.Framework
4+
open System
5+
open FSharp.Compiler
6+
open FSharp.Compiler.Service.Tests
7+
open NUnit.Framework
8+
open Utils
9+
10+
let configs =
11+
let workDir = @"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests"
12+
let path = $@"C:\projekty\fsharp\heuristic\tests\ParallelTypeCheckingTests\ComponentTests_args.txt"
13+
methods
14+
|> List.map (fun method ->
15+
{
16+
Path = path
17+
WorkingDir = Some workDir
18+
Mode = method
19+
}
20+
)
21+
22+
let setupArgsMethod (method: Method) (args: string[]): string[] =
23+
printfn $"Method: {method}"
24+
match method with
25+
| Method.Sequential ->
26+
// Restore default
27+
ParseAndCheckInputs.CheckMultipleInputsInParallel2 <- ParseAndCheckInputs.CheckMultipleInputsInParallel
28+
args
29+
| Method.ParallelFs ->
30+
ParseAndCheckInputs.CheckMultipleInputsInParallel2 <- ParseAndCheckInputs.CheckMultipleInputsInParallel
31+
Array.append args [|"--test:ParallelCheckingWithSignatureFilesOn"|]
32+
| Method.Graph ->
33+
ParseAndCheckInputs.CheckMultipleInputsInParallel2 <- ParallelTypeChecking.Real.CheckMultipleInputsInParallel
34+
Array.append args [|"--test:ParallelCheckingWithSignatureFilesOn"|]
35+
| Method.Nojaf ->
36+
ParseAndCheckInputs.CheckMultipleInputsInParallel2 <- ParallelTypeChecking.Nojaf.CheckMultipleInputsInParallel
37+
Array.append args [|"--test:ParallelCheckingWithSignatureFilesOn"|]
38+
39+
let setupParsed config =
40+
let {Path = path; Mode = mode; WorkingDir = workingDir} = config
41+
let args = System.IO.File.ReadAllLines(path)
42+
printfn $"WorkingDir = {workingDir}"
43+
let args = setupArgsMethod mode args
44+
workingDir |> Option.iter (fun dir -> Environment.CurrentDirectory <- dir)
45+
args
46+
47+
[<TestCaseSource(nameof(configs))>]
48+
let TestCompilerFromArgs (config : Args) : unit =
49+
let args = setupParsed config
50+
let exit = CommandLineMain.main args
51+
Assert.That(exit, Is.Zero)
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
module ParallelTypeCheckingTests.CompilationTests
2+
3+
open FSharp.Test
4+
open NUnit.Framework
5+
open FSharp.Test.Compiler
6+
open ParallelTypeCheckingTests.Utils
7+
8+
type OutputType =
9+
| Exe
10+
| Library
11+
12+
module Codebases =
13+
let encodeDecodeSimple =
14+
[
15+
"Encode.fsi",
16+
"""
17+
module Encode
18+
19+
val encode: obj -> string
20+
"""
21+
22+
"Encode.fs",
23+
"""
24+
module Encode
25+
26+
let encode (v: obj) : string = failwith "todo"
27+
"""
28+
29+
"Decode.fsi",
30+
"""
31+
module Decode
32+
33+
val decode: string -> obj
34+
"""
35+
36+
"Decode.fs",
37+
"""
38+
module Decode
39+
40+
let decode (v: string) : obj = failwith "todo"
41+
"""
42+
43+
"Program.fs", "printfn \"Hello from F#\""
44+
]
45+
46+
let diamondBroken1 =
47+
[
48+
"A.fs", """
49+
module A
50+
let a = 1
51+
"""
52+
"B.fsi", """
53+
module B
54+
open A
55+
val b : int
56+
"""
57+
"B.fs", """
58+
module B
59+
let b = 1 + A.a
60+
"""
61+
"C.fs", """
62+
namespace N.M.K
63+
module Y2 = let y = 4
64+
"""
65+
"D.fs", """
66+
namespace N.M.K
67+
module Y3 = let y = 5
68+
"""
69+
"E.fs", """
70+
namespace N.M.K
71+
module Y4 =
72+
let y = 6
73+
"""
74+
]
75+
76+
let all =
77+
[
78+
encodeDecodeSimple, CompileOutput.Exe
79+
diamondBroken1, CompileOutput.Library
80+
]
81+
82+
type Case =
83+
{
84+
Files : (string * string) list
85+
OutputType : CompileOutput
86+
Method : Method
87+
}
88+
89+
let cases : Case list =
90+
methods
91+
|> List.allPairs Codebases.all
92+
|> List.map (fun ((a, t), b) -> {Files = a; OutputType = t; Method = b})
93+
94+
[<TestCaseSource(nameof(cases))>]
95+
let ``Compile all codebase examples with all methods`` (x : Case) =
96+
makeCompilationUnit x.Files
97+
|> withOutputType x.OutputType
98+
|> setupCompilationMethod x.Method
99+
|> compile
100+
|> shouldSucceed
101+
|> ignore

tests/ParallelTypeCheckingTests/Tests/Diamonds.fs

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)