-
-
Notifications
You must be signed in to change notification settings - Fork 100
Improve support for interactive experiences #482
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
base: main
Are you sure you want to change the base?
Changes from 2 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 |
|---|---|---|
|
|
@@ -643,3 +643,44 @@ module Tests = | |
| /// Returns 0 if all tests passed, otherwise 1 | ||
| let runTestsInAssemblyWithCLIArgs cliArgs args = | ||
| runTestsInAssemblyWithCLIArgsAndCancel CancellationToken.None cliArgs args | ||
|
|
||
| let runTestsReturnLogs cliArgs args tests = | ||
| let tryBuildConfig cliArgs args = | ||
| let config = | ||
| Seq.fold (fun s a -> foldCLIArgumentToConfig a s) | ||
| ExpectoConfig.defaultConfig cliArgs | ||
|
|
||
| match ExpectoConfig.fillFromArgs config args with | ||
|
||
| | ArgsUsage (usage, errors) -> | ||
| None | ||
| | ArgsList config | ||
| | ArgsRun config | ||
| | ArgsVersion config -> | ||
| Some config | ||
|
|
||
| let literateOutputWriter (outputBuilder: Text.StringBuilder) (text: (string*ConsoleColor) list) : unit = | ||
| let colorizeLine (text, color) = ColourText.colouriseText color text | ||
| let sbAppend (builder: Text.StringBuilder) (text: string) = | ||
| builder.Append(text) | ||
|
|
||
| text | ||
| |> List.iter (colorizeLine >> (sbAppend outputBuilder) >> ignore) | ||
|
|
||
| let outputBuilder = System.Text.StringBuilder("") | ||
|
|
||
| let verbosity = | ||
| tryBuildConfig cliArgs args | ||
| |> Option.defaultValue ExpectoConfig.defaultConfig | ||
| |> (fun config -> config.verbosity) | ||
|
|
||
| Global.initialise | ||
| { Global.defaultConfig with | ||
| getLogger = fun name -> | ||
| Expecto.Logging.LiterateConsoleTarget( | ||
| name, | ||
| minLevel = verbosity, | ||
| outputWriter = (literateOutputWriter outputBuilder)) :> Expecto.Logging.Logger | ||
| } | ||
|
|
||
| runTestsWithCLIArgs cliArgs args tests |> ignore | ||
| outputBuilder.ToString() | ||
| 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 | ||
|
Collaborator
Author
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
Collaborator
Author
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" | ||
|
|
||
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
runTestsForInteractiveThere 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,
runTestsForInteractiveseems reasonable to me, then.