Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions tests/FSharp.Test.Utilities/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/FSharp.Test.Utilities/ILChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 2 additions & 8 deletions tests/FSharp.Test.Utilities/ILVerifierModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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<RequireQualifiedAccessAttribute>.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 }
Expand Down
46 changes: 8 additions & 38 deletions tests/FSharp.Test.Utilities/TestFramework.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 =
Expand Down
10 changes: 4 additions & 6 deletions tests/FSharp.Test.Utilities/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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????"
Expand Down Expand Up @@ -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)
$"""
Expand Down
Loading