Expand test harness (#6)

This commit is contained in:
Patrick Stevens
2025-05-16 21:18:32 +01:00
committed by GitHub
parent 3415b7a73d
commit d85bfeb168
12 changed files with 95 additions and 18 deletions

View File

@@ -0,0 +1,37 @@
namespace WoofWare.Pawprint.Test
open System.Collections.Immutable
open System.IO
open FsUnitTyped
open NUnit.Framework
open WoofWare.PawPrint
open WoofWare.PawPrint.Test
open WoofWare.DotnetRuntimeLocator
[<TestFixture>]
module TestHelloWorld =
let assy = typeof<RunResult>.Assembly
[<Test ; Explicit "This test doesn't run yet">]
let ``Can run Hello World`` () : unit =
let source = Assembly.getEmbeddedResourceAsString "HelloWorld.cs" assy
let image = Roslyn.compile [ source ]
let messages, loggerFactory = LoggerFactory.makeTest ()
let dotnetRuntimes =
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
use peImage = new MemoryStream (image)
let terminalState, terminatingThread =
Program.run loggerFactory peImage dotnetRuntimes []
let exitCode =
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
| [] -> failwith "expected program to return 1, but it returned void"
| head :: _ ->
match head with
| EvalStackValue.Int32 i -> i
| _ -> failwith "TODO"
exitCode |> shouldEqual 0

View File

@@ -4,11 +4,12 @@ open System.Collections.Immutable
open System.IO
open FsUnitTyped
open NUnit.Framework
open WoofWare.DotnetRuntimeLocator
open WoofWare.PawPrint
open WoofWare.PawPrint.Test
[<TestFixture>]
module TestThing =
module TestNoOp =
let assy = typeof<RunResult>.Assembly
[<Test>]
@@ -18,16 +19,12 @@ module TestThing =
let messages, loggerFactory = LoggerFactory.makeTest ()
let dotnetRuntimes =
// TODO: work out which runtime it expects to use, parsing the runtimeconfig etc and using DotnetRuntimeLocator. For now we assume we're self-contained.
// DotnetEnvironmentInfo.Get().Frameworks
// |> Seq.map (fun fi -> Path.Combine (fi.Path, fi.Version.ToString ()))
// |> ImmutableArray.CreateRange
ImmutableArray.Create (FileInfo(assy.Location).Directory.FullName)
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
use peImage = new MemoryStream (image)
let terminalState, terminatingThread =
Program.run loggerFactory peImage (ImmutableArray.CreateRange []) []
Program.run loggerFactory peImage dotnetRuntimes []
let exitCode =
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with

View File

@@ -14,8 +14,10 @@
<Compile Include="Assembly.fs" />
<Compile Include="Roslyn.fs" />
<Compile Include="TestHarness.fs"/>
<Compile Include="TestThing.fs"/>
<Compile Include="TestNoOp.fs" />
<Compile Include="TestHelloWorld.fs" />
<EmbeddedResource Include="sources\NoOp.cs" />
<EmbeddedResource Include="sources\HelloWorld.cs" />
</ItemGroup>
<ItemGroup>
@@ -29,6 +31,7 @@
<PackageReference Include="NUnit" Version="4.3.2"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
<PackageReference Include="WoofWare.DotnetRuntimeLocator" Version="0.3.2"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@
using System;
namespace HelloWorldApp
{
class Program
{
static int ReallyMain(string[] args)
{
Console.WriteLine("Hello, world!");
return 0;
}
static int Main(string[] args)
{
try
{
return ReallyMain(args);
}
catch
{
throw;
}
}
}
}