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

Update macro to allow overriding the target at compile time #26

Conversation

inferiorhumanorgans
Copy link

Currently I'm using frondeus/test-case to parameterize some of my tests. Unfortunately it ends up creating a "super" test by concatenating the names of all of your variants (or worse the parameters). This isn't a huge problem until you want to look at the logs (e.g. with tracing-test) and all of a sudden your tracing target is well over a hundred characters (and not meaningful even if it were shorter).

The implementation feels a bit gross, but the general idea is to allow the user to override the tracing target with a macro attribute, e.g.

#[test_case::test_case(r#"value1")]
#[test_case::test_case(r#"value2")]
#[test_case::test_case(r#"value3")]
#[tracing_test::traced_test(target="shorter_name")]
fn the_test(line: &str)  {
    tracing::info!("meaningless info goes here");
    assert_eq!(line.len(), 6);
}

Would give output of:

2023-06-24T13:13:13.185821Z INFO shorter_name: crate::the_test: meaningless info goes here

Instead of:

2023-06-24T13:13:13.185821Z INFO value1_value2_value3: crate::the_test: meaningless info goes here

@dbrgn
Copy link
Owner

dbrgn commented Jun 25, 2023

Hi, thanks for the PR!

I can see the use case, but I'm a bit unsure whether I should merge or not, given the increased complexity of the macro (and thus the increased maintenance burden). Especially since the main problem is caused by an interaction with another crate, and since nothing breaks (it's juts an inconvenience). If this is a very rare case, then I'd tend towards not including the contribution.

For now, I'll keep the PR open, and if other people think it's useful, please leave a comment!

@inferiorhumanorgans
Copy link
Author

Ah, so I got that wrong. The long target name was being picked because I didn't give the variant an explicit name. I'm parsing apache logs so the input strings are pretty girthy.

However, it's a bit of an XY problem as my ultimate goal is to keep the log formatting during tests as terse as possible. For e.g. it'd be nice to hide the target completely as well as the timestamp and potentially even the level. For testing, IMO, that much detail isn't needed as the output is already grouped per test (and the target is going to be the same for the duration of the test anyhow).

@dbrgn
Copy link
Owner

dbrgn commented Feb 14, 2024

For now, in the interest of keeping maintenance effort low, I'll close this pull request. If other people think this would be useful, please leave a comment or a 👍🏻 on the PR.

@dbrgn dbrgn closed this Feb 14, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants