Skip to content
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

Requires env-logger #15

Closed
eloff opened this issue Aug 14, 2021 · 8 comments
Closed

Requires env-logger #15

eloff opened this issue Aug 14, 2021 · 8 comments

Comments

@eloff
Copy link

eloff commented Aug 14, 2021

I get the error:

error[E0433]: failed to resolve: could not find `env_logger` in the list of imported crates
  --> src/tests/backend_auth_test.rs:10:1
   |
10 | #[test(tokio::test)]
   | ^^^^^^^^^^^^^^^^^^^^ could not find `env_logger` in the list of imported crates

Which goes away when I add env_logger to my dev-dependencies. I think it probably should be a dependency, not a dev-dependency for this crate.

@d-e-s-o
Copy link
Owner

d-e-s-o commented Aug 14, 2021

Unfortunately, that's not how it works, see: db6e700.

@d-e-s-o
Copy link
Owner

d-e-s-o commented Aug 31, 2021

I assume the above answers the question.

@d-e-s-o d-e-s-o closed this as completed Aug 31, 2021
@azdle
Copy link

azdle commented May 30, 2022

From the looks of it, proc-macro crates' dependencies are treated a bit
differently by Cargo than those of library crates. In particular, they
are not "inherited" by (and, hence, available in) the consuming crate.
As such, the dependency to env_logger that we had specified all along
was effectively unused: while we emitted code that requires the
dependency to be available, it still had to be specified explicitly in
the crate making use of test-env-log.
This change fixes the confusion by converting the dependency to a
dev-only one. We require still require it for testing because our tests
execute the emitted code.

Hey, @d-e-s-o. Apologies if you're already aware of this. If you wanted to make this work, you just need to structure this as two different crates. If you moved the current macro crate into a test-log-macros and then just pub use each macro from a new standard test-log crate. Then you could have env_log (and/or tracing-subcriber) as a dependency of the top-level test-log and have it actually get propagated up.

@d-e-s-o
Copy link
Owner

d-e-s-o commented May 31, 2022

Ah interesting. Yeah, I didn't think of that -- may be worthwhile to pursue.

@d-e-s-o
Copy link
Owner

d-e-s-o commented May 31, 2022

The one downside I see is that at least when using resolver v2 (the default), users would no longer be able to enable additional features of tracing/tracing-subscriber. Colored output, for example, should be configurable this way. On the bright side, we could facade it properly then behind a colored feature that applies to both log and tracing.

@azdle
Copy link

azdle commented May 31, 2022

Maybe there's some nuance in the v2 resolver that I'm not aware of, but based on rereading the section of the book it sounds like dev-dependencies' features are still unified if the dev-dependencies are used, so a parallel dev-dependency with added features should still work.

Or, maybe I'm misinterpreting what you meant would be a problem?

But, reguarless a test-log feature would still be an even nicer option if you like that.

@d-e-s-o
Copy link
Owner

d-e-s-o commented Jun 1, 2022

Ah indeed; just tried it out, it would still work. Glad we discussed that ;)

@Stargateur
Copy link

It would be nice to reopen this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants