mirror of
https://github.com/Smaug123/unofficial-nunit-runner
synced 2025-10-07 18:18:39 +00:00
Add Spectre progress (#31)
This commit is contained in:
@@ -102,9 +102,9 @@ type UserMethodFailure =
|
||||
override this.ToString () =
|
||||
match this with
|
||||
| UserMethodFailure.ReturnedNonUnit (method, ret) ->
|
||||
$"User-defined method %s{method} returned a non-unit: %O{ret}"
|
||||
$"User-defined method '%s{method}' returned a non-unit: %O{ret}"
|
||||
| UserMethodFailure.Threw (method, exc) ->
|
||||
$"User-defined method %s{method} threw: %s{exc.Message}\n %s{exc.StackTrace}"
|
||||
$"User-defined method '%s{method}' threw: %s{exc.Message}\n %s{exc.StackTrace}"
|
||||
|
||||
/// Name (not fully-qualified) of the method which failed.
|
||||
member this.Name =
|
||||
@@ -132,6 +132,13 @@ type TestFailure =
|
||||
| TestFailure.SetUpFailed f
|
||||
| TestFailure.TearDownFailed f -> f.Name
|
||||
|
||||
/// Human-readable string representation.
|
||||
override this.ToString () =
|
||||
match this with
|
||||
| TestFailure.TestFailed f -> $"execution: %O{f}"
|
||||
| TestFailure.SetUpFailed f -> $"Setup failed, and we did not attempt to run test: %O{f}"
|
||||
| TestFailure.TearDownFailed f -> $"Tear-down failed: %O{f}"
|
||||
|
||||
/// Represents the result of a test that didn't fail.
|
||||
[<RequireQualifiedAccess>]
|
||||
type TestMemberSuccess =
|
||||
@@ -150,3 +157,17 @@ type TestMemberFailure =
|
||||
/// We tried to run the test, but it failed. (A single test can fail many times, e.g. if it failed and also
|
||||
/// the tear-down logic failed afterwards.)
|
||||
| Failed of TestFailure list
|
||||
|
||||
/// Human-readable string representation
|
||||
override this.ToString () : string =
|
||||
match this with
|
||||
| TestMemberFailure.Malformed reasons ->
|
||||
let reasons = reasons |> String.concat "; "
|
||||
$"Could not run test because it was malformed: %s{reasons}"
|
||||
| TestMemberFailure.Failed errors ->
|
||||
let errors =
|
||||
errors
|
||||
|> Seq.map (fun failure -> (failure : TestFailure).ToString ())
|
||||
|> String.concat "\n"
|
||||
|
||||
$"Test failed: %s{errors}"
|
||||
|
@@ -84,7 +84,7 @@ module SingleTestMethod =
|
||||
match isTest, sources, hasData, modifiers, categories, repeat, comb with
|
||||
| _, _ :: _, Some _, _, _, _, _ ->
|
||||
failwith
|
||||
$"Test %s{method.Name} unexpectedly has both TestData and TestCaseSource; not currently supported"
|
||||
$"Test '%s{method.Name}' unexpectedly has both TestData and TestCaseSource; not currently supported"
|
||||
| false, [], None, [], _, _, _ -> None
|
||||
| _, _ :: _, None, mods, categories, repeat, comb ->
|
||||
{
|
||||
|
@@ -267,4 +267,4 @@ TestRunner.UserMethodFailure.IsThrew [property]: [read-only] bool
|
||||
TestRunner.UserMethodFailure.Name [property]: [read-only] string
|
||||
TestRunner.UserMethodFailure.NewReturnedNonUnit [static method]: (string, obj) -> TestRunner.UserMethodFailure
|
||||
TestRunner.UserMethodFailure.NewThrew [static method]: (string, System.Exception) -> TestRunner.UserMethodFailure
|
||||
TestRunner.UserMethodFailure.Tag [property]: [read-only] int
|
||||
TestRunner.UserMethodFailure.Tag [property]: [read-only] int
|
||||
|
@@ -97,7 +97,7 @@ module TestFixture =
|
||||
if valuesAttrs |> Array.exists (fun l -> l.IsSome) then
|
||||
if valuesAttrs |> Array.exists (fun l -> l.IsNone) then
|
||||
failwith
|
||||
$"Test %s{test.Name} has a parameter with the Values attribute and a parameter without. All parameters must have Values if any one does."
|
||||
$"Test '%s{test.Name}' has a parameter with the Values attribute and a parameter without. All parameters must have Values if any one does."
|
||||
|
||||
Some (valuesAttrs |> Array.map Option.get) |> Ok
|
||||
else
|
||||
|
@@ -28,7 +28,7 @@ module Program =
|
||||
| Some filter -> Filter.shouldRun filter
|
||||
| None -> fun _ _ -> true
|
||||
|
||||
let progress = TestProgress.toStderr ()
|
||||
let progress = Progress.spectre ()
|
||||
|
||||
use _ = new SetBaseDir (testDll)
|
||||
|
||||
|
24
TestRunner/Progress.fs
Normal file
24
TestRunner/Progress.fs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace TestRunner
|
||||
|
||||
open Spectre.Console
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Progress =
|
||||
let spectre () : ITestProgress =
|
||||
{ new ITestProgress with
|
||||
member _.OnTestFailed name failure =
|
||||
AnsiConsole.Console.MarkupLine
|
||||
$"[red]Test '%s{Markup.Escape name}' failed: %s{Markup.Escape (failure.ToString ())}[/]"
|
||||
|
||||
member _.OnTestFixtureStart name testCount =
|
||||
AnsiConsole.Console.MarkupLine $"[white]Running tests: %s{Markup.Escape name}[/]"
|
||||
|
||||
member _.OnTestMemberFinished name =
|
||||
AnsiConsole.Console.MarkupLine $"[gray]Finished test: %s{Markup.Escape name}[/]"
|
||||
|
||||
member _.OnTestMemberSkipped name =
|
||||
AnsiConsole.Console.MarkupLine $"[yellow]Skipping test due to filter: %s{Markup.Escape name}[/]"
|
||||
|
||||
member _.OnTestMemberStart name =
|
||||
AnsiConsole.Console.MarkupLine $"[white]Running test: %s{Markup.Escape name}[/]"
|
||||
}
|
@@ -18,6 +18,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Progress.fs" />
|
||||
<Compile Include="Program.fs" />
|
||||
<None Include="..\README.md">
|
||||
<Pack>True</Pack>
|
||||
@@ -29,4 +30,8 @@
|
||||
<ProjectReference Include="..\TestRunner.Lib\TestRunner.Lib.fsproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console" Version="0.49.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -121,6 +121,11 @@
|
||||
version = "4.5.0";
|
||||
sha256 = "1srx1629s0k1kmf02nmz251q07vj6pv58mdafcr5dr0bbn1fh78i";
|
||||
})
|
||||
(fetchNuGet {
|
||||
pname = "Spectre.Console";
|
||||
version = "0.49.1";
|
||||
sha256 = "0fhl96p3xjd5k1wwvhs80cp35rrlgnza6mw9vy0knhmf7ji9b95n";
|
||||
})
|
||||
(fetchNuGet {
|
||||
pname = "System.Formats.Asn1";
|
||||
version = "6.0.0";
|
||||
|
Reference in New Issue
Block a user