-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RUST_BACKTRACE=1 should be on by default for cargo test
#1634
Comments
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 |
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. |
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. |
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. |
@alexcrichton how do you feel about non- |
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. |
@alexcrichton How do you feel about converting the magic environment variables people have to learn into global command-line flags? |
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. |
@alexcrichton the problem is that most people experience running Rust programs through Cargo, and having to learn about |
Having |
@jimmycuadra fwiw, For me, the question is simply whether someone would reasonably think of the change as a configuration of the command they typed. |
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 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 |
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. |
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 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. |
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) |
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." |
That said, I think I would prefer |
Moving conversation to https://internals.rust-lang.org/t/cargo-test-and-backtraces/2518 |
Got stuck a bit on the inverted image coordinate system. U and V are spacial, with positive Y up, while x and y are in the image coordinate system, with positive Y down. Background: rust-lang/cargo#1634
For anyone seeing this now and wondering if there is an easy work-around to set this by default, you can add a file in [env]
RUST_BACKTRACE = "1" to automatically set this env variable in all |
Can also be set/overridden via aliases, for example, I put this in my
|
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
rustc
itself 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.The text was updated successfully, but these errors were encountered: