I'm trying to write a test for a small lib I'm writing that (essentially) just logs to the console.
Is there a way to mock function like this is F#?
example: in src/Lib/Lib.fs
module Lib
let print msg = printfn "Your message is: %s" msg
then, in test/LibTest/Lib.fs
module LibTest
open NUnit.Framework
open FsUnit
[<Test>]
let ``should print what I expect``() =
print "test" |> should equal "Your message is: test"
Note: I'm aware that currently print
returns unit
- I am looking for a way to make assertions about what is passed to printfn
(or, more ideally, what is sent to stdout, which relies less on implementation).
I've tried directly assigning a mock function to Printf.printfn
to no avail (obviously, when I think about it). Is it possible to capture the output to the console? Or to mock the printfn
function (it's an implementation detail, but I can live with that).