From b453c6bcba5526e127361e5ea45765d12431b996 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 14 Jan 2022 23:33:11 +0000 Subject: [PATCH] [gardening] Fix env_test/has_mirror_support. Fix the test so it reports that mirrors are not supported in aot configuration. Fixes https://github.com/dart-lang/sdk/issues/48125 Change-Id: I07fceebf8cbee8048988c8bd5287c8aec1bb8f0e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227582 Reviewed-by: Lasse Nielsen Reviewed-by: Sigmund Cherem Commit-Queue: Alexander Aprelev --- pkg/expect/lib/config.dart | 33 +++++++++++++++++++ pkg/expect/pubspec.yaml | 3 ++ pkg/modular_test/lib/src/loader.dart | 4 ++- .../expectation.txt | 13 +++++++- .../loader/valid_packages/expectation.txt | 13 +++++++- pkg/test_runner/lib/src/options.dart | 5 ++- tests/language/library/env_test.dart | 19 ++++------- tests/language_2/library/env_test.dart | 19 ++++------- 8 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 pkg/expect/lib/config.dart diff --git a/pkg/expect/lib/config.dart b/pkg/expect/lib/config.dart new file mode 100644 index 00000000000..52296453ea7 --- /dev/null +++ b/pkg/expect/lib/config.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// Access to the runner configuration this test is running in. +/// +/// Provides queries against and properties of the current configuration +/// that a test is being compiled and executed in. +/// +/// This library is separate from `expect.dart` because it uses +/// `fromEnvironment` constants that cannot be precompiled, +/// and we precompile `expect.dart`. + +library expect_config; + +import 'package:smith/smith.dart'; + +final Configuration _configuration = Configuration.parse( + const String.fromEnvironment("test_runner.configuration"), + {}); + +bool get isDart2jsConfiguration { + return _configuration.compiler == Compiler.dart2js; +} + +bool get isDdcConfiguration { + return _configuration.compiler == Compiler.dartdevk || + _configuration.compiler == Compiler.dartdevc; +} + +bool get isVmAotConfiguration { + return _configuration.compiler == Compiler.dartkp; +} diff --git a/pkg/expect/pubspec.yaml b/pkg/expect/pubspec.yaml index 70c2817088f..54c4ad12118 100644 --- a/pkg/expect/pubspec.yaml +++ b/pkg/expect/pubspec.yaml @@ -13,7 +13,10 @@ environment: dependencies: meta: any + smith: any dependency_overrides: meta: path: ../meta + smith: + path: ../smith diff --git a/pkg/modular_test/lib/src/loader.dart b/pkg/modular_test/lib/src/loader.dart index 90500179255..825e6796747 100644 --- a/pkg/modular_test/lib/src/loader.dart +++ b/pkg/modular_test/lib/src/loader.dart @@ -252,6 +252,7 @@ _detectCyclesAndRemoveUnreachable(Map modules, Module main) { /// Default entries for a .packages file with paths relative to the SDK root. List _defaultPackagesInput = utf8.encode(''' expect:pkg/expect/lib +smith:pkg/smith/lib async_helper:pkg/async_helper/lib meta:pkg/meta/lib collection:third_party/pkg/collection/lib @@ -264,7 +265,8 @@ collection:third_party/pkg/collection/lib // import graph, or adding tests that validate this is always up to date. String _defaultPackagesSpec = ''' dependencies: - expect: meta + expect: [meta, smith] + smith: [] meta: [] async_helper: [] collection: [] diff --git a/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt b/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt index e00a4e24211..3f41f4c2d72 100644 --- a/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt +++ b/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt @@ -4,7 +4,8 @@ expect is package? yes is shared? yes is sdk? no - dependencies: meta, sdk + dependencies: meta, smith, sdk + lib/config.dart lib/expect.dart lib/minitest.dart @@ -31,3 +32,13 @@ sdk is sdk? yes (no dependencies) (sdk sources omitted) + +smith + is package? yes + is shared? yes + is sdk? no + dependencies: sdk + lib/builder.dart + lib/configuration.dart + lib/smith.dart + lib/test_matrix.dart diff --git a/pkg/modular_test/test/loader/valid_packages/expectation.txt b/pkg/modular_test/test/loader/valid_packages/expectation.txt index e3bfaeb225b..12742779e66 100644 --- a/pkg/modular_test/test/loader/valid_packages/expectation.txt +++ b/pkg/modular_test/test/loader/valid_packages/expectation.txt @@ -4,7 +4,8 @@ expect is package? yes is shared? yes is sdk? no - dependencies: meta, sdk + dependencies: meta, smith, sdk + lib/config.dart lib/expect.dart lib/minitest.dart @@ -40,3 +41,13 @@ sdk is sdk? yes (no dependencies) (sdk sources omitted) + +smith + is package? yes + is shared? yes + is sdk? no + dependencies: sdk + lib/builder.dart + lib/configuration.dart + lib/smith.dart + lib/test_matrix.dart diff --git a/pkg/test_runner/lib/src/options.dart b/pkg/test_runner/lib/src/options.dart index 142b123c721..c028e33394a 100644 --- a/pkg/test_runner/lib/src/options.dart +++ b/pkg/test_runner/lib/src/options.dart @@ -778,7 +778,10 @@ has been specified on the command line.''', data['test_server_cross_origin_port'] as int, testDriverErrorPort: data["test_driver_error_port"] as int, localIP: data["local_ip"] as String, - sharedOptions: sharedOptions, + sharedOptions: [ + ...sharedOptions, + "-Dtest_runner.configuration=${innerConfiguration.name}" + ], packages: data["packages"] as String, serviceResponseSizesDirectory: data['service_response_sizes_directory'] as String, diff --git a/tests/language/library/env_test.dart b/tests/language/library/env_test.dart index 9adcf8d3597..3dc36ddadf8 100644 --- a/tests/language/library/env_test.dart +++ b/tests/language/library/env_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:expect/expect.dart'; +import 'package:expect/config.dart'; main() { const NOT_PRESENT = false; @@ -61,18 +62,12 @@ main() { const bool.fromEnvironment("dart.library.io", defaultValue: false)); } - bool? hasMirrorSupport; - hasMirrorSupport = true; //# has_mirror_support: ok - hasMirrorSupport = false; //# has_no_mirror_support: ok - - if (hasMirrorSupport != null) { - bool expectedResult = hasMirrorSupport ? true : NOT_PRESENT; - - Expect.equals( - expectedResult, - const bool.fromEnvironment("dart.library.mirrors", - defaultValue: NOT_PRESENT)); - } + bool hasMirrorSupport = !isDart2jsConfiguration && + !isDdcConfiguration && !isVmAotConfiguration; + Expect.equals( + hasMirrorSupport, + const bool.fromEnvironment("dart.library.mirrors", + defaultValue: NOT_PRESENT)); Expect.equals( NOT_PRESENT, diff --git a/tests/language_2/library/env_test.dart b/tests/language_2/library/env_test.dart index 8df205bd7f6..34fd5b55805 100644 --- a/tests/language_2/library/env_test.dart +++ b/tests/language_2/library/env_test.dart @@ -5,6 +5,7 @@ // @dart = 2.9 import 'package:expect/expect.dart'; +import 'package:expect/config.dart'; main() { const NOT_PRESENT = false; @@ -63,18 +64,12 @@ main() { const bool.fromEnvironment("dart.library.io", defaultValue: false)); } - bool hasMirrorSupport; - hasMirrorSupport = true; //# has_mirror_support: ok - hasMirrorSupport = false; //# has_no_mirror_support: ok - - if (hasMirrorSupport != null) { - bool expectedResult = hasMirrorSupport ? true : NOT_PRESENT; - - Expect.equals( - expectedResult, - const bool.fromEnvironment("dart.library.mirrors", - defaultValue: NOT_PRESENT)); - } + bool hasMirrorSupport = !isDart2jsConfiguration && + !isDdcConfiguration && !isVmAotConfiguration; + Expect.equals( + hasMirrorSupport, + const bool.fromEnvironment("dart.library.mirrors", + defaultValue: NOT_PRESENT)); Expect.equals( NOT_PRESENT,