-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add isTestSkipped
to TestPrinters.beforeEach
#516
Add isTestSkipped
to TestPrinters.beforeEach
#516
Conversation
(cherry picked from commit 79f6e21)
Hmm. It feels like something the existing Printer argument should be able to handle. Something like this let skipPrinter =
{
TestPrinters.defaultPrinter with
beforeEach = (fun (test) ->
match test.shouldSkipEvaluation with
| None -> TestPrinters.beforeEach test
| Some -> ())
}
runTestsWithCLIArgs [CLIArguments.Printer skipPrinter] argv tests
|
That works. One thing about changing the printer is it seems to break the visual studio adapter, for example when I run in Jetbrains Rider I get an exception from I believe reflection failing: Exception
|
Here's the patch
Index: Expecto/Expecto.fs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Expecto/Expecto.fs b/Expecto/Expecto.fs
--- a/Expecto/Expecto.fs (revision ec1eb970d9e73d3f48c197ceedd851f5eb10ad39)
+++ b/Expecto/Expecto.fs (date 1736273834444)
@@ -449,8 +449,6 @@
| Colours of int
/// Adds a test printer.
| Printer of TestPrinters
- /// Whether to show skipped tests in the output.
- | PrintSkippedTests of bool
/// Sets the verbosity level.
| Verbosity of LogLevel
/// Append a summary handler.
Index: Expecto/CSharp.fs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Expecto/CSharp.fs b/Expecto/CSharp.fs
--- a/Expecto/CSharp.fs (revision ec1eb970d9e73d3f48c197ceedd851f5eb10ad39)
+++ b/Expecto/CSharp.fs (date 1736274464043)
@@ -13,7 +13,7 @@
// C# is weak and can't really handle Async or partial application
type ITestPrinter =
abstract member BeforeRun : Test -> Task
- abstract member BeforeEach : string -> Task
+ abstract member BeforeEach : name: string * enabled: bool -> Task
abstract member Info : string -> Task
abstract member Passed : string * TimeSpan -> Task
abstract member Ignored : string * string -> Task
@@ -28,7 +28,7 @@
let private printerFromInterface (i : ITestPrinter) =
{ beforeRun = fun t -> async { return! i.BeforeRun(t) |> Async.AwaitTask }
- beforeEach = fun s -> async { return! i.BeforeEach(s) |> Async.AwaitTask }
+ beforeEach = fun s e -> async { return! i.BeforeEach(s, e) |> Async.AwaitTask }
passed = fun n d -> async { return! i.Passed(n, d) |> Async.AwaitTask }
info = fun s -> async { return! i.Info(s) |> Async.AwaitTask }
ignored = fun n m -> async { return! i.Ignored(n, m) |> Async.AwaitTask }
Index: Expecto.Tests.CSharp/Tests.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Expecto.Tests.CSharp/Tests.cs b/Expecto.Tests.CSharp/Tests.cs
--- a/Expecto.Tests.CSharp/Tests.cs (revision ec1eb970d9e73d3f48c197ceedd851f5eb10ad39)
+++ b/Expecto.Tests.CSharp/Tests.cs (date 1736272442448)
@@ -10,7 +10,7 @@
{
public class CSharpPrinter : ITestPrinter
{
- Task ITestPrinter.BeforeEach(string value)
+ Task ITestPrinter.BeforeEach(string value, bool enabled)
{
return Task.CompletedTask;
}
Index: Expecto/Expecto.Impl.fs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Expecto/Expecto.Impl.fs b/Expecto/Expecto.Impl.fs
--- a/Expecto/Expecto.Impl.fs (revision ec1eb970d9e73d3f48c197ceedd851f5eb10ad39)
+++ b/Expecto/Expecto.Impl.fs (date 1736274398337)
@@ -207,8 +207,8 @@
type TestPrinters =
{ /// Called before a test run (e.g. at the top of your main function)
beforeRun: Test -> Async<unit>
- /// Called before atomic test (TestCode) is executed.
- beforeEach: string -> Async<unit>
+ /// test name -> enabled -> unit. Called before a test is executed (when enabled = true) or skipped (when enabled = false)
+ beforeEach: string -> bool -> Async<unit>
/// info
info: string -> Async<unit>
/// test name -> time taken -> unit
@@ -232,7 +232,7 @@
static member silent =
{ beforeRun = fun _ -> async.Zero()
- beforeEach = fun _ -> async.Zero()
+ beforeEach = fun _ _ -> async.Zero()
info = fun _ -> async.Zero()
passed = fun _ _ -> async.Zero()
ignored = fun _ _ -> async.Zero()
@@ -244,7 +244,7 @@
{ beforeRun = fun _tests ->
logger.logWithAck Info (eventX "EXPECTO? Running tests...")
- beforeEach = fun n ->
+ beforeEach = fun n _ ->
logger.logWithAck Debug (
eventX "{testName} starting..."
>> setField "testName" n)
@@ -404,8 +404,8 @@
tcLog "testSuiteStarted" [
"name", "ExpectoTestSuite" ] }
- beforeEach = fun n -> async {
- do! innerPrinter.beforeEach n
+ beforeEach = fun n e -> async {
+ do! innerPrinter.beforeEach n e
tcLog "testStarted" [
"flowId", formatName n
"name", formatName n ] }
@@ -439,7 +439,7 @@
"duration", d.TotalMilliseconds |> int |> string ] }
exn = fun n e d -> async {
- do! innerPrinter.beforeEach n
+ do! innerPrinter.beforeEach n true
tcLog "testFailed" [
"flowId", formatName n
"name", formatName n
@@ -460,7 +460,7 @@
do! b
}
{ beforeRun = fun _tests -> runTwoAsyncs (first.beforeRun _tests) (second.beforeRun _tests)
- beforeEach = fun n -> runTwoAsyncs (first.beforeEach n) (second.beforeEach n)
+ beforeEach = fun n e -> runTwoAsyncs (first.beforeEach n e) (second.beforeEach n e)
info = fun s -> runTwoAsyncs (first.info s) (second.info s)
passed = fun n d -> runTwoAsyncs (first.passed n d) (second.passed n d)
ignored = fun n m -> runTwoAsyncs (first.ignored n m) (second.ignored n m)
@@ -498,8 +498,6 @@
listStates : FocusState list
/// Allows the test printer to be parametised to your liking.
printer : TestPrinters
- /// Whether to show skipped tests in the output.
- printSkippedTests : bool
/// Verbosity level (default: Info).
verbosity : LogLevel
/// Process name to log under (default: "Expecto")
@@ -538,7 +536,6 @@
TestPrinters.defaultPrinter
else
TestPrinters.teamCityPrinter TestPrinters.defaultPrinter
- printSkippedTests = true
verbosity = Info
logName = None
locate = fun _ -> SourceLocation.empty
@@ -651,18 +648,15 @@
let beforeEach (test:FlatTest) =
let name = config.joinWith.format test.name
- if config.printSkippedTests || test.shouldSkipEvaluation.IsNone then
- config.printer.beforeEach name
- else
- async.Zero()
+
+ config.printer.beforeEach name <| Option.isNone test.shouldSkipEvaluation
async {
let! beforeAsync = beforeEach test |> Async.StartChild
let! result = execTestAsync ct config test
do! beforeAsync
- if config.printSkippedTests || test.shouldSkipEvaluation.IsNone then
- do! TestPrinters.printResult config test result
+ do! TestPrinters.printResult config test result
if progressStarted && Option.isNone test.shouldSkipEvaluation then
Fraction (Interlocked.Increment testsCompleted, testLength)
|
|
…config # Conflicts: # RELEASE_NOTES.md
YoloDev/YoloDev.Expecto.TestSdk#186 updates the VSTest adapter for the above changes. I tested locally and was able to run the tests in Jetbrains Rider |
isTestSkipped
to TestPrinters.beforeEach
I'd rather not risk pushing a broken package. Are you familiar with how to set up a local nuget source? If you run dotnet nuget add source c:\packages You can also create a nuget.config in the repository root if you want it more locally scoped This should allow you to reference local Expecto builds in YoloDev for testing |
That's what I meant by testing locally 👍 |
That makes sense in retrospect. It's unfortunate there's no way to release this without some compatibility break |
Resolves #453
Separated out from #511