Skip to content

Commit 1614065

Browse files
authored
Surface area tests: improve updating FCS baselines (#18883)
1 parent 04e353f commit 1614065

File tree

6 files changed

+21
-12430
lines changed

6 files changed

+21
-12430
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ launchSettings.json
7474
*.jrs
7575
*.chk
7676
*.bak
77+
*.out
7778
*.vserr
7879
*.err
7980
*.orig
File renamed without changes.

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl

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

tests/FSharp.Compiler.Service.Tests/SurfaceArea.fs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@ type SurfaceAreaTest() =
1919

2020
[<Fact>]
2121
member _.VerifySurfaceAreaFSharpCompilerService() =
22+
// System.Environment.SetEnvironmentVariable("TEST_UPDATE_BSL", "1")
2223

2324
let platform = "netstandard20"
2425

25-
let flavor =
26-
#if DEBUG
27-
"debug"
28-
#else
29-
"release"
30-
#endif
3126
let assembly =
3227
let path = Path.Combine(Path.GetDirectoryName(typeof<int list>.Assembly.Location), "FSharp.Compiler.Service.dll")
3328
Assembly.LoadFrom path
3429

35-
let baseline = Path.Combine(__SOURCE_DIRECTORY__, $"FSharp.Compiler.Service.SurfaceArea.{platform}.{flavor}.bsl")
36-
let outFileName = $"FSharp.Compiler.Service.SurfaceArea.{platform}.{flavor}.out"
30+
let baseline = Path.Combine(__SOURCE_DIRECTORY__, $"FSharp.Compiler.Service.SurfaceArea.{platform}.bsl")
31+
let outFileName = Path.Combine(__SOURCE_DIRECTORY__, $"FSharp.Compiler.Service.SurfaceArea.{platform}.out")
3732
FSharp.Test.SurfaceArea.verify assembly baseline outFileName

tests/FSharp.Core.UnitTests/SurfaceArea.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace FSharp.Core.UnitTests.Portable.SurfaceArea
44

55
open Xunit
6-
open System
76
open System.IO
87
open FSharp.Test
98

@@ -39,5 +38,5 @@ type SurfaceAreaTest() =
3938
#endif
4039
let assembly = typeof<int list>.Assembly
4140
let baseline = Path.Combine(__SOURCE_DIRECTORY__, $"FSharp.Core.SurfaceArea.{platform}.{flavor}.bsl")
42-
let outFileName = $"FSharp.Core.SurfaceArea.{platform}.{flavor}.out"
43-
FSharp.Test.SurfaceArea.verify assembly baseline outFileName
41+
let outFileName = Path.Combine(Path.GetDirectoryName(assembly.Location), $"FSharp.Core.SurfaceArea.{platform}.{flavor}.out")
42+
SurfaceArea.verify assembly baseline outFileName

tests/FSharp.Test.Utilities/SurfaceArea.fs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ module FSharp.Test.SurfaceArea
4444
let private appendNewLine str = str + System.Environment.NewLine
4545

4646
// verify public surface area matches expected, handles baseline update when TEST_UPDATE_BSL is set
47-
let verify assembly baselinePath outFileName : unit =
48-
47+
let verify assembly baselinePath outFilePath : unit =
4948
let expected =
5049
File.ReadAllLines(baselinePath)
5150
|> String.concat System.Environment.NewLine
@@ -62,24 +61,23 @@ module FSharp.Test.SurfaceArea
6261

6362
let expected = normalize expected
6463

65-
let logFile =
66-
Path.Combine(Path.GetDirectoryName(assembly.Location), outFileName)
67-
68-
File.WriteAllText(logFile, actual)
69-
7064
match Assert.shouldBeSameMultilineStringSets expected actual with
71-
| None -> ()
65+
| None ->
66+
File.Delete(outFilePath)
67+
7268
| Some diff ->
73-
// Update baselines here
7469
match Environment.GetEnvironmentVariable("TEST_UPDATE_BSL") with
75-
| null -> ()
76-
| _ -> File.Copy(logFile, baselinePath, true)
77-
78-
let msg = $"""Assembly: %A{asm}
70+
| null ->
71+
File.WriteAllText(outFilePath, actual)
72+
73+
let msg = $"""Assembly: %A{asm}
7974
80-
Expected and actual surface area don't match. To see the delta, run:
81-
windiff {baselinePath} {logFile}
75+
Expected and actual surface area don't match. To see the delta, run:
76+
windiff {baselinePath} {outFilePath}
8277
83-
{diff}"""
78+
{diff}"""
8479

85-
failwith msg
80+
failwith msg
81+
| _ ->
82+
File.Delete(outFilePath)
83+
File.WriteAllText(baselinePath, actual)

0 commit comments

Comments
 (0)