-
-
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
Improve support for interactive experiences #482
base: main
Are you sure you want to change the base?
Changes from all commits
89a35bd
cbb623b
6d67df3
c3aae55
b6a7d90
4539e82
c23d67f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Bug_RepeatedColourSetting | ||
|
||
open Expecto | ||
open Expecto.Logging | ||
|
||
|
||
[<Tests>] | ||
let tests = | ||
ftest "Colour can be set repeatedly" { | ||
let colours = [|Colour0; Colour256|] | ||
colours |> Array.iter ANSIOutputWriter.setColourLevel | ||
|
||
Expect.equal (ANSIOutputWriter.getColour ()) (Array.last colours) "Colour should be the last set value" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -879,7 +879,7 @@ module internal ANSIOutputWriter = | |
override __.WriteLine() = write "\n" | ||
|
||
let mutable internal colours = None | ||
let internal setColourLevel c = if colours.IsNone then colours <- Some c | ||
let internal setColourLevel c = colours <- Some c | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't discern a reason this needed to be settable only once, and it prevents the colour setting from working as expected in interactive environments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
let internal getColour() = Option.defaultValue Colour8 colours | ||
|
||
let colourReset = "\u001b[0m" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ What follows is the Table of Contents for this README, which also serves as the | |
- [`runTestsWithCLIArgsAndCancel`](#runtestswithcliargsandcancel) | ||
- [`runTestsInAssemblyWithCLIArgs`](#runtestsinassemblywithcliargs) | ||
- [`runTestsInAssemblyWithCLIArgsAndCancel`](#runtestsinassemblywithcliargsandcancel) | ||
- [`runTestsReturnLogs`](#runtestsreturnlogs) | ||
- [Filtering with `filter`](#filtering-with-filter) | ||
- [Shuffling with `shuffle`](#shuffling-with-shuffle) | ||
- [Stress testing](#stress-testing) | ||
|
@@ -220,6 +221,8 @@ runTestsWithCLIArgs [] [||] simpleTest | |
which returns 1 if any tests failed, otherwise 0. Useful for returning to the | ||
operating system as error code. | ||
|
||
For interactive environments, you can alternatively call [`runTestsReturnLogs`](#runtestsreturnlogs), which returns the console output as a string. | ||
|
||
It's worth noting that `<|` is just a way to change the associativity of the | ||
language parser. In other words; it's equivalent to: | ||
|
||
|
@@ -250,6 +253,22 @@ Signature `CancellationToken -> CLIArguments seq -> string[] -> int`. Runs the t | |
assembly and also overrides the passed `CLIArguments` with the command line | ||
parameters. All tests need to be marked with the `[<Tests>]` attribute. | ||
|
||
### `runTestsReturnLogs` | ||
|
||
Signature `CLIArguments seq -> string[] -> Test -> string`. | ||
Accepts the same arguments as `runTestsWithCLIArgs`, but returns the console output as a string. | ||
|
||
This is useful for interactive environments like [F# interactive](https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/) and [Polyglot Notebooks](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode), where console output is not available but the returned string can be displayed instead. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I plan to add a screen shot once I can show the proper package reference. |
||
Note that ANSI colors are used by default, but can be turned off using `--colours 0`. | ||
```fsharp | ||
runTestsReturnLogs [] [|"--colours";"0"|] tests | ||
``` | ||
|
||
Any valid CLI arguments work, including `--help` and `--list-tests`. | ||
|
||
|
||
|
||
### Filtering with `filter` | ||
|
||
You can single out tests by filtering them by name (e.g. in the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use feedback on this method name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
runTestsForInteractive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about
runTestsInteractively
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of a similar name, but I feel like it denotes the test run itself is interactive, as in there will be decision points for the user during the test run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well,
runTestsForInteractive
seems reasonable to me, then.