Skip to content

Commit 489a82d

Browse files
committed
Tests: extract 'should update baselines' checks
1 parent 9c88398 commit 489a82d

3 files changed

Lines changed: 19 additions & 25 deletions

File tree

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open FSharp.Compiler.Service.Tests.Common
77
open FSharp.Compiler.Syntax
88
open FSharp.Compiler.Text
99
open FSharp.Test
10+
open FSharp.Test.Compiler
1011
open Xunit
1112

1213
let testCasesDir = __SOURCE_DIRECTORY__ ++ ".." ++ "service" ++ "data" ++ "SyntaxTree"
@@ -186,18 +187,14 @@ let ParseFile fileName =
186187
else
187188
"No baseline was found"
188189

189-
let equals = expected = actual
190-
let testUpdateBSLEnv = System.Environment.GetEnvironmentVariable("TEST_UPDATE_BSL")
191-
192-
let shouldUpdateBaseline =
193-
(not (isNull testUpdateBSLEnv) && testUpdateBSLEnv.Trim() = "1" && not equals)
194-
195-
if shouldUpdateBaseline then
196-
File.WriteAllText(bslPath, actual)
197-
elif not equals then
198-
File.WriteAllText(actualPath, actual)
199-
else
190+
if expected = actual then
200191
File.Delete(actualPath)
192+
else
193+
if shouldUpdateBaselines then
194+
File.Delete(actualPath)
195+
File.WriteAllText(bslPath, actual)
196+
else
197+
File.WriteAllText(actualPath, actual)
201198

202199
Assert.Equal(expected, actual)
203200

tests/FSharp.Test.Utilities/Compiler.fs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ namespace FSharp.Test
55
open FSharp.Compiler.Interactive.Shell
66
open FSharp.Compiler.IO
77
open FSharp.Compiler.Diagnostics
8-
open FSharp.Compiler.Symbols
98
open FSharp.Compiler.Text
10-
open FSharp.Test.Assert
119
open FSharp.Test.Utilities
1210
open FSharp.Test.ScriptHelpers
1311
open Microsoft.CodeAnalysis
@@ -27,9 +25,10 @@ open TestFramework
2725

2826
open System.Runtime.CompilerServices
2927
open System.Runtime.InteropServices
30-
open FSharp.Compiler.CodeAnalysis
3128

3229
module rec Compiler =
30+
let shouldUpdateBaselines =
31+
Environment.GetEnvironmentVariable("TEST_UPDATE_BSL") <> null
3332

3433
[<AutoOpen>]
3534
type SourceUtilities () =
@@ -1230,10 +1229,8 @@ Expected:
12301229
{expected}
12311230
Actual:
12321231
{actual}"""
1233-
let updateBaseline () =
1234-
snd (Int32.TryParse(Environment.GetEnvironmentVariable("TEST_UPDATE_BSL"))) <> 0
12351232
let updateBaseLineIfEnvironmentSaysSo baseline =
1236-
if updateBaseline () then
1233+
if shouldUpdateBaselines then
12371234
if FileSystem.FileExistsShim baseline.FilePath then
12381235
FileSystem.CopyShim(baseline.FilePath, baseline.BslSource, true)
12391236

@@ -2020,7 +2017,7 @@ Actual:
20202017
match Assert.shouldBeSameMultilineStringSets expectedContent actualErrors with
20212018
| None -> ()
20222019
| Some diff ->
2023-
if Environment.GetEnvironmentVariable("TEST_UPDATE_BSL") <> null then
2020+
if shouldUpdateBaselines then
20242021
File.WriteAllText(path, actualErrors)
20252022

20262023
printfn $"{Path.GetFullPath path} \n {diff}"

tests/FSharp.Test.Utilities/SurfaceArea.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ module FSharp.Test.SurfaceArea
44
open System
55
open System.IO
66
open System.Reflection
7-
open System.Text.RegularExpressions
8-
7+
open FSharp.Test.Compiler
8+
open System.Text.RegularExpressions
9+
910
// Gets string form of public surface area for the currently-loaded assembly
1011
let private getSurfaceAreaForAssembly (assembly: Assembly) =
1112

@@ -66,8 +67,10 @@ module FSharp.Test.SurfaceArea
6667
File.Delete(outFilePath)
6768

6869
| Some diff ->
69-
match Environment.GetEnvironmentVariable("TEST_UPDATE_BSL") with
70-
| null ->
70+
if shouldUpdateBaselines then
71+
File.Delete(outFilePath)
72+
File.WriteAllText(baselinePath, actual)
73+
else
7174
File.WriteAllText(outFilePath, actual)
7275

7376
let msg = $"""Assembly: %A{asm}
@@ -78,6 +81,3 @@ module FSharp.Test.SurfaceArea
7881
{diff}"""
7982

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

0 commit comments

Comments
 (0)