SwensenSoftware / unquote

Write F# unit test assertions as quoted expressions, get step-by-step failure messages for free
http://www.swensensoftware.com/unquote
Apache License 2.0
285 stars 26 forks source link

Missing stacktrace for exceptions #140

Closed peterzeller closed 5 years ago

peterzeller commented 5 years ago

When calling a function that throws an exception, the resulting stacktrace only includes the unquote stack and not the stack for the called function.

For example:

module Program
open Swensen.Unquote

let bar(n) =
    failwith "blub"

let foo n =
    bar (n+1)

let [<EntryPoint>] main _ =
    test <@ foo 5 = 5 @>
    0

Terminates with the following message:

Unhandled Exception: Xunit.Sdk.TrueException:

Program.foo 5 = 5
System.Exception: blub
   at Swensen.Unquote.Evaluation.eval(FSharpList`1 env, FSharpExpr expr)
   at Swensen.Unquote.Reduction.reduce(FSharpList`1 env, FSharpExpr expr)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
   at Swensen.Unquote.Reduction.reduce(FSharpList`1 env, FSharpExpr expr)
   at Swensen.Unquote.Reduction.loop@126(FSharpList`1 env, FSharpExpr expr, FSharpList`1 acc)

Expected: True
Actual:   False
   at Program.main(String[] _arg1) in Program.fs:line 11

Instead, I would expect it to include functions foo and bar in the stacktrace. Something like this:

Unhandled Exception: System.Exception: blub
   at Program.bar[a,b](a n) in Program.fs:line 5
   at Program.foo[a](Int32 n) in Program.fs:line 8
   at Program.main(String[] _arg1) in Program.fs:line 11
stephen-swensen commented 5 years ago

Hi @peterzeller - I think this is because of the combination you have of a console application with a reference to Xunit... is that intentional?

peterzeller commented 5 years ago

I am using unquote in Xunit tests, but wanted to create a minimal example without the Xunit dependency for this issue. Seems I forgot to remove the Xunit dependency, the actual error message is:

Unhandled Exception: Swensen.Unquote.AssertionFailedException: Test failed:

Program.foo 5 = 5
System.Exception: blub
   at Swensen.Unquote.Evaluation.eval(FSharpList`1 env, FSharpExpr expr)
   at Swensen.Unquote.Reduction.reduce(FSharpList`1 env, FSharpExpr expr)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
   at Swensen.Unquote.Reduction.reduce(FSharpList`1 env, FSharpExpr expr)
   at Swensen.Unquote.Reduction.loop@126(FSharpList`1 env, FSharpExpr expr, FSharpList`1 acc)

   at Program.main(String[] _arg1) in /home/peter/work/fsharp-tests/ut/Program.fs:line 11

So it seems unrelated to using Xunit.

stephen-swensen commented 5 years ago

Fixed!: https://github.com/SwensenSoftware/unquote/pull/146/commits/95d53254c83c01b5c5d2eeac9a4ce4c9616e6478

Thanks for reporting, this will be in the next release