Skip to content

Commit

Permalink
Merge pull request #10611 from dotnet/merges/release/dev16.8-to-relea…
Browse files Browse the repository at this point in the history
…se/fcs

Merge release/dev16.8 to release/fcs
  • Loading branch information
KevinRansom authored Dec 4, 2020
2 parents f3a37b6 + 35f543e commit 952f389
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
34 changes: 30 additions & 4 deletions tests/FSharp.Test.Utilities/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ type CompilerAssert private () =
</Project>"""

static let directoryBuildProps = """
<Project>
<PropertyGroup>
<DisableCompilerRedirection>true</DisableCompilerRedirection>
</PropertyGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
</Project>
"""

static let programFs = """
open System
Expand All @@ -127,20 +137,25 @@ let main argv = 0"""
let mutable output = ""
let mutable errors = ""
let mutable cleanUp = true
let projectDirectory = Path.Combine(Path.GetTempPath(), "CompilerAssert", Path.GetRandomFileName())
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????"
let pathToTemp = Path.Combine(pathToArtifacts, "Temp")
let projectDirectory = Path.Combine(pathToTemp, "CompilerAssert", Path.GetRandomFileName())
let pathToFSharpCore = typeof<RequireQualifiedAccessAttribute>.Assembly.Location
try
try
Directory.CreateDirectory(projectDirectory) |> ignore
let projectFileName = Path.Combine(projectDirectory, "ProjectFile.fsproj")
let programFsFileName = Path.Combine(projectDirectory, "Program.fs")
let directoryBuildPropsFileName = Path.Combine(projectDirectory, "Directory.Build.props")
let frameworkReferencesFileName = Path.Combine(projectDirectory, "FrameworkReferences.txt")
#if NETCOREAPP
File.WriteAllText(projectFileName, projectFile.Replace("$TARGETFRAMEWORK", "netcoreapp3.1").Replace("$FSHARPCORELOCATION", pathToFSharpCore))
#else
File.WriteAllText(projectFileName, projectFile.Replace("$TARGETFRAMEWORK", "net472").Replace("$FSHARPCORELOCATION", pathToFSharpCore))
#endif
File.WriteAllText(programFsFileName, programFs)
File.WriteAllText(directoryBuildPropsFileName, directoryBuildProps)

let pInfo = ProcessStartInfo ()
pInfo.FileName <- config.DotNetExe
Expand All @@ -157,16 +172,27 @@ let main argv = 0"""
output <- p.StandardOutput.ReadToEnd ()
errors <- p.StandardError.ReadToEnd ()

if not (String.IsNullOrWhiteSpace errors) then Assert.Fail errors
if p.ExitCode <> 0 then Assert.Fail(sprintf "Program exited with exit code %d" p.ExitCode)
if not succeeded then Assert.Fail(sprintf "Program timed out after %d ms" timeout)
if not (String.IsNullOrWhiteSpace errors) then
printfn "Output:\n=======\n%s\n" output
printfn "Errors:\n=======\n%s\n" errors
Assert.Fail errors
if p.ExitCode <> 0 then
printfn "Output:\n=======\n%s\n" output
printfn "Errors:\n=======\n%s\n" errors
Assert.Fail(sprintf "Program exited with exit code %d" p.ExitCode)
if not succeeded then
printfn "Output:\n=======\n%s\n" output
printfn "Errors:\n=======\n%s\n" errors
Assert.Fail(sprintf "Program timed out after %d ms" timeout)

File.ReadLines(frameworkReferencesFileName) |> Seq.toArray
with | e ->
cleanUp <- false
printfn "Project directory: %s" projectDirectory
printfn "STDOUT: %s" output
File.WriteAllText(Path.Combine(projectDirectory, "project.stdout"), output)
printfn "STDERR: %s" errors
File.WriteAllText(Path.Combine(projectDirectory, "project.stderror"), errors)
raise (new Exception (sprintf "An error occurred getting netcoreapp references: %A" e))
finally
if cleanUp then
Expand Down
12 changes: 8 additions & 4 deletions tests/fsharp/single-test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open System
open System.IO
open System.Diagnostics
open System.Reflection
open NUnit.Framework
open TestFramework
open HandleExpects
Expand Down Expand Up @@ -222,12 +223,15 @@ let singleTestBuildAndRunCore cfg copyFiles p languageVersion =
let mutable result = ""
lock lockObj <| (fun () ->
let rec loop () =
let dir = Path.Combine(Path.GetTempPath(), "FSharp.Cambridge", Path.GetRandomFileName())
if Directory.Exists(dir) then
let pathToArtifacts = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "../../../.."))
if Path.GetFileName(pathToArtifacts) <> "artifacts" then failwith "FSharp.Cambridge did not find artifacts directory --- has the location changed????"
let pathToTemp = Path.Combine(pathToArtifacts, "Temp")
let projectDirectory = Path.Combine(pathToTemp, "FSharp.Cambridge", Path.GetRandomFileName())
if Directory.Exists(projectDirectory) then
loop ()
else
Directory.CreateDirectory(dir) |>ignore
dir
Directory.CreateDirectory(projectDirectory) |>ignore
projectDirectory
result <- loop())
result

Expand Down

0 comments on commit 952f389

Please sign in to comment.