mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-11 08:48:38 +00:00
Add more test cases (#11)
This commit is contained in:
@@ -9,12 +9,24 @@ open WoofWare.PawPrint
|
||||
open WoofWare.PawPrint.Test
|
||||
|
||||
[<TestFixture>]
|
||||
module TestNoOp =
|
||||
module TestCases =
|
||||
let assy = typeof<RunResult>.Assembly
|
||||
|
||||
[<Test>]
|
||||
let ``Can run a no-op`` () : unit =
|
||||
let source = Assembly.getEmbeddedResourceAsString "NoOp.cs" assy
|
||||
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 ()
|
||||
|
||||
@@ -28,10 +40,10 @@ module TestNoOp =
|
||||
|
||||
let exitCode =
|
||||
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
||||
| [] -> failwith "expected program to return 1, but it returned void"
|
||||
| [] -> failwith "expected program to return a value, but it returned void"
|
||||
| head :: _ ->
|
||||
match head with
|
||||
| EvalStackValue.Int32 i -> i
|
||||
| _ -> failwith "TODO"
|
||||
| ret -> failwith "expected program to return an int, but it returned %O{ret}"
|
||||
|
||||
exitCode |> shouldEqual 1
|
||||
exitCode |> shouldEqual case.ExpectedReturnCode
|
@@ -15,3 +15,9 @@ type RunResult =
|
||||
/// Final interpreter state after we stopped executing.
|
||||
FinalState : IlMachineState
|
||||
}
|
||||
|
||||
type TestCase =
|
||||
{
|
||||
FileName : string
|
||||
ExpectedReturnCode : int
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
namespace WoofWare.Pawprint.Test
|
||||
|
||||
open System
|
||||
open System.Collections.Immutable
|
||||
open System.IO
|
||||
open FsUnitTyped
|
||||
@@ -21,17 +22,23 @@ module TestHelloWorld =
|
||||
let dotnetRuntimes =
|
||||
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
|
||||
|
||||
use peImage = new MemoryStream (image)
|
||||
try
|
||||
use peImage = new MemoryStream (image)
|
||||
|
||||
let terminalState, terminatingThread =
|
||||
Program.run loggerFactory peImage dotnetRuntimes []
|
||||
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"
|
||||
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
|
||||
exitCode |> shouldEqual 0
|
||||
with _ ->
|
||||
for m in messages () do
|
||||
Console.Error.WriteLine $"{m}"
|
||||
|
||||
reraise ()
|
||||
|
@@ -14,12 +14,13 @@
|
||||
<Compile Include="Assembly.fs" />
|
||||
<Compile Include="Roslyn.fs" />
|
||||
<Compile Include="TestHarness.fs"/>
|
||||
<Compile Include="TestNoOp.fs" />
|
||||
<Compile Include="TestCases.fs" />
|
||||
<Compile Include="TestHelloWorld.fs" />
|
||||
<Compile Include="TestBasicLock.fs" />
|
||||
<EmbeddedResource Include="sources\BasicLock.cs" />
|
||||
<EmbeddedResource Include="sources\NoOp.cs" />
|
||||
<EmbeddedResource Include="sources\HelloWorld.cs" />
|
||||
<EmbeddedResource Include="sources\TriangleNumber.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
17
WoofWare.PawPrint.Test/sources/TriangleNumber.cs
Normal file
17
WoofWare.PawPrint.Test/sources/TriangleNumber.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace TriangleNumber
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
var answer = 0;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
answer += i;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user