mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-08 15:38:41 +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']" \
|
||||
--value "$MSBUILD" \
|
||||
"$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
|
||||
|
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
|
||||
run: nix develop --command dotnet build --no-restore --configuration Release
|
||||
- name: Test
|
||||
run: nix develop --command dotnet test --no-build --verbosity normal --configuration Release
|
||||
run: nix develop --command dotnet test
|
||||
|
||||
build-nix:
|
||||
runs-on: ubuntu-latest
|
||||
|
@@ -1,6 +1,5 @@
|
||||
namespace WoofWare.PawPrint
|
||||
|
||||
open System
|
||||
open System.Collections.Immutable
|
||||
open System.IO
|
||||
open Microsoft.Extensions.Logging
|
||||
@@ -21,11 +20,7 @@ module Program =
|
||||
match argv |> Array.toList with
|
||||
| dllPath :: args ->
|
||||
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.
|
||||
// DotnetEnvironmentInfo.Get().Frameworks
|
||||
// |> Seq.map (fun fi -> Path.Combine (fi.Path, fi.Version.ToString ()))
|
||||
// |> ImmutableArray.CreateRange
|
||||
ImmutableArray.Create (FileInfo(dllPath).Directory.FullName)
|
||||
DotnetRuntime.SelectForDll dllPath |> ImmutableArray.CreateRange
|
||||
|
||||
use fileStream = new FileStream (dllPath, FileMode.Open, FileAccess.Read)
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<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>
|
||||
|
||||
</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 FsUnitTyped
|
||||
open NUnit.Framework
|
||||
open WoofWare.DotnetRuntimeLocator
|
||||
open WoofWare.PawPrint
|
||||
open WoofWare.PawPrint.Test
|
||||
|
||||
[<TestFixture>]
|
||||
module TestThing =
|
||||
module TestNoOp =
|
||||
let assy = typeof<RunResult>.Assembly
|
||||
|
||||
[<Test>]
|
||||
@@ -18,16 +19,12 @@ module TestThing =
|
||||
let messages, loggerFactory = LoggerFactory.makeTest ()
|
||||
|
||||
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.
|
||||
// DotnetEnvironmentInfo.Get().Frameworks
|
||||
// |> Seq.map (fun fi -> Path.Combine (fi.Path, fi.Version.ToString ()))
|
||||
// |> ImmutableArray.CreateRange
|
||||
ImmutableArray.Create (FileInfo(assy.Location).Directory.FullName)
|
||||
DotnetRuntime.SelectForDll assy.Location |> ImmutableArray.CreateRange
|
||||
|
||||
use peImage = new MemoryStream (image)
|
||||
|
||||
let terminalState, terminatingThread =
|
||||
Program.run loggerFactory peImage (ImmutableArray.CreateRange []) []
|
||||
Program.run loggerFactory peImage dotnetRuntimes []
|
||||
|
||||
let exitCode =
|
||||
match terminalState.ThreadState.[terminatingThread].MethodState.EvaluationStack.Values with
|
@@ -14,8 +14,10 @@
|
||||
<Compile Include="Assembly.fs" />
|
||||
<Compile Include="Roslyn.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\HelloWorld.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -29,6 +31,7 @@
|
||||
<PackageReference Include="NUnit" Version="4.3.2"/>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||
<PackageReference Include="WoofWare.DotnetRuntimeLocator" Version="0.3.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
</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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -470,7 +470,12 @@ module IlMachineState =
|
||||
with :? FileNotFoundException ->
|
||||
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
|
||||
|
||||
|
@@ -228,5 +228,10 @@
|
||||
"pname": "System.Runtime.CompilerServices.Unsafe",
|
||||
"version": "6.0.0",
|
||||
"hash": "sha256-bEG1PnDp7uKYz/OgLOWs3RWwQSVYm+AnPwVmAmcgp2I="
|
||||
},
|
||||
{
|
||||
"pname": "WoofWare.DotnetRuntimeLocator",
|
||||
"version": "0.3.2",
|
||||
"hash": "sha256-Pnm8gnULh33Iog3eN2lTqqxGuaKUFiM9yLLgiAvyFkU="
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user