mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-06 14:38:40 +00:00
50 lines
1.5 KiB
Forth
50 lines
1.5 KiB
Forth
namespace WoofWare.Pawprint.Test
|
|
|
|
open System.Collections.Immutable
|
|
open System.IO
|
|
open FsUnitTyped
|
|
open NUnit.Framework
|
|
open WoofWare.DotnetRuntimeLocator
|
|
open WoofWare.PawPrint
|
|
open WoofWare.PawPrint.Test
|
|
|
|
[<TestFixture>]
|
|
module TestCases =
|
|
let assy = typeof<RunResult>.Assembly
|
|
|
|
let cases : TestCase list =
|
|
[
|
|
{
|
|
FileName = "NoOp.cs"
|
|
ExpectedReturnCode = 1
|
|
}
|
|
{
|
|
FileName = "TriangleNumber.cs"
|
|
ExpectedReturnCode = 10
|
|
}
|
|
]
|
|
|
|
[<TestCaseSource(nameof cases)>]
|
|
let ``Can run a no-op`` (case : TestCase) : unit =
|
|
let source = Assembly.getEmbeddedResourceAsString case.FileName 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 a value, but it returned void"
|
|
| head :: _ ->
|
|
match head with
|
|
| EvalStackValue.Int32 i -> i
|
|
| ret -> failwith "expected program to return an int, but it returned %O{ret}"
|
|
|
|
exitCode |> shouldEqual case.ExpectedReturnCode
|