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

Cannot access environment on dart test #1794

Open
mnordine opened this issue Nov 21, 2022 · 7 comments
Open

Cannot access environment on dart test #1794

mnordine opened this issue Nov 21, 2022 · 7 comments

Comments

@mnordine
Copy link

mnordine commented Nov 21, 2022

void main() {
  print(const bool.hasEnvironment('blah'));
}

dart -Dblah=true test outputs:

false
No tests were found.

It seems like the environment does not exist when you run dart test

Dart SDK 2.18.4

@mraleph mraleph transferred this issue from dart-lang/sdk Nov 21, 2022
@mraleph
Copy link
Member

mraleph commented Nov 21, 2022

Should work according to #1509, but indeed does not work. Must be a regression.

/cc @bkonyi @natebosch

@mnordine
Copy link
Author

mnordine commented Nov 21, 2022

It seems it doesn't pick up any environment variables, either.

@natebosch
Copy link
Member

You can get back to the old behavior with the flag --use-data-isolate-strategy

With the new strategy we might need to build support for parsing the arguments as passed to the test runner. If we did that we'd probably want it to be general and work for dart2js tests as well.

cc @jakemac53

@mnordine
Copy link
Author

mnordine commented Nov 21, 2022

You can get back to the old behavior with the flag --use-data-isolate-strategy

Confirmed on my machine that dart -Dblah=true test --use-data-isolate-strategy works.

It still doesn't pick up any environment variables, though.

So If I do

MY_VAR=true
import 'dart:io' show Platform;

void main() {
  print(Platform.environment['MY_VAR']);
}

dart test --use-data-isolate-strategy outputs:

null

@natebosch
Copy link
Member

It still doesn't pick up any environment variables, though.

I can't repro. Either strategy picks up the environment for me. Are you confident that the environment for the dart test process has the variable?

@mnordine
Copy link
Author

mnordine commented Nov 22, 2022

Are you confident that the environment for the dart test process has the variable?

My bad, I didn't export the env var. After I did, it works.

@jakemac53
Copy link
Contributor

I don't see this as a high priority feature personally, and adding -D support may also further complicate any future plans regarding DDC or other modular compilation. If we add it, I would probably want to make it only a global option to alleviate that issue (build_web_compilers also only supports it as a global for this reason).

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