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

Allow environment variables in #[files] attributes #277

Merged
merged 6 commits into from
Sep 26, 2024

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Sep 24, 2024

The environment variable must be passed to cargo test. Any variable name is valid and would be replaced. If a variable is not defined, the macro will error with the proper error message.

Fixes #276

The environment variable must be passed to cargo test. Any variable
name is valid and would be replaced. If a variable is not defined,
the macro will error with the proper error message.
@hansl
Copy link
Contributor Author

hansl commented Sep 24, 2024

I changed the test to add a HELLO_WORLD. I'm going to add a proper test, but this is just to show an example.

Here is the result when running with the environment variable undeclared:

CleanShot 2024-09-24 at 09 32 37@2x

Here is the same test with a proper value (just having fun doing up and down on path):

CleanShot 2024-09-24 at 09 33 20@2x

Please note that if the environment variable is declared but doesn't go into the proper folder, it is equivalent to specifying the wrong path in #[files]. So the tests don't run.

Copy link
Owner

@la10736 la10736 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice JOB!!! Thanks for your contribution.

Can you please add some unit tests, a line in change log and add document this new feature in
https://github.com/la10736/rstest/blob/master/rstest/src/lib.rs#L954 and https://github.com/la10736/rstest/blob/master/README.md?plain=1#L233 ?

rstest_macros/src/parse/rstest/files.rs Outdated Show resolved Hide resolved
rstest_macros/src/parse/rstest/files.rs Outdated Show resolved Hide resolved
rstest_macros/src/parse/rstest/files.rs Show resolved Hide resolved
@hansl
Copy link
Contributor Author

hansl commented Sep 26, 2024

@la10736 Thanks for the review.

Added a new #[base_dir = '...'] to allow to change the base dir for a test. It helps when using absolute paths (which cannot be used for #[files(...)]). Added tests for pretty much everything in this PR (checked locally with coverage). Also added a couple more integration tests.

PTAL

@hansl hansl requested a review from la10736 September 26, 2024 01:02
hansl added a commit to hansl/boa that referenced this pull request Sep 26, 2024
To run the tests, you require adding the `wpt-tests` feature
and setting the `WPT_ROOT` environment variable on the
command line. This is currently depending on a pending rstest
PR: la10736/rstest#277

The current set of curated tests are all working.
Copy link
Owner

@la10736 la10736 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an amazing work. Thanks again.
I would have preferred that formatting was separated by code changing and some more unit tests about parsing: but I really appreciated your work and I should find a compromise with my desiderata 😄

I'm not sure if I really like the base_dir feature but maybe it can be useful in some context.

@la10736 la10736 merged commit 8c232bc into la10736:master Sep 26, 2024
2 checks passed
@la10736
Copy link
Owner

la10736 commented Sep 26, 2024

Just a note about tests and coverage: pass in every lines (100% coverage) doesn't means spot all issues.... especially on on algorithms where the corner cases are not trivially identified by if branches. Anyway, your code and tests are really great!

Comment on lines +89 to +90
// Make sure cargo would rerun if the value of this environment variable changes.
println!("cargo::rerun-if-env-changed={var_name}");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it doesn't seem to work. I tried it this feature for base root and if just change, add or remove this variable the tests are not recompiled. If I add if to a build script it seams to work.

I'll remove it and add some documentation notes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it on my side, let me investigate a bit.

@hansl hansl deleted the allow-env-vars-in-files branch September 30, 2024 03:49
hansl added a commit to hansl/boa that referenced this pull request Sep 30, 2024
@hansl hansl mentioned this pull request Sep 30, 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.

Using ${ENV_VAR} environment variables in #[files] possible?
2 participants