From 9537e6ec543a8525fe7a4e5227336f29cad802fd Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Sat, 31 May 2025 00:59:17 +0100 Subject: [PATCH] Assert contents of local variables in tests (#26) --- WoofWare.PawPrint.Test/TestCases.fs | 23 +++++++++++++++++++++++ WoofWare.PawPrint.Test/TestHarness.fs | 1 + 2 files changed, 24 insertions(+) diff --git a/WoofWare.PawPrint.Test/TestCases.fs b/WoofWare.PawPrint.Test/TestCases.fs index 24e214e..6203963 100644 --- a/WoofWare.PawPrint.Test/TestCases.fs +++ b/WoofWare.PawPrint.Test/TestCases.fs @@ -19,11 +19,13 @@ module TestCases = FileName = "Threads.cs" ExpectedReturnCode = 3 NativeImpls = MockEnv.make () + LocalVariablesOfMain = [] } { FileName = "BasicException.cs" ExpectedReturnCode = 10 NativeImpls = MockEnv.make () + LocalVariablesOfMain = [] } { FileName = "BasicLock.cs" @@ -34,11 +36,13 @@ module TestCases = { mock with System_Threading_Monitor = System_Threading_Monitor.passThru } + LocalVariablesOfMain = [] } { FileName = "WriteLine.cs" ExpectedReturnCode = 1 NativeImpls = MockEnv.make () + LocalVariablesOfMain = [] } ] @@ -48,11 +52,23 @@ module TestCases = FileName = "NoOp.cs" ExpectedReturnCode = 1 NativeImpls = MockEnv.make () + LocalVariablesOfMain = [ CliType.Numeric (CliNumericType.Int32 1) ] } { FileName = "TriangleNumber.cs" ExpectedReturnCode = 10 NativeImpls = MockEnv.make () + LocalVariablesOfMain = + [ + // answer + CliType.Numeric (CliNumericType.Int32 10) + // i + CliType.Numeric (CliNumericType.Int32 5) + // End-loop condition + CliType.OfBool false + // Ret + CliType.Numeric (CliNumericType.Int32 10) + ] } { FileName = "InstaQuit.cs" @@ -75,6 +91,7 @@ module TestCases = ExecutionResult.Terminated (state, thread) } } + LocalVariablesOfMain = [] } ] @@ -103,6 +120,12 @@ module TestCases = exitCode |> shouldEqual case.ExpectedReturnCode + let finalVariables = + terminalState.ThreadState.[terminatingThread].MethodState.LocalVariables + |> Seq.toList + + finalVariables |> shouldEqual case.LocalVariablesOfMain + with _ -> for message in messages () do System.Console.Error.WriteLine $"{message}" diff --git a/WoofWare.PawPrint.Test/TestHarness.fs b/WoofWare.PawPrint.Test/TestHarness.fs index b59aa4e..1b1d0ab 100644 --- a/WoofWare.PawPrint.Test/TestHarness.fs +++ b/WoofWare.PawPrint.Test/TestHarness.fs @@ -30,4 +30,5 @@ type TestCase = FileName : string ExpectedReturnCode : int NativeImpls : NativeImpls + LocalVariablesOfMain : CliType list }