Cannot access environment on dart test
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
Should work according to https://github.com/dart-lang/test/issues/1509, but indeed does not work. Must be a regression.
/cc @bkonyi @natebosch
It seems it doesn't pick up any environment variables, either.
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
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
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?
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.
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).