So, there have been a few requests to enable backtraces for cargo test by default. @alexcrichton and I were just having a bit of a discussion on #1634 and it seemed like it’d be better to move this discussion to a more public forum, so we can get a wider survey of opinions.
My basic feeling is that backtraces are pretty basic and we should make it easy for users to see them when a test fails. @alexcrichton righly points out that while many users have come to expect backtraces from VM-based languages, backtraces in a native environment are a different beast. And I agree with this. But I still think we want to print them, imperfect or no – otherwise, test failures tend to give you no clue as the context. Moreover, I find that as long as you pass -g
, backtraces are quite reliable, even with optimization enabled – for example, at least on linux, they tell you what was inlined into what, and so forth.
One interesting point is that since we print backtraces on every panic, that sometimes includes “internal” panics where a backtrace printout is undesired. An example actually occurs within the execution of cargo test itself, I think, since the final backtrace that you see is basically an internal printout that derives from an error that will ultimately be handled. (Right?)
A middle-ground might be making backtraces more discoverable, e.g. via cargo test --backtrace
. It seems to me though that adding an option makes it an order of magnitude less likely that people will find it, even if that option is prominently listed.