Skip to content

Commit

Permalink
Added standalone tests (dotnet#8109)
Browse files Browse the repository at this point in the history
  • Loading branch information
TIHan authored and cartermp committed Jan 7, 2020
1 parent 99c5a49 commit 317700e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
32 changes: 31 additions & 1 deletion tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,34 @@ else failwith "Test Failed"
"""
Compilation.Create(source, Fsx, Exe, [|"--optimize+"|], [CompilationReference.CreateFSharp(module1, staticLink=true)])

CompilerAssert.Execute(module2, ignoreWarnings=true)
CompilerAssert.Execute(module2, ignoreWarnings=true)

[<Test>]
let ``Standalone linking``() =
let source =
"""
module Module1
let _ = List.iter (fun s -> eprintf "%s" s) ["hello"; " "; "world"]
let _ = eprintfn "%s" "."
let _ = exit 0
"""

let module1 = Compilation.Create(source, Fsx, Exe, [|"--standalone"|])

CompilerAssert.Execute(module1, newProcess=true)

[<Test>]
let ``Standalone linking - optimized``() =
let source =
"""
module Module1
let _ = List.iter (fun s -> eprintf "%s" s) ["hello"; " "; "world"]
let _ = eprintfn "%s" "."
let _ = exit 0
"""

let module1 = Compilation.Create(source, Fsx, Exe, [|"--standalone"; "--optimize+"|])

CompilerAssert.Execute(module1, newProcess=true)
41 changes: 39 additions & 2 deletions tests/fsharp/Compiler/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,51 @@ let main argv = 0"""
compileCompilation ignoreWarnings cmpl (fun ((errors, _), _) ->
assertErrors ignoreWarnings errors))

static member Execute(cmpl: Compilation, ?ignoreWarnings, ?beforeExecute) =
static member Execute(cmpl: Compilation, ?ignoreWarnings, ?beforeExecute, ?newProcess) =
let ignoreWarnings = defaultArg ignoreWarnings false
let beforeExecute = defaultArg beforeExecute (fun _ _ -> ())
let newProcess = defaultArg newProcess false
lock gate (fun () ->
compileCompilation ignoreWarnings cmpl (fun ((errors, outputFilePath), deps) ->
assertErrors ignoreWarnings errors
beforeExecute outputFilePath deps
executeBuiltApp outputFilePath deps))
if newProcess then
let mutable pinfo = ProcessStartInfo()
pinfo.RedirectStandardError <- true
pinfo.RedirectStandardOutput <- true
#if !NETCOREAPP
pinfo.FileName <- outputFilePath
#else
pinfo.FileName <- "dotnet"
pinfo.Arguments <- outputFilePath

let runtimeconfig =
"""
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
"""

let runtimeconfigPath = Path.ChangeExtension(outputFilePath, ".runtimeconfig.json")
File.WriteAllText(runtimeconfigPath, runtimeconfig)
use _disposal =
{ new IDisposable with
member _.Dispose() = try File.Delete runtimeconfigPath with | _ -> () }
#endif
pinfo.UseShellExecute <- false
let p = Process.Start pinfo
let errors = p.StandardError.ReadToEnd()
Assert.True(p.WaitForExit(120000))
if p.ExitCode <> 0 then
Assert.Fail errors
else
executeBuiltApp outputFilePath deps))

static member Pass (source: string) =
lock gate <| fun () ->
Expand Down

0 comments on commit 317700e

Please sign in to comment.