From 317700eb8b845aa9e6bd8de6c63d5cae3d975289 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Tue, 7 Jan 2020 09:39:38 -0800 Subject: [PATCH] Added standalone tests (#8109) --- .../CodeGen/EmittedIL/StaticLinkTests.fs | 32 ++++++++++++++- tests/fsharp/Compiler/CompilerAssert.fs | 41 ++++++++++++++++++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs b/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs index 8d47ba7dd7e..ad5c9eda65b 100644 --- a/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs +++ b/tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs @@ -224,4 +224,34 @@ else failwith "Test Failed" """ Compilation.Create(source, Fsx, Exe, [|"--optimize+"|], [CompilationReference.CreateFSharp(module1, staticLink=true)]) - CompilerAssert.Execute(module2, ignoreWarnings=true) \ No newline at end of file + CompilerAssert.Execute(module2, ignoreWarnings=true) + + [] + 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) + + [] + 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) \ No newline at end of file diff --git a/tests/fsharp/Compiler/CompilerAssert.fs b/tests/fsharp/Compiler/CompilerAssert.fs index 11e886a055d..b06d40fc032 100644 --- a/tests/fsharp/Compiler/CompilerAssert.fs +++ b/tests/fsharp/Compiler/CompilerAssert.fs @@ -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 () ->