From 477cb9b3fbb1d2c63748ef20e222959352af0c3b Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Fri, 27 Jun 2025 12:02:18 +0100 Subject: [PATCH] Delete spare files (#70) --- WoofWare.PawPrint.Test/TestCases.fs | 278 ----------------------- WoofWare.PawPrint.Test/TestHelloWorld.fs | 47 ---- 2 files changed, 325 deletions(-) delete mode 100644 WoofWare.PawPrint.Test/TestCases.fs delete mode 100644 WoofWare.PawPrint.Test/TestHelloWorld.fs diff --git a/WoofWare.PawPrint.Test/TestCases.fs b/WoofWare.PawPrint.Test/TestCases.fs deleted file mode 100644 index e24ffb7..0000000 --- a/WoofWare.PawPrint.Test/TestCases.fs +++ /dev/null @@ -1,278 +0,0 @@ -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.ExternImplementations -open WoofWare.PawPrint.Test - -[] -[] -module TestCases = - let assy = typeof.Assembly - - let unimplemented = - [ - { - FileName = "Threads.cs" - ExpectedReturnCode = 3 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = [] - } - { - FileName = "ComplexTryCatch.cs" - ExpectedReturnCode = 14 - NativeImpls = NativeImpls.PassThru () - LocalVariablesOfMain = - [ - 4 - 20 - 115 - 12 - 1 - 10 - 2 - 112 - 12 - 1111 - 42 - 99 - 25 - 50 - 123 - 20 - 35 - 5 - 11111 - 100001 - ] - |> List.map (fun i -> CliType.Numeric (CliNumericType.Int32 i)) - } - { - FileName = "WriteLine.cs" - ExpectedReturnCode = 1 - NativeImpls = NativeImpls.PassThru () - LocalVariablesOfMain = [] - } - { - FileName = "ResizeArray.cs" - ExpectedReturnCode = 109 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = [ CliType.Numeric (CliNumericType.Int32 10) ] - } - ] - - let cases : TestCase list = - [ - { - FileName = "NoOp.cs" - ExpectedReturnCode = 1 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = [ CliType.Numeric (CliNumericType.Int32 1) ] - } - { - FileName = "Ldind.cs" - ExpectedReturnCode = 0 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = - [ - // `failures` - CliType.Numeric (CliNumericType.Int32 0) - // Return value - CliType.Numeric (CliNumericType.Int32 0) - ] - } - { - FileName = "CustomDelegate.cs" - ExpectedReturnCode = 8 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = - [ - // filter - CliType.ObjectRef (Some (ManagedHeapAddress 2)) - // result - CliType.OfBool true - // result, cloned for "if(result)" check - CliType.OfBool true - // ret - CliType.Numeric (CliNumericType.Int32 8) - ] - } - { - FileName = "ArgumentOrdering.cs" - ExpectedReturnCode = 42 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = - [ - // localVar - CliType.Numeric (CliNumericType.Int32 42) - // t - CliType.ValueType [ CliType.Numeric (CliNumericType.Int32 42) ] - // return value - CliType.Numeric (CliNumericType.Int32 42) - ] - } - { - FileName = "BasicLock.cs" - ExpectedReturnCode = 1 - NativeImpls = - let mock = MockEnv.make () - - { mock with - System_Threading_Monitor = System_Threading_Monitor.passThru - } - LocalVariablesOfMain = - [ - // Four variables: - // locker - CliType.ObjectRef (Some (ManagedHeapAddress 2)) - // a copy of locker, taken so that the contents of the implicit `finally` have a stable copy - CliType.ObjectRef (Some (ManagedHeapAddress 2)) - // out param of `ReliableEnter` - CliType.OfBool true - // return value - 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" - ExpectedReturnCode = 1 - NativeImpls = - let mock = MockEnv.make () - - { mock with - System_Environment = - { System_EnvironmentMock.Empty with - GetProcessorCount = - fun thread state -> - let state = - state |> IlMachineState.pushToEvalStack' (EvalStackValue.Int32 1) thread - - (state, WhatWeDid.Executed) |> ExecutionResult.Stepped - _Exit = - fun thread state -> - let state = state |> IlMachineState.loadArgument thread 0 - ExecutionResult.Terminated (state, thread) - } - } - LocalVariablesOfMain = [] - } - { - FileName = "ExceptionWithNoOpFinally.cs" - ExpectedReturnCode = 3 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = - [ - // Variable 1 is `x`, variable 2 is the implicit return value - 4 - 3 - ] - |> List.map (fun i -> CliType.Numeric (CliNumericType.Int32 i)) - } - { - FileName = "ExceptionWithNoOpCatch.cs" - ExpectedReturnCode = 10 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = [ CliType.Numeric (CliNumericType.Int32 10) ] - } - { - FileName = "TryCatchWithThrowInBody.cs" - ExpectedReturnCode = 4 - NativeImpls = MockEnv.make () - LocalVariablesOfMain = - [ - // one variable is x, one variable is the return value which also happens to have the same value - 4 - 4 - ] - |> List.map (fun i -> CliType.Numeric (CliNumericType.Int32 i)) - } - ] - - [] - let ``Can evaluate C# files`` (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) - - try - let terminalState, terminatingThread = - Program.run loggerFactory (Some case.FileName) peImage dotnetRuntimes case.NativeImpls [] - - 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 - - let finalVariables = - terminalState.ThreadState.[terminatingThread].MethodState.LocalVariables - |> Seq.toList - - finalVariables |> shouldEqual case.LocalVariablesOfMain - - with _ -> - for message in messages () do - System.Console.Error.WriteLine $"{message}" - - reraise () - - [] - [] - let ``Can evaluate C# files, unimplemented`` (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) - - try - let terminalState, terminatingThread = - Program.run loggerFactory (Some case.FileName) peImage dotnetRuntimes case.NativeImpls [] - - 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 - - with _ -> - for message in messages () do - System.Console.Error.WriteLine $"{message}" - - reraise () diff --git a/WoofWare.PawPrint.Test/TestHelloWorld.fs b/WoofWare.PawPrint.Test/TestHelloWorld.fs deleted file mode 100644 index 9f1c8f2..0000000 --- a/WoofWare.PawPrint.Test/TestHelloWorld.fs +++ /dev/null @@ -1,47 +0,0 @@ -namespace WoofWare.Pawprint.Test - -open System -open System.Collections.Immutable -open System.IO -open FsUnitTyped -open NUnit.Framework -open WoofWare.PawPrint -open WoofWare.PawPrint.ExternImplementations -open WoofWare.PawPrint.Test -open WoofWare.DotnetRuntimeLocator - -[] -module TestHelloWorld = - let assy = typeof.Assembly - - [] - let ``Can run Hello World`` () : unit = - let source = Assembly.getEmbeddedResourceAsString "WriteLine.cs" assy - let image = Roslyn.compile [ source ] - let messages, loggerFactory = LoggerFactory.makeTest () - - let dotnetRuntimes = - DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange - - let impls = NativeImpls.PassThru () - - try - use peImage = new MemoryStream (image) - - let terminalState, terminatingThread = - Program.run loggerFactory (Some "HelloWorld.cs") peImage dotnetRuntimes impls [] - - 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 - with _ -> - for m in messages () do - Console.Error.WriteLine $"{m}" - - reraise ()