mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-10 00:08:39 +00:00
Expand test harness (#6)
This commit is contained in:
9
.envrc
9
.envrc
@@ -20,4 +20,13 @@ if [ -f "$SETTINGS_FILE" ] ; then
|
|||||||
--update "//s:String[@x:Key='/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue']" \
|
--update "//s:String[@x:Key='/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue']" \
|
||||||
--value "$MSBUILD" \
|
--value "$MSBUILD" \
|
||||||
"$SETTINGS_FILE"
|
"$SETTINGS_FILE"
|
||||||
|
|
||||||
|
xmlstarlet ed --inplace \
|
||||||
|
-N wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \
|
||||||
|
-N x="http://schemas.microsoft.com/winfx/2006/xaml" \
|
||||||
|
-N s="clr-namespace:System;assembly=mscorlib" \
|
||||||
|
-N ss="urn:shemas-jetbrains-com:settings-storage-xaml" \
|
||||||
|
--update "//s:String[@x:Key='/Default/Housekeeping/UnitTestingMru/UnitTestRunner/EnvironmentVariablesIndexed/=WOOFWARE_005FDOTNET_005FLOCATOR_005FDOTNET_005FEXE/@EntryIndexedValue']" \
|
||||||
|
--value "$DOTNET_PATH" \
|
||||||
|
"$SETTINGS_FILE"
|
||||||
fi
|
fi
|
||||||
|
1
.fantomasignore
Normal file
1
.fantomasignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.direnv/
|
2
.github/workflows/dotnet.yaml
vendored
2
.github/workflows/dotnet.yaml
vendored
@@ -32,7 +32,7 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: nix develop --command dotnet build --no-restore --configuration Release
|
run: nix develop --command dotnet build --no-restore --configuration Release
|
||||||
- name: Test
|
- name: Test
|
||||||
run: nix develop --command dotnet test --no-build --verbosity normal --configuration Release
|
run: nix develop --command dotnet test
|
||||||
|
|
||||||
build-nix:
|
build-nix:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
namespace WoofWare.PawPrint
|
namespace WoofWare.PawPrint
|
||||||
|
|
||||||
open System
|
|
||||||
open System.Collections.Immutable
|
open System.Collections.Immutable
|
||||||
open System.IO
|
open System.IO
|
||||||
open Microsoft.Extensions.Logging
|
open Microsoft.Extensions.Logging
|
||||||
@@ -21,11 +20,7 @@ module Program =
|
|||||||
match argv |> Array.toList with
|
match argv |> Array.toList with
|
||||||
| dllPath :: args ->
|
| dllPath :: args ->
|
||||||
let dotnetRuntimes =
|
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.
|
DotnetRuntime.SelectForDll dllPath |> ImmutableArray.CreateRange
|
||||||
// DotnetEnvironmentInfo.Get().Frameworks
|
|
||||||
// |> Seq.map (fun fi -> Path.Combine (fi.Path, fi.Version.ToString ()))
|
|
||||||
// |> ImmutableArray.CreateRange
|
|
||||||
ImmutableArray.Create (FileInfo(dllPath).Directory.FullName)
|
|
||||||
|
|
||||||
use fileStream = new FileStream (dllPath, FileMode.Open, FileAccess.Read)
|
use fileStream = new FileStream (dllPath, FileMode.Open, FileAccess.Read)
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.2" />
|
||||||
<PackageReference Include="WoofWare.DotnetRuntimeLocator" Version="0.1.11" />
|
<PackageReference Include="WoofWare.DotnetRuntimeLocator" Version="0.3.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
37
WoofWare.PawPrint.Test/TestHelloWorld.fs
Normal file
37
WoofWare.PawPrint.Test/TestHelloWorld.fs
Normal 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
|
@@ -4,11 +4,12 @@ open System.Collections.Immutable
|
|||||||
open System.IO
|
open System.IO
|
||||||
open FsUnitTyped
|
open FsUnitTyped
|
||||||
open NUnit.Framework
|
open NUnit.Framework
|
||||||
|
open WoofWare.DotnetRuntimeLocator
|
||||||
open WoofWare.PawPrint
|
open WoofWare.PawPrint
|
||||||
open WoofWare.PawPrint.Test
|
open WoofWare.PawPrint.Test
|
||||||
|
|
||||||
[<TestFixture>]
|
[<TestFixture>]
|
||||||
module TestThing =
|
module TestNoOp =
|
||||||
let assy = typeof<RunResult>.Assembly
|
let assy = typeof<RunResult>.Assembly
|
||||||
|
|
||||||
[<Test>]
|
[<Test>]
|
||||||
@@ -18,16 +19,12 @@ module TestThing =
|
|||||||
let messages, loggerFactory = LoggerFactory.makeTest ()
|
let messages, loggerFactory = LoggerFactory.makeTest ()
|
||||||
|
|
||||||
let dotnetRuntimes =
|
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.
|
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
|
||||||
// DotnetEnvironmentInfo.Get().Frameworks
|
|
||||||
// |> Seq.map (fun fi -> Path.Combine (fi.Path, fi.Version.ToString ()))
|
|
||||||
// |> ImmutableArray.CreateRange
|
|
||||||
ImmutableArray.Create (FileInfo(assy.Location).Directory.FullName)
|
|
||||||
|
|
||||||
use peImage = new MemoryStream (image)
|
use peImage = new MemoryStream (image)
|
||||||
|
|
||||||
let terminalState, terminatingThread =
|
let terminalState, terminatingThread =
|
||||||
Program.run loggerFactory peImage (ImmutableArray.CreateRange []) []
|
Program.run loggerFactory peImage dotnetRuntimes []
|
||||||
|
|
||||||
let exitCode =
|
let exitCode =
|
||||||
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
@@ -14,8 +14,10 @@
|
|||||||
<Compile Include="Assembly.fs" />
|
<Compile Include="Assembly.fs" />
|
||||||
<Compile Include="Roslyn.fs" />
|
<Compile Include="Roslyn.fs" />
|
||||||
<Compile Include="TestHarness.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\NoOp.cs" />
|
||||||
|
<EmbeddedResource Include="sources\HelloWorld.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -29,6 +31,7 @@
|
|||||||
<PackageReference Include="NUnit" Version="4.3.2"/>
|
<PackageReference Include="NUnit" Version="4.3.2"/>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0"/>
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||||
|
<PackageReference Include="WoofWare.DotnetRuntimeLocator" Version="0.3.2"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
25
WoofWare.PawPrint.Test/sources/HelloWorld.cs
Normal file
25
WoofWare.PawPrint.Test/sources/HelloWorld.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
#
|
#
|
||||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "WoofWare.PawPrint", "WoofWare.PawPrint\WoofWare.PawPrint.fsproj", "{505F34FE-76ED-4E17-BDE4-C8A59848A4A3}"
|
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "WoofWare.PawPrint", "WoofWare.PawPrint\WoofWare.PawPrint.fsproj", "{505F34FE-76ED-4E17-BDE4-C8A59848A4A3}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "WoofWare.PawPrint.App", "WoofWare.PawPrint.App\WoofWare.PawPrint.App.fsproj", "{D661BF46-97C1-458B-838B-77ED0378A1A9}"
|
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "WoofWare.PawPrint.App", "WoofWare.PawPrint.App\WoofWare.PawPrint.App.fsproj", "{D661BF46-97C1-458B-838B-77ED0378A1A9}"
|
||||||
|
@@ -470,7 +470,12 @@ module IlMachineState =
|
|||||||
with :? FileNotFoundException ->
|
with :? FileNotFoundException ->
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|> Seq.exactlyOne
|
|> Seq.toList
|
||||||
|
|
||||||
|
match assy with
|
||||||
|
| [] -> failwith $"Could not find a readable DLL in any runtime dir with name %s{assemblyName.Name}.dll"
|
||||||
|
| _ :: _ :: _ -> failwith $"Found multiple DLLs in runtime dirs with name %s{assemblyName.Name}.dll"
|
||||||
|
| [ assy ] ->
|
||||||
|
|
||||||
state.WithLoadedAssembly assemblyName assy, assy, assemblyName
|
state.WithLoadedAssembly assemblyName assy, assy, assemblyName
|
||||||
|
|
||||||
|
@@ -228,5 +228,10 @@
|
|||||||
"pname": "System.Runtime.CompilerServices.Unsafe",
|
"pname": "System.Runtime.CompilerServices.Unsafe",
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"hash": "sha256-bEG1PnDp7uKYz/OgLOWs3RWwQSVYm+AnPwVmAmcgp2I="
|
"hash": "sha256-bEG1PnDp7uKYz/OgLOWs3RWwQSVYm+AnPwVmAmcgp2I="
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pname": "WoofWare.DotnetRuntimeLocator",
|
||||||
|
"version": "0.3.2",
|
||||||
|
"hash": "sha256-Pnm8gnULh33Iog3eN2lTqqxGuaKUFiM9yLLgiAvyFkU="
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user