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

fix: env macro multiline support #83

Merged
merged 1 commit into from
Feb 15, 2024
Merged

fix: env macro multiline support #83

merged 1 commit into from
Feb 15, 2024

Conversation

LNSD
Copy link
Contributor

@LNSD LNSD commented Feb 14, 2024

Context and problem description

The test_with::env and test_with::no_env macros fail to handle properly the following multiline env vars case:

#[test_with::env(
    IT_SOME_LONG_ENV_VAR_NAME_TEST_URL,
    IT_SOME_LONG_ENV_VAR_NAME_TEST_AUTH_TOKEN
)]
#[tokio::test]
async fn some_test() {}

This is problematic since it interferes with rustfmt, i.e., cargo fmt command automatically changes the long attribute lines in a multiline format.

A possible workaround would be to annotate the test with the #[rustfmt::skip] so the macro attributes are not laid out in separate lines:

#[rustfmt::skip]
#[test_with::env(IT_SOME_LONG_ENV_VAR_NAME_TEST_URL,IT_SOME_LONG_ENV_VAR_NAME_TEST_AUTH_TOKEN)]
#[tokio::test]
async fn some_test() {

Proposed solution

To fix the issue, I introduced the sanitize_env_vars_attr(...) function that properly handles the macro attributes arguments, removing any whitespace character and obtaining a slice containing the sanitized environment variable names.

Additionally, I added some unit tests covering the check_env_condition, check_no_env_condition, and sanitize_env_vars_attr functions.

@LNSD LNSD marked this pull request as ready for review February 14, 2024 16:14
@LNSD
Copy link
Contributor Author

LNSD commented Feb 14, 2024

I am not sure why the Lint/lint check is failing. But it seems unrelated to the code changes introduced in this PR

@yanganto
Copy link
Owner

Nice catch. I will handle on the linter, thanks for the PR

@yanganto yanganto merged commit f97db7d into yanganto:main Feb 15, 2024
1 of 2 checks passed
@LNSD LNSD deleted the fix-env-macro-multiline branch February 15, 2024 08:18
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.

2 participants