diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index d7c910e05f..d04b39bc04 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -627,8 +627,6 @@ module CompilerAssertHelpers = File.WriteAllText(runtimeconfigPath, runtimeconfig) #endif let rc, output, errors = Commands.executeProcess fileName arguments (Path.GetDirectoryName(outputFilePath)) - let output = String.Join(Environment.NewLine, output) - let errors = String.Join(Environment.NewLine, errors) ExitCode rc, output, errors open CompilerAssertHelpers diff --git a/tests/FSharp.Test.Utilities/ILChecker.fs b/tests/FSharp.Test.Utilities/ILChecker.fs index 7857910212..a9ec56ccc6 100644 --- a/tests/FSharp.Test.Utilities/ILChecker.fs +++ b/tests/FSharp.Test.Utilities/ILChecker.fs @@ -15,9 +15,7 @@ module ILChecker = let private exec exe args = let arguments = args |> String.concat " " - let exitCode, _output, errors = Commands.executeProcess exe arguments "" - let errors = errors |> String.concat Environment.NewLine - errors, exitCode + Commands.executeProcess exe arguments "" /// Filters i.e ['The system type \'System.ReadOnlySpan`1\' was required but no referenced system DLL contained this type'] let private filterSpecialComment (text: string) = @@ -101,7 +99,7 @@ module ILChecker = let ildasmFullArgs = [ dllFilePath; $"-out=%s{ilFilePath}"; yield! ildasmArgs ] - let stdErr, exitCode = + let exitCode, _, stdErr = let ildasmCommandPath = Path.ChangeExtension(dllFilePath, ".ildasmCommandPath") File.WriteAllLines(ildasmCommandPath, [| $"{ildasmPath} {ildasmFullArgs}" |] ) exec ildasmPath ildasmFullArgs @@ -212,5 +210,5 @@ module ILChecker = let reassembleIL ilFilePath dllFilePath = let ilasmPath = config.ILASM - let errors, _ = exec ilasmPath [ $"%s{ilFilePath} /output=%s{dllFilePath} /dll" ] + let _, _, errors = exec ilasmPath [ $"%s{ilFilePath} /output=%s{dllFilePath} /dll" ] errors diff --git a/tests/FSharp.Test.Utilities/ILVerifierModule.fs b/tests/FSharp.Test.Utilities/ILVerifierModule.fs index 799af017e6..30ff766287 100644 --- a/tests/FSharp.Test.Utilities/ILVerifierModule.fs +++ b/tests/FSharp.Test.Utilities/ILVerifierModule.fs @@ -23,9 +23,7 @@ module ILVerifierModule = let private exec (dotnetExe: string) args workingDirectory = let arguments = args |> String.concat " " - let exitCode, _output, errors = Commands.executeProcess dotnetExe arguments workingDirectory - let errors = errors |> String.concat Environment.NewLine - errors, exitCode + Commands.executeProcess dotnetExe arguments workingDirectory let private verifyPEFileCore peverifierArgs (dllFilePath: string) = let nuget_packages = @@ -36,17 +34,13 @@ module ILVerifierModule = | path -> path let peverifyFullArgs = [ yield "exec"; yield $"""{nuget_packages}/dotnet-ilverify/9.0.0/tools/net9.0/any/ILVerify.dll"""; yield "--verbose"; yield dllFilePath; yield! peverifierArgs ] let workingDirectory = Path.GetDirectoryName dllFilePath - let _, exitCode = + let exitCode, outputText, errorText = let peverifierCommandPath = Path.ChangeExtension(dllFilePath, ".peverifierCommandPath.cmd") let args = peverifyFullArgs |> Seq.fold(fun a acc -> $"{a} " + acc) "" File.WriteAllLines(peverifierCommandPath, [| $"{args}" |] ) File.Copy(typeof.Assembly.Location, Path.GetDirectoryName(dllFilePath) ++ "FSharp.Core.dll", true) exec config.DotNetExe peverifyFullArgs workingDirectory - // Grab output - let outputText = File.ReadAllText(Path.Combine(workingDirectory, "StandardOutput.txt")) - let errorText = File.ReadAllText(Path.Combine(workingDirectory, "StandardError.txt")) - match exitCode with | 0 -> {Outcome = NoExitCode; StdOut = outputText; StdErr = errorText } | _ -> {Outcome = ExitCode exitCode; StdOut = outputText; StdErr = errorText } diff --git a/tests/FSharp.Test.Utilities/TestFramework.fs b/tests/FSharp.Test.Utilities/TestFramework.fs index 10046298e3..bbb1b55674 100644 --- a/tests/FSharp.Test.Utilities/TestFramework.fs +++ b/tests/FSharp.Test.Utilities/TestFramework.fs @@ -65,21 +65,6 @@ module Commands = // returns exit code, stdio and stderr as string arrays let executeProcess pathToExe arguments workingDir = let commandLine = ResizeArray() - let errorsList = ResizeArray() - let outputList = ResizeArray() - let errorslock = obj() - let outputlock = obj() - let outputDataReceived (message: string) = - if not (isNull message) then - lock outputlock (fun () -> - printfn "%s" message - outputList.Add(message)) - - let errorDataReceived (message: string) = - if not (isNull message) then - lock errorslock (fun () -> - eprintfn "%s" message - errorsList.Add(message)) commandLine.Add $"cd {workingDir}" commandLine.Add $"{pathToExe} {arguments} /bl" @@ -103,29 +88,14 @@ module Commands = use p = new Process() p.StartInfo <- psi - p.OutputDataReceived.Add(fun a -> outputDataReceived a.Data) - p.ErrorDataReceived.Add(fun a -> errorDataReceived a.Data) - - if p.Start() then - p.BeginOutputReadLine() - p.BeginErrorReadLine() - p.WaitForExit() - - let workingDir' = - if workingDir = "" - then - // Assign working dir to prevent default to C:\Windows\System32 - let executionLocation = Assembly.GetExecutingAssembly().Location - Path.GetDirectoryName executionLocation - else - workingDir - - lock gate (fun () -> - File.WriteAllLines(Path.Combine(workingDir', "commandline.txt"), commandLine) - File.WriteAllLines(Path.Combine(workingDir', "StandardOutput.txt"), outputList) - File.WriteAllLines(Path.Combine(workingDir', "StandardError.txt"), errorsList) - ) - p.ExitCode, outputList.ToArray(), errorsList.ToArray() + if not (p.Start()) then failwith "new process did not start" + + let readOutput = backgroundTask { return! p.StandardOutput.ReadToEndAsync() } + let readErrors = backgroundTask { return! p.StandardError.ReadToEndAsync() } + + p.WaitForExit() + + p.ExitCode, readOutput.Result, readErrors.Result let getfullpath workDir (path:string) = let rooted = diff --git a/tests/FSharp.Test.Utilities/Utilities.fs b/tests/FSharp.Test.Utilities/Utilities.fs index 8a424e8219..92b8c1dffa 100644 --- a/tests/FSharp.Test.Utilities/Utilities.fs +++ b/tests/FSharp.Test.Utilities/Utilities.fs @@ -165,8 +165,8 @@ open System let main argv = 0""" let private getNetCoreAppReferences = - let mutable output = [||] - let mutable errors = [||] + let mutable output = "" + let mutable errors = "" let mutable cleanUp = true let pathToArtifacts = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "../../../..")) if Path.GetFileName(pathToArtifacts) <> "artifacts" then failwith "CompilerAssert did not find artifacts directory --- has the location changed????" @@ -196,17 +196,15 @@ let main argv = 0""" errors <- dotneterrors output <- dotnetoutput printfn "Output:\n=======\n" - output |> Seq.iter(fun line -> printfn "STDOUT:%s\n" line) + printfn "%s" dotnetoutput printfn "Errors:\n=======\n" - errors |> Seq.iter(fun line -> printfn "STDERR:%s\n" line) + printfn "%s" dotneterrors Assert.True(false, "Errors produced generating References") File.ReadLines(frameworkReferencesFileName) |> Seq.toArray with | e -> cleanUp <- false let message = - let output = output |> String.concat "\nSTDOUT: " - let errors = errors |> String.concat "\nSTDERR: " File.WriteAllText(Path.Combine(projectDirectory, "project.stdout"), output) File.WriteAllText(Path.Combine(projectDirectory, "project.stderror"), errors) $"""