haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
668 stars 96 forks source link

[Logging] PR back ANSI logger #266

Open haf opened 6 years ago

haf commented 6 years ago

To Logary Facade to be used elsewhere.

Checklist

haf commented 5 years ago

https://github.com/haf/expecto/blob/57489567c10849f1d4db05312864f4be01fdb503/Expecto/Expecto.fs#L1798 is bugged

Since it's mutated on running the tests, it causes things printed before the tests to have no colour

image
haf commented 5 years ago

The ANSI Console Writer can't be used in more than a single place in a process, because it has side-effects... The refactoring done 1bb391c is good, but only a small step towards completing this PR; this code needs to be coordinated between loggers/Facades.

    // since this executes on module load, it will be the original stdout
    stdout.Flush()
    let encoding = stdout.Encoding
    let std s = prettyPrint true true [s, foregroundColor]

    Console.SetOut (new FuncTextWriter(encoding, std))
    let errorEncoding = stderr.Encoding
    let errorToOutput s = prettyPrint true true [s, ConsoleColor.Red]

    Console.SetError (new FuncTextWriter(errorEncoding, errorToOutput))