Skip to content
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

How to show test results in interactive #365

Closed
halcwb opened this issue Nov 14, 2019 · 3 comments
Closed

How to show test results in interactive #365

halcwb opened this issue Nov 14, 2019 · 3 comments

Comments

@halcwb
Copy link

halcwb commented Nov 14, 2019

How can I print the test results in a nice way in the interactive? I tried something like:

let config =
    { defaultConfig with ``parallel`` = false }

let handler (sum : Impl.TestRunSummary) =
    for (t, r) in sum.results do
        printfn "Test: %A Result: %A" t.name r.result

ValueRange.tests
|> runTests (config.appendSummaryHandler handler)

But this results in garbled output in the interactive. Is there an easy way to accomplish this?

@halcwb halcwb changed the title How to show test results in FSI How to show test results in interactive Nov 14, 2019
@haf
Copy link
Owner

haf commented Nov 15, 2019

You have to create a logger:

open Expecto.Logging
open Expecto.Logging.Message
let logger = Log.create "FSI"
logger.info (eventX "Hi")

@haf haf closed this as completed Nov 15, 2019
@halcwb
Copy link
Author

halcwb commented Apr 25, 2021

@haf Sorry, but still not get this. For example with the following I was expecting that a verbose print should be visible in the FSI:

runTestsWithCLIArgs [ CLIArguments.Debug; CLIArguments.Sequenced ] [||]

However, whether or not I add the CLIArguments the print out just shows:

[15:43:56 INF] EXPECTO? Running tests...
[15:43:56 INF] EXPECTO! 28 tests run in 00:00:00.0477646 for PIM – 28 passed, 0 ignored, 0 failed, 0 errored. Success!
val it : int = 0

How can I tell Expecto to use the logger? Or do I need to manually insert a logging message in each test?

I use VSCode on a Macbook.

@farlee2121
Copy link
Collaborator

@halcwb

It's still a bit scrappy, but I wrote these run methods for better interactive support. They capture the logs normally printed to the console and return them as a string from the run method. There's one with ANSI coloration and one without

module Tests =

    let private literateOutputWriter (outputBuilder: StringBuilder) (text: (string*ConsoleColor) list) : unit =
            let colorizeLine (text, color) = ColourText.colouriseText color text
            let sbAppend (builder: StringBuilder) (text: string) =
                builder.Append(text)

            text
            |> List.iter (colorizeLine >> (sbAppend outputBuilder) >> ignore)
            

    let private colorlessOutputWriter (outputBuilder: StringBuilder) (text: (string*ConsoleColor) list) : unit =
        text
        |> List.iter (fun (text, color) ->
            outputBuilder.Append(text)
            |> ignore)


    let run_ReturnLogs cliArgs args tests =

        let outputBuilder = StringBuilder("")
        
        Global.initialise 
            { Global.defaultConfig with
                getLogger = fun name ->
                    Expecto.Logging.LiterateConsoleTarget(
                        name = [|"boi"|], 
                        minLevel = Expecto.Logging.LogLevel.Info, 
                        outputWriter = (literateOutputWriter outputBuilder)) :> Expecto.Logging.Logger
            }

        Tests.runTestsWithCLIArgs cliArgs args tests |> ignore
        outputBuilder.ToString()

    let run_ReturnLogs_NoColor cliArgs args tests =

        let outputBuilder = StringBuilder("")
        
        Global.initialise 
            { Global.defaultConfig with
                getLogger = fun name ->
                    Expecto.Logging.LiterateConsoleTarget(
                        name =[|"boi"|], 
                        minLevel = Expecto.Logging.LogLevel.Info, 
                        outputWriter = (colorlessOutputWriter outputBuilder)) :> Expecto.Logging.Logger
            }

        Tests.runTestsWithCLIArgs cliArgs args tests |> ignore
        outputBuilder.ToString()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants