Skip to content

Commit c281bd0

Browse files
authored
redirect log to test output (#18324)
1 parent 1e244bd commit c281bd0

File tree

6 files changed

+22
-34
lines changed

6 files changed

+22
-34
lines changed

tests/FSharp.Test.Utilities/ILChecker.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open TestFramework
1111

1212
[<RequireQualifiedAccess>]
1313
module ILChecker =
14-
let config = initializeSuite ()
14+
let config = initialConfig
1515

1616
let private exec exe args =
1717
let arguments = args |> String.concat " "

tests/FSharp.Test.Utilities/ILVerifierModule.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ open TestFramework
88

99
[<AutoOpen>]
1010
module ILVerifierModule =
11-
let config = initializeSuite ()
11+
let config = initialConfig
1212

1313
let fsharpCoreReference = $"--reference \"{typeof<unit>.Assembly.Location}\""
1414

tests/FSharp.Test.Utilities/TestFramework.fs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ let logConfig (cfg: TestConfig) =
410410
log "FSCOREDLLPATH = %s" cfg.FSCOREDLLPATH
411411
log "FSI = %s" cfg.FSI
412412
#if NETCOREAPP
413-
log "DotNetExe =%s" cfg.DotNetExe
413+
log "DotNetExe = %s" cfg.DotNetExe
414414
log "DOTNET_MULTILEVEL_LOOKUP = %s" cfg.DotNetMultiLevelLookup
415415
log "DOTNET_ROOT = %s" cfg.DotNetRoot
416416
#else
@@ -447,7 +447,7 @@ let envVars () =
447447
|> Seq.map (fun d -> d.Key :?> string, d.Value :?> string)
448448
|> Map.ofSeq
449449

450-
let initializeSuite () =
450+
let initialConfig =
451451

452452
#if DEBUG
453453
let configurationName = "Debug"
@@ -461,15 +461,9 @@ let initializeSuite () =
461461
let usedEnvVars = c.EnvironmentVariables |> Map.add "FSC" c.FSC
462462
{ c with EnvironmentVariables = usedEnvVars }
463463

464-
logConfig cfg
465-
466464
cfg
467465

468-
469-
let suiteHelpers = lazy (initializeSuite ())
470-
471466
let testConfig sourceDir (relativePathToTestFixture: string) =
472-
let cfg = suiteHelpers.Value
473467
let testFixtureFullPath = Path.GetFullPath(sourceDir ++ relativePathToTestFixture)
474468

475469
let tempTestDir =
@@ -478,11 +472,10 @@ let testConfig sourceDir (relativePathToTestFixture: string) =
478472
.FullName
479473
copyDirectory testFixtureFullPath tempTestDir true
480474

481-
{ cfg with Directory = tempTestDir }
475+
{ initialConfig with Directory = tempTestDir }
482476

483477
let createConfigWithEmptyDirectory() =
484-
let cfg = suiteHelpers.Value
485-
{ cfg with Directory = createTemporaryDirectory().FullName }
478+
{ initialConfig with Directory = createTemporaryDirectory().FullName }
486479

487480
type RedirectToType =
488481
| Overwrite of FilePath

tests/FSharp.Test.Utilities/Utilities.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module Utilities =
138138
[<RequireQualifiedAccess>]
139139
module public TargetFrameworkUtil =
140140

141-
let private config = TestFramework.initializeSuite ()
141+
let private config = initialConfig
142142

143143
// Do a one time dotnet sdk build to compute the proper set of reference assemblies to pass to the compiler
144144
let private projectFile = """

tests/FSharp.Test.Utilities/XunitHelpers.fs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type FSharpXunitFramework(sink: IMessageSink) =
2929
// Because xUnit v2 lacks assembly fixture, the next best place to ensure things get called
3030
// right at the start of the test run is here in the constructor.
3131
// This gets executed once per test assembly.
32-
MessageSink.sinkWriter |> ignore
32+
logConfig initialConfig
33+
log "FSharpXunitFramework installing TestConsole redirection"
3334
TestConsole.install()
3435
#if !NETCOREAPP
3536
AssemblyResolver.addResolver ()
@@ -144,16 +145,6 @@ type CustomTheoryTestCase =
144145
/// `XunitTestFramework` providing parallel console support and conditionally enabling optional xUnit customizations.
145146
type FSharpXunitFramework(sink: IMessageSink) =
146147
inherit XunitTestFramework(sink)
147-
do
148-
// Because xUnit v2 lacks assembly fixture, the next best place to ensure things get called
149-
// right at the start of the test run is here in the constructor.
150-
// This gets executed once per test assembly.
151-
log "FSharpXunitFramework with XUNIT_EXTRAS installing TestConsole redirection"
152-
TestConsole.install()
153-
154-
#if !NETCOREAPP
155-
AssemblyResolver.addResolver ()
156-
#endif
157148

158149
let traceProvider =
159150
Sdk.CreateTracerProviderBuilder()
@@ -176,6 +167,18 @@ type FSharpXunitFramework(sink: IMessageSink) =
176167
{ new XunitTestFrameworkExecutor(assemblyName, this.SourceInformationProvider, this.DiagnosticMessageSink) with
177168
override _.RunTestCases(testCases, executionMessageSink, executionOptions) =
178169
use _ = Activity.start $"{assemblyName.Name} {Runtime.InteropServices.RuntimeInformation.FrameworkDescription}" []
170+
171+
// Because xUnit v2 lacks assembly fixture, the next best place to ensure things get called
172+
// right at the start of the test run is here or in the FSharpXunitFramework constructor.
173+
// This gets executed once per test assembly.
174+
printfn $"Running tests in {assemblyName.Name} with XUNIT_EXTRAS"
175+
logConfig initialConfig
176+
log "Installing TestConsole redirection"
177+
TestConsole.install()
178+
179+
#if !NETCOREAPP
180+
AssemblyResolver.addResolver ()
181+
#endif
179182
base.RunTestCases(testCases, executionMessageSink, executionOptions)
180183
}
181184

tests/scripts/scriptlib.fsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ open System.IO
1010
open System.Text
1111
open System.Diagnostics
1212

13-
module MessageSink =
14-
let sinkWriter =
15-
#if DEBUG
16-
Console.Out
17-
#else
18-
TextWriter.Null
19-
#endif
20-
2113
[<AutoOpen>]
2214
module Scripting =
2315

@@ -85,7 +77,7 @@ module Scripting =
8577
if Directory.Exists output then
8678
Directory.Delete(output, true)
8779

88-
let log format = fprintfn MessageSink.sinkWriter format
80+
let log format = printfn format
8981

9082
type FilePath = string
9183

0 commit comments

Comments
 (0)