Skip to content

Commit d0dfdb9

Browse files
authored
FsharpSuite.tests reduction diet (#14590)
* Porting selected fsharpsuite tests to ComponentTests without fsc.exe/ dotnet.exe process invocations
1 parent c263094 commit d0dfdb9

File tree

25 files changed

+1438
-1089
lines changed

25 files changed

+1438
-1089
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ stages:
441441
- checkout: self
442442
clean: true
443443
- script: ./eng/cibuild.sh --configuration $(_BuildConfig) --testcoreclr
444+
env:
445+
COMPlus_DefaultStackSize: 1000000
444446
displayName: Build / Test
445447
- task: PublishTestResults@2
446448
displayName: Publish Test Results

tests/FSharp.Compiler.ComponentTests/Conformance/LexicalFiltering/OffsideExceptions/OffsideExceptions.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ namespace FSharp.Compiler.ComponentTests.Conformance.LexicalFiltering.Basic
55
open Xunit
66
open FSharp.Test
77
open FSharp.Test.Compiler
8+
open FSharp.Test.Compiler.Assertions.StructuredResultsAsserts
89

910
module OffsideExceptions =
11+
1012
type FileAttribute(file) =
1113
inherit DirectoryAttribute(__SOURCE_DIRECTORY__, Includes=[|file|])
1214

tests/FSharp.Compiler.ComponentTests/EmittedIL/Enums.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace FSharp.Compiler.ComponentTests.EmittedIL
44

55
open Xunit
66
open FSharp.Test.Compiler
7+
open FSharp.Test.Compiler.Assertions.StructuredResultsAsserts
78

89
module Enums =
910

tests/FSharp.Compiler.ComponentTests/EmittedIL/Literals.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace FSharp.Compiler.ComponentTests.EmittedIL
44

55
open Xunit
66
open FSharp.Test.Compiler
7+
open FSharp.Test.Compiler.Assertions.StructuredResultsAsserts
78

89
module ``Literals`` =
910

tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace FSharp.Compiler.ComponentTests.ErrorMessages
44

55
open Xunit
66
open FSharp.Test.Compiler
7+
open FSharp.Test.Compiler.Assertions.StructuredResultsAsserts
78

89
module ``Unsupported Attributes`` =
910

tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@
226226
<Compile Include="Miscellaneous\ListLiterals.fs" />
227227
<Compile Include="Miscellaneous\SemanticClassificationKeyBuilder.fs" />
228228
<Compile Include="Miscellaneous\XmlDoc.fs" />
229+
<Compile Include="Miscellaneous\FsharpSuiteMigrated.fs" />
230+
<Compile Include="Miscellaneous\MigratedCoreTests.fs" />
231+
<Compile Include="Miscellaneous\MigratedOverloadTests.fs" />
232+
<Compile Include="Miscellaneous\MigratedTypeCheckTests.fs" />
229233
<Compile Include="Miscellaneous\GraphTests.fs" />
230234
<Compile Include="Signatures\TestHelpers.fs" />
231235
<Compile Include="Signatures\ModuleOrNamespaceTests.fs" />

tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressionTests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module FSharp.Compiler.ComponentTests.Language.SequenceExpressionTests
44

55
open Xunit
66
open FSharp.Test.Compiler
7+
open FSharp.Test.ScriptHelpers
78

89

9-
10-
let fsiSession = getSessionForEval()
10+
let fsiSession = getSessionForEval [||] LangVersion.Preview
1111

1212
let runCode = evalInSharedSession fsiSession
1313

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.ComponentTests.Miscellaneous.FsharpSuiteMigrated
4+
5+
open System
6+
open System.IO
7+
open Xunit
8+
open FSharp.Test
9+
open FSharp.Test.Compiler
10+
open FSharp.Test.ScriptHelpers
11+
12+
13+
14+
module Configuration =
15+
let supportedNames = set ["testlib.fsi";"testlib.fs";"test.mli";"test.ml";"test.fsi";"test.fs";"test2.fsi";"test2.fs";"test.fsx";"test2.fsx"]
16+
17+
module ScriptRunner =
18+
open Internal.Utilities.Library
19+
20+
let private createEngine(args,version) =
21+
let scriptingEnv = getSessionForEval args version
22+
scriptingEnv.Eval """
23+
let errorStringWriter = new System.IO.StringWriter()
24+
let oldConsoleError = System.Console.Error
25+
System.Console.SetError(errorStringWriter)
26+
let exit (code:int) =
27+
System.Console.SetError(oldConsoleError)
28+
if code=0 then
29+
()
30+
else failwith $"Script called function 'exit' with code={code} and collected in stderr: {errorStringWriter.ToString()}" """ |> ignore
31+
scriptingEnv
32+
33+
let defaultDefines =
34+
[
35+
#if NETCOREAPP
36+
"NETCOREAPP"
37+
#endif
38+
]
39+
40+
let runScriptFile version (cu:CompilationUnit) =
41+
let cu = cu |> withDefines defaultDefines
42+
match cu with
43+
| FS fsSource ->
44+
File.Delete("test.ok")
45+
let engine = createEngine (fsSource.Options |> Array.ofList,version)
46+
let res = evalScriptFromDiskInSharedSession engine cu
47+
match res with
48+
| CompilationResult.Failure _ -> res
49+
| CompilationResult.Success s ->
50+
if File.Exists("test.ok") then
51+
res
52+
else
53+
failwith $"Results looked correct, but 'test.ok' file was not created. Result: %A{s}"
54+
55+
| _ -> failwith $"Compilation unit other than fsharp is not supported, cannot process %A{cu}"
56+
57+
/// This test file was created by porting over (slower) FsharpSuite.Tests
58+
/// In order to minimize human error, the test definitions have been copy-pasted and this adapter provides implementations of the test functions
59+
module TestFrameworkAdapter =
60+
open FSharp.Test.Compiler.Assertions.TextBasedDiagnosticAsserts
61+
62+
type ExecutionMode =
63+
| FSC_DEBUG
64+
| FSC_OPTIMIZED
65+
| FSI
66+
| COMPILED_EXE_APP
67+
| NEG_TEST_BUILD of testName:string
68+
69+
let baseFolder = Path.Combine(__SOURCE_DIRECTORY__,"..","..","fsharp") |> Path.GetFullPath
70+
71+
let diffNegativeBaseline (cr:CompilationUnit) absFolder testName _version =
72+
let expectedFiles = Directory.GetFiles(absFolder, testName + ".*")
73+
let baselines =
74+
[ for f in expectedFiles do
75+
match Path.GetExtension(f) with
76+
| ".bsl" -> cr, f
77+
| ".vsbsl" -> cr |> withOptions ["--test:ContinueAfterParseFailure"], f
78+
| _ -> () ]
79+
[ for compilationUnit,baseline in baselines do
80+
compilationUnit
81+
|> typecheck
82+
|> withResultsMatchingFile baseline ]
83+
|> List.head
84+
85+
86+
let adjustVersion version bonusArgs =
87+
match version with
88+
| LangVersion.V47 -> "4.7",bonusArgs
89+
| LangVersion.V50 -> "5.0",bonusArgs
90+
| LangVersion.V60 -> "6.0",bonusArgs
91+
| LangVersion.V70 -> "7.0",bonusArgs
92+
| LangVersion.Preview -> "preview",bonusArgs
93+
| LangVersion.Latest -> "latest", bonusArgs
94+
| LangVersion.SupportsMl -> "5.0", "--mlcompatibility" :: bonusArgs
95+
96+
97+
let singleTestBuildAndRunAuxVersion (folder:string) bonusArgs mode langVersion =
98+
let absFolder = Path.Combine(baseFolder,folder)
99+
let supportedNames, files =
100+
match mode with
101+
| NEG_TEST_BUILD testName ->
102+
let nameSet =
103+
Configuration.supportedNames
104+
.Add(testName+".fsx")
105+
.Add(testName+".fs")
106+
.Add(testName+".fsi")
107+
.Add(testName+"-pre.fs")
108+
let files = Directory.GetFiles(absFolder,"*.fs*") |> Array.filter(fun n -> nameSet.Contains(Path.GetFileName(n)))
109+
nameSet, files
110+
| _ -> Configuration.supportedNames, Directory.GetFiles(absFolder,"test*.fs*")
111+
112+
let mainFile,otherFiles =
113+
match files.Length with
114+
| 0 -> Directory.GetFiles(absFolder,"*.ml") |> Array.exactlyOne, [||]
115+
| 1 -> files |> Array.exactlyOne, [||]
116+
| _ ->
117+
let mainFile,dependencies =
118+
files
119+
|> Array.filter (fun n -> supportedNames.Contains(Path.GetFileName(n)))
120+
// Convention in older FsharpSuite: test2 goes last, longer names like testlib before test, .fsi before .fs on equal filenames
121+
|> Array.sortBy (fun n -> n.Contains("test2"), -n.IndexOf('.'), n.EndsWith(".fsi") |> not)
122+
|> Array.splitAt 1
123+
124+
mainFile[0],dependencies
125+
126+
let version,bonusArgs = adjustVersion langVersion bonusArgs
127+
128+
FsFromPath mainFile
129+
|> withAdditionalSourceFiles [for f in otherFiles -> SourceFromPath f]
130+
|> withLangVersion version
131+
|> fun cu ->
132+
match mode with
133+
| FSC_DEBUG | FSC_OPTIMIZED | FSI | COMPILED_EXE_APP ->
134+
cu
135+
|> ignoreWarnings
136+
|> withOptions (["--nowarn:0988;3370"] @ bonusArgs)
137+
| NEG_TEST_BUILD _ ->
138+
cu |>
139+
withOptions (["--vserrors";"--maxerrors:10000";"--warnaserror";"--warn:3";"--nowarn:20;21;1178;52"] @ bonusArgs)
140+
|> fun cu ->
141+
match mode with
142+
| FSC_DEBUG ->
143+
cu
144+
|> withDebug
145+
|> withNoOptimize
146+
|> ScriptRunner.runScriptFile langVersion
147+
|> shouldSucceed
148+
| FSC_OPTIMIZED ->
149+
cu
150+
|> withOptimize
151+
|> withNoDebug
152+
|> ScriptRunner.runScriptFile langVersion
153+
|> shouldSucceed
154+
| FSI ->
155+
cu
156+
|> ScriptRunner.runScriptFile langVersion
157+
|> shouldSucceed
158+
| COMPILED_EXE_APP ->
159+
cu
160+
|> withDefines ("TESTS_AS_APP" :: ScriptRunner.defaultDefines)
161+
|> compileExeAndRun
162+
|> shouldSucceed
163+
| NEG_TEST_BUILD testName -> diffNegativeBaseline (cu |> withName mainFile) absFolder testName langVersion
164+
165+
|> ignore<CompilationResult>
166+
167+
168+
let singleTestBuildAndRunAux folder bonusArgs mode = singleTestBuildAndRunAuxVersion folder bonusArgs mode LangVersion.Latest
169+
let singleTestBuildAndRunVersion folder mode version = singleTestBuildAndRunAuxVersion folder [] mode version
170+
let singleTestBuildAndRun folder mode = singleTestBuildAndRunVersion folder mode LangVersion.Latest
171+
172+
let singleVersionedNegTestAux folder bonusArgs version testName =
173+
singleTestBuildAndRunAuxVersion folder bonusArgs (NEG_TEST_BUILD testName) version
174+
let singleVersionedNegTest (folder:string) (version:LangVersion) (testName:string) =
175+
singleVersionedNegTestAux folder [] version testName
176+
let singleNegTest folder testName = singleVersionedNegTest folder LangVersion.Latest testName

0 commit comments

Comments
 (0)