Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit d693dd9

Browse files
TIHannosami
authored andcommitted
Added standalone tests (dotnet#8109)
1 parent 5fb2a7a commit d693dd9

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

tests/fsharp/Compiler/CodeGen/EmittedIL/StaticLinkTests.fs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,34 @@ else failwith "Test Failed"
224224
"""
225225
Compilation.Create(source, Fsx, Exe, [|"--optimize+"|], [CompilationReference.CreateFSharp(module1, staticLink=true)])
226226

227-
CompilerAssert.Execute(module2, ignoreWarnings=true)
227+
CompilerAssert.Execute(module2, ignoreWarnings=true)
228+
229+
[<Test>]
230+
let ``Standalone linking``() =
231+
let source =
232+
"""
233+
module Module1
234+
235+
let _ = List.iter (fun s -> eprintf "%s" s) ["hello"; " "; "world"]
236+
let _ = eprintfn "%s" "."
237+
let _ = exit 0
238+
"""
239+
240+
let module1 = Compilation.Create(source, Fsx, Exe, [|"--standalone"|])
241+
242+
CompilerAssert.Execute(module1, newProcess=true)
243+
244+
[<Test>]
245+
let ``Standalone linking - optimized``() =
246+
let source =
247+
"""
248+
module Module1
249+
250+
let _ = List.iter (fun s -> eprintf "%s" s) ["hello"; " "; "world"]
251+
let _ = eprintfn "%s" "."
252+
let _ = exit 0
253+
"""
254+
255+
let module1 = Compilation.Create(source, Fsx, Exe, [|"--standalone"; "--optimize+"|])
256+
257+
CompilerAssert.Execute(module1, newProcess=true)

tests/fsharp/Compiler/CompilerAssert.fs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,51 @@ let main argv = 0"""
325325
compileCompilation ignoreWarnings cmpl (fun ((errors, _), _) ->
326326
assertErrors ignoreWarnings errors))
327327

328-
static member Execute(cmpl: Compilation, ?ignoreWarnings, ?beforeExecute) =
328+
static member Execute(cmpl: Compilation, ?ignoreWarnings, ?beforeExecute, ?newProcess) =
329329
let ignoreWarnings = defaultArg ignoreWarnings false
330330
let beforeExecute = defaultArg beforeExecute (fun _ _ -> ())
331+
let newProcess = defaultArg newProcess false
331332
lock gate (fun () ->
332333
compileCompilation ignoreWarnings cmpl (fun ((errors, outputFilePath), deps) ->
333334
assertErrors ignoreWarnings errors
334335
beforeExecute outputFilePath deps
335-
executeBuiltApp outputFilePath deps))
336+
if newProcess then
337+
let mutable pinfo = ProcessStartInfo()
338+
pinfo.RedirectStandardError <- true
339+
pinfo.RedirectStandardOutput <- true
340+
#if !NETCOREAPP
341+
pinfo.FileName <- outputFilePath
342+
#else
343+
pinfo.FileName <- "dotnet"
344+
pinfo.Arguments <- outputFilePath
345+
346+
let runtimeconfig =
347+
"""
348+
{
349+
"runtimeOptions": {
350+
"tfm": "netcoreapp3.1",
351+
"framework": {
352+
"name": "Microsoft.NETCore.App",
353+
"version": "3.1.0"
354+
}
355+
}
356+
}
357+
"""
358+
359+
let runtimeconfigPath = Path.ChangeExtension(outputFilePath, ".runtimeconfig.json")
360+
File.WriteAllText(runtimeconfigPath, runtimeconfig)
361+
use _disposal =
362+
{ new IDisposable with
363+
member _.Dispose() = try File.Delete runtimeconfigPath with | _ -> () }
364+
#endif
365+
pinfo.UseShellExecute <- false
366+
let p = Process.Start pinfo
367+
let errors = p.StandardError.ReadToEnd()
368+
Assert.True(p.WaitForExit(120000))
369+
if p.ExitCode <> 0 then
370+
Assert.Fail errors
371+
else
372+
executeBuiltApp outputFilePath deps))
336373

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

0 commit comments

Comments
 (0)