Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRUST_BACKTRACE=1 should be on by default for `cargo test` #1634
Comments
This comment has been minimized.
This comment has been minimized.
|
Thanks for the report! This is a dupe of #1517, however, and I've explained there why I don't think this should be implemented in Cargo. For example I do not want |
This comment has been minimized.
This comment has been minimized.
|
Is there precedent in other languages for tests to hide backtraces by default? This seems quite unusual to me. Maybe it'd feel less noisy if rust-lang/rust#25621 is implemented. |
This comment has been minimized.
This comment has been minimized.
|
Also, taking into account your desire not to have Cargo set default options for rustc's test harness, maybe this is really a rustc issue. |
This comment has been minimized.
This comment has been minimized.
|
I could see this either way as a Rust or Cargo issue, but for example languages like C do not have stack traces by default (as it requires a good deal of machinery to get a stack trace). In Rust it also requires a good deal of machinery to get a stack trace and you're not guaranteed that it exists. For example languages like Ruby and Python have a VM where the stack is explicit and there's a data structure to keep track of the information, but compiled languages like Rust, C and C++ use the native stack which is far less portable to inspect. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton how do you feel about non- |
This comment has been minimized.
This comment has been minimized.
|
I'm a little worried about too many different knobs for defaults, and I also feel that each knob will grow a cli switch at some point, which seems like somewhat overkill for this. |
This comment has been minimized.
This comment has been minimized.
alexcrichton
closed this
Jun 17, 2015
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton How do you feel about converting the magic environment variables people have to learn into global command-line flags? |
This comment has been minimized.
This comment has been minimized.
|
I still feel that generating a backtrace or not is orthogonal enough to a package manager that Cargo shouldn't be dealing with it. Cargo should certainly enable it to be specified one way or another (e.g. let the environment variable be inherited), but adding flags and/or logic to Cargo for all the bells and whistles in the standard distribution seems like the wrong direction to go in for me. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton the problem is that most people experience running Rust programs through Cargo, and having to learn about |
This comment has been minimized.
This comment has been minimized.
|
Having |
This comment has been minimized.
This comment has been minimized.
|
@jimmycuadra fwiw, For me, the question is simply whether someone would reasonably think of the change as a configuration of the command they typed. |
This comment has been minimized.
This comment has been minimized.
I agree, but the whole idea of an environment variable controlling backtraces also seems a little odd to me as well, and I'm not sure that adding a flag to
This seems like a somewhat critical distinction to me, though, in that a backtrace for a Rust program is a lower abstraction and is not a normal kind of thing. The stack traces from Rust are very different than the stack traces from Ruby/Python, for example:
Backtraces in Rust are just not a "super first class" utility which are expected to be 100% accurate, they're mostly just advisory. Along those lines I don't necessarily want all advisory debugging tools to be various Cargo flags. |
This comment has been minimized.
This comment has been minimized.
jaredly
commented
Aug 6, 2015
|
This is a huge frustration for new users :/ I should amend that to say "if they're following the commonly done (though ill-advisable) practice of just |
This comment has been minimized.
This comment has been minimized.
Hmm, I don't think I agree with this. I think backtraces are pretty de rigeur for C/C++ programmers, and I've always experienced very reliable line numbers in that setting -- sure, when full optimization is enabled, things get a little bit iffy, but it's usually been enough for me to figure out what's going on. Rust backtraces aren't quite as reliable as C++, obviously, but they've come a long way and are quite usable (at least on linux, I can't speak for other platforms). For example, I build rustc with I have found debugging unit tests in cargo to be quite annoying. I often get an error like "unwrap called on I agree with you Alex that we can't add every option to cargo, but having backtraces readily accessible -- perfect or not -- feels pretty basic to me! If the backtraces aren't reliable enough, we should fix them. |
This comment has been minimized.
This comment has been minimized.
Oh, and, if we have backtraces with line numbers, then I can just click on the relevant line in emacs and get taken there. Much nicer. |
This comment has been minimized.
This comment has been minimized.
This is the exact reason I even turn on backtraces most of the time. It's essentially useless information to tell me where in std the actual panic happened rather than where in my code the unwrap was called. Maybe having backtraces off by default wouldn't feel so wrong if the higher level error messages were better. |
This comment has been minimized.
This comment has been minimized.
I totally agree that debugging without backtraces is quite annoying, but the issue here to me is just whether they're turned on by default or not. Right now a failing test with a backtrace certainly has some UI issues:
(e.g. the extra panic at the end). Beyond that I feel that Cargo silently turning them on for tests (and only tests) gives the wrong impression about backtraces in Rust code. Setting up `RUST_BACKTRACE=1 doesn't seem so bad and it's one of those things which you should probably learn early on in Rust (at least in my opinion) |
This comment has been minimized.
This comment has been minimized.
Yes, that is silly.
I'll be honest, I don't really know what impression you mean. I think you are referring to the idea that backtraces are special because they require infrastructure that is not always available; but I feel like this also describes memory allocation, stdout, dynamic linking, and a bunch of other stuff that we make available in libstd. Now, I certainly agree that learning about I guess something like "cargo test --backtrace" could be a middle-ground, in that it's relatively discoverable, and the help for it can explain a bit more: "Dump a backtrace when a panic occurs. This is equivalent to setting RUST_BACKTRACE in the environment." |
This comment has been minimized.
This comment has been minimized.
|
That said, I think I would prefer |
This comment has been minimized.
This comment has been minimized.
|
Moving conversation to https://internals.rust-lang.org/t/cargo-test-and-backtraces/2518 |
jimmycuadra commentedMay 19, 2015
Having to set this somewhat arcane environment variable in order to get a backtrace on a failing test is not a good user experience. I'm not sure if there are any plans to implement this option as a flag to
rustcitself instead of an environment variable, or if there are any plans to make it on by default, but in any case I think Cargo should take care of turning it on for the user by default, at the very least when running tests.