Treat the expect and async_helper packages as opted in to NNBD.

This should enable strong mode tests to be fully NNBD opted in. At the
same time, legacy tests when run with the experiment off should
hopefully be able to still consume these libraries because they don't
actually use any NNBD features.

To do this, I changed the script that generates the SDK repo's package
config to not put in a language version for any package whose pubspec
has no SDK version. According to language versioning, that means the
package should be considered to be at the "current" version of the SDK
running the code.

In NNBD, that's opted in. With the experiment off, that is (presumably)
"opted out" in the sense that NNBD doesn't exist.

In order to *not* opt in some of the other packages that currently
lack SDK constraints, I put those in and pinned them to "^2.7.0" which
was what the package config script used to implicitly fill in for them.

I see a bunch of other changes in the generated package config too. The
update script probably hasn't been run in a while.

Change-Id: I55193d42eac0696a6b0105546551efa45a1f3252
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144305
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom 2020-04-27 21:04:56 +00:00 committed by commit-bot@chromium.org
parent 38c0fb78b6
commit d9bb487ca8
17 changed files with 67 additions and 136 deletions

View file

@ -11,7 +11,7 @@
"constraint, update this by running tools/generate_package_config.dart."
],
"configVersion": 2,
"generated": "2020-03-11T09:16:09.767708",
"generated": "2020-04-21T17:36:03.446742",
"generator": "tools/generate_package_config.dart",
"packages": [
{
@ -66,19 +66,18 @@
"name": "args",
"rootUri": "../third_party/pkg/args",
"packageUri": "lib/",
"languageVersion": "2.0"
"languageVersion": "2.3"
},
{
"name": "async",
"rootUri": "../third_party/pkg/async",
"packageUri": "lib/",
"languageVersion": "2.0"
"languageVersion": "2.2"
},
{
"name": "async_helper",
"rootUri": "../pkg/async_helper",
"packageUri": "lib/",
"languageVersion": "2.7"
"packageUri": "lib/"
},
{
"name": "bazel_worker",
@ -116,12 +115,6 @@
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "code_transformers",
"rootUri": "../third_party/pkg/code_transformers",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "collection",
"rootUri": "../third_party/pkg/collection",
@ -180,7 +173,7 @@
"name": "dart_style",
"rootUri": "../third_party/pkg_tested/dart_style",
"packageUri": "lib/",
"languageVersion": "2.3"
"languageVersion": "2.7"
},
{
"name": "dartdev",
@ -192,7 +185,7 @@
"name": "dartdoc",
"rootUri": "../third_party/pkg/dartdoc",
"packageUri": "lib/",
"languageVersion": "2.6"
"languageVersion": "2.7"
},
{
"name": "dartfix",
@ -204,7 +197,7 @@
"name": "dds",
"rootUri": "../pkg/dds",
"packageUri": "lib/",
"languageVersion": "2.3"
"languageVersion": "2.6"
},
{
"name": "dev_compiler",
@ -221,8 +214,7 @@
{
"name": "expect",
"rootUri": "../pkg/expect",
"packageUri": "lib/",
"languageVersion": "2.0"
"packageUri": "lib/"
},
{
"name": "ffi",
@ -273,12 +265,6 @@
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "func",
"rootUri": "../third_party/pkg/func",
"packageUri": "lib/",
"languageVersion": "1.9"
},
{
"name": "gardening",
"rootUri": "../tools/gardening",
@ -333,17 +319,11 @@
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "initialize",
"rootUri": "../third_party/pkg/initialize",
"packageUri": "lib/",
"languageVersion": "1.9"
},
{
"name": "intl",
"rootUri": "../third_party/pkg/intl",
"packageUri": "lib/",
"languageVersion": "2.0"
"languageVersion": "2.5"
},
{
"name": "js",
@ -379,7 +359,7 @@
"name": "linter",
"rootUri": "../third_party/pkg/linter",
"packageUri": "lib/",
"languageVersion": "2.2"
"languageVersion": "2.6"
},
{
"name": "logging",
@ -405,12 +385,6 @@
"packageUri": "lib/",
"languageVersion": "1.12"
},
{
"name": "metatest",
"rootUri": "../third_party/pkg/metatest",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "mime",
"rootUri": "../third_party/pkg/mime",
@ -453,12 +427,6 @@
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "observable",
"rootUri": "../third_party/pkg/observable",
"packageUri": "lib/",
"languageVersion": "1.19"
},
{
"name": "observatory",
"rootUri": "../runtime/observatory",
@ -470,12 +438,6 @@
"rootUri": "../runtime/observatory/tests/service/observatory_test_package",
"languageVersion": "2.7"
},
{
"name": "observe",
"rootUri": "../third_party/pkg/observe",
"packageUri": "lib/",
"languageVersion": "1.9"
},
{
"name": "package_config",
"rootUri": "../third_party/pkg_tested/package_config",
@ -494,30 +456,12 @@
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "platform",
"rootUri": "../third_party/pkg/platform",
"packageUri": "lib/",
"languageVersion": "1.24"
},
{
"name": "plugin",
"rootUri": "../third_party/pkg/plugin",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "pool",
"rootUri": "../third_party/pkg/pool",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "process",
"rootUri": "../third_party/pkg/process",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "protobuf",
"rootUri": "../third_party/pkg/protobuf/protobuf",
@ -534,7 +478,7 @@
"name": "pub_semver",
"rootUri": "../third_party/pkg/pub_semver",
"packageUri": "lib/",
"languageVersion": "1.0"
"languageVersion": "2.0"
},
{
"name": "quiver",
@ -548,12 +492,6 @@
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "scheduled_test",
"rootUri": "../third_party/pkg/scheduled_test",
"packageUri": "lib/",
"languageVersion": "1.22"
},
{
"name": "sdk_library_metadata",
"rootUri": "../sdk/lib/_internal/sdk_library_metadata",
@ -570,13 +508,13 @@
"name": "shelf_packages_handler",
"rootUri": "../third_party/pkg/shelf_packages_handler",
"packageUri": "lib/",
"languageVersion": "1.22"
"languageVersion": "2.0"
},
{
"name": "shelf_proxy",
"rootUri": "../third_party/pkg/shelf_proxy",
"packageUri": "lib/",
"languageVersion": "2.3"
"languageVersion": "2.0"
},
{
"name": "shelf_static",
@ -596,17 +534,11 @@
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "smoke",
"rootUri": "../third_party/pkg/smoke",
"packageUri": "lib/",
"languageVersion": "1.12"
},
{
"name": "source_map_stack_trace",
"rootUri": "../third_party/pkg/source_map_stack_trace",
"packageUri": "lib/",
"languageVersion": "1.8"
"languageVersion": "2.7"
},
{
"name": "source_maps",
@ -672,19 +604,19 @@
"name": "test",
"rootUri": "../third_party/pkg/test/pkgs/test",
"packageUri": "lib/",
"languageVersion": "2.2"
"languageVersion": "2.7"
},
{
"name": "test_api",
"rootUri": "../third_party/pkg/test/pkgs/test_api",
"packageUri": "lib/",
"languageVersion": "2.1"
"languageVersion": "2.7"
},
{
"name": "test_core",
"rootUri": "../third_party/pkg/test/pkgs/test_core",
"packageUri": "lib/",
"languageVersion": "2.1"
"languageVersion": "2.7"
},
{
"name": "test_descriptor",
@ -722,12 +654,6 @@
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "tuple",
"rootUri": "../third_party/pkg/tuple",
"packageUri": "lib/",
"languageVersion": "1.6"
},
{
"name": "typed_data",
"rootUri": "../third_party/pkg/typed_data",
@ -740,12 +666,6 @@
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "utf",
"rootUri": "../third_party/pkg/utf",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "vm",
"rootUri": "../pkg/vm",
@ -762,7 +682,7 @@
"name": "watcher",
"rootUri": "../third_party/pkg/watcher",
"packageUri": "lib/",
"languageVersion": "2.0"
"languageVersion": "2.2"
},
{
"name": "web_components",
@ -783,4 +703,4 @@
"languageVersion": "2.0"
}
]
}
}

View file

@ -1,6 +1,8 @@
name: analyzer_cli
description: Command line interface for the Dart Analyzer.
publish_to: none
environment:
sdk: "^2.7.0"
dependencies:
analyzer: ^0.37.0
args: '>=0.13.0 <2.0.0'

View file

@ -107,7 +107,10 @@ void asyncExpectThrows<T>(Future<void> f(),
[bool check(T error) = _pass, String reason = ""]) {
var type = "";
if (T != dynamic && T != Object) type = "<$T>";
var header = "asyncExpectThrows$type(${reason ?? ''}):";
// Handle null being passed in from legacy code while also avoiding producing
// an unnecessary null check warning here.
if ((reason as dynamic) == null) reason = "";
var header = "asyncExpectThrows$type(${reason}):";
// TODO(rnystrom): It might useful to validate that T is not bound to
// ExpectException since that won't work.
@ -124,7 +127,7 @@ void asyncExpectThrows<T>(Future<void> f(),
}
asyncStart();
result.then((_) {
result.then<Null>((_) {
throw ExpectException("$header Did not throw.");
}).catchError((error, stack) {
// A test failure doesn't count as throwing.

View file

@ -310,9 +310,7 @@ final _testToken = Object();
bool _initializedTestNameCallback = false;
/// The current combined name of the nesting [group] or [test].
// TODO(rnystrom): Type this "String?" when this library does not need to be
// NNBD agnostic.
dynamic _currentName = null;
String _currentName = "";
String _pushName(String newName) {
// Look up the current test name from the zone created for the test.
@ -322,7 +320,7 @@ String _pushName(String newName) {
}
var oldName = _currentName;
if (oldName == null) {
if (oldName == "") {
_currentName = newName;
} else {
_currentName = "$oldName $newName";

View file

@ -7,6 +7,5 @@ description: >-
language tests.
Third parties are discouraged from using this, and should use
the facilities provided in package:test.
dependencies:
expect: any

View file

@ -1,6 +1,9 @@
name: dart2native
publish_to: none
environment:
sdk: "^2.7.0"
# Add the bin/dart2native.dart script to the scripts pub installs.
executables:
dart2native:

View file

@ -490,7 +490,7 @@ class Expect {
*
* If the objects are iterables or maps, recurses into them.
*/
static void deepEquals(Object expected, Object actual) {
static void deepEquals(dynamic expected, dynamic actual) {
// Early exit check for equality.
if (expected == actual) return;
@ -560,8 +560,10 @@ class Expect {
// TODO(vsm): Make check and reason nullable or change call sites.
// Existing tests pass null to set a reason and/or pass them through
// via helpers.
check ??= _defaultCheck;
reason ??= "";
// TODO(rnystrom): Using the strange form below instead of "??=" to avoid
// warnings of unnecessary null checks when analyzed as NNBD code.
if ((check as dynamic) == null) check = _defaultCheck;
if ((reason as dynamic) == null) reason = "";
String msg = reason.isEmpty ? "" : "($reason)";
if (f is! Function()) {
// Only throws from executing the function body should count as throwing.
@ -570,7 +572,7 @@ class Expect {
}
try {
f();
} on Object catch (e, s) {
} catch (e, s) {
// A test failure doesn't count as throwing.
if (e is ExpectException) rethrow;
if (e is T && check(e as dynamic)) return;

View file

@ -26,7 +26,7 @@ import 'dart:async';
import 'package:expect/expect.dart';
typedef dynamic _Action();
typedef void _ExpectationFunction(Object actual);
typedef void _ExpectationFunction(dynamic actual);
final List<_Group> _groups = [new _Group()];
@ -124,7 +124,7 @@ void tearDown(body()) {
_groups.last.tearDownFunction = body;
}
void expect(Object actual, Object expected, {String reason = ""}) {
void expect(dynamic actual, dynamic expected, {String reason = ""}) {
// TODO(rnystrom): Do something useful with reason.
if (expected is! _Expectation) {
expected = equals(expected);
@ -138,19 +138,19 @@ void fail(String message) {
Expect.fail(message);
}
Object equals(Object value) => new _Expectation((actual) {
Object equals(dynamic value) => new _Expectation((actual) {
Expect.deepEquals(value, actual);
});
Object notEquals(Object value) => new _Expectation((actual) {
Object notEquals(dynamic value) => new _Expectation((actual) {
Expect.notEquals(value, actual);
});
Object unorderedEquals(Object value) => new _Expectation((actual) {
Object unorderedEquals(dynamic value) => new _Expectation((actual) {
Expect.setEquals(value as Iterable, actual as Iterable);
});
Object predicate(bool fn(Object value), [String description = ""]) =>
Object predicate(bool fn(dynamic value), [String description = ""]) =>
new _Expectation((actual) {
Expect.isTrue(fn(actual), description);
});
@ -169,7 +169,7 @@ Object greaterThan(num value) => new _Expectation((actual) {
}
});
Object same(Object value) => new _Expectation((actual) {
Object same(dynamic value) => new _Expectation((actual) {
Expect.identical(value, actual);
});

View file

@ -6,8 +6,5 @@ description: >
Third parties are discouraged from using this, and should use
the expect() function in the unit test library instead for
test assertions.
environment:
sdk: ">=2.0.0 <3.0.0"
dependencies:
meta: any

View file

@ -3,6 +3,9 @@ name: frontend_server
# version: do-not-upload
description: A resident kernel compiler
environment:
sdk: "^2.7.0"
dependencies:
build_integration:
path: ../build_integration

View file

@ -3,6 +3,9 @@ name: vm
# version: do-not-upload
description: VM specific Dart code and helper scripts
environment:
sdk: "^2.7.0"
dependencies:
build_integration:
path: ../build_integration

View file

@ -0,0 +1,4 @@
name: observatory_test_package
publish_to: none
environment:
sdk: '^2.7.0'

View file

@ -32,10 +32,12 @@ void testEscape(str, regexp) {
assertEquals("foo:bar:baz", str.split(regexp).join(":"));
}
void assertEquals(actual, expected, [message]) =>
void assertEquals(actual, expected, [String message = ""]) =>
Expect.equals(actual, expected, message);
void assertTrue(actual, [message]) => Expect.isTrue(actual, message);
void assertFalse(actual, [message]) => Expect.isFalse(actual, message);
void assertTrue(actual, [String message = ""]) =>
Expect.isTrue(actual, message);
void assertFalse(actual, [String message = ""]) =>
Expect.isFalse(actual, message);
void assertThrows(fn) => Expect.throws(fn);
void main() {

View file

@ -470,8 +470,8 @@ void testReplace() {
});
var params = uri.queryParametersAll;
Expect.equals(2, params.length);
Expect.listEquals(["42", "37"], params["x"]);
Expect.listEquals(["43", "38"], params["y"]);
Expect.listEquals(["42", "37"], params["x"]!);
Expect.listEquals(["43", "38"], params["y"]!);
}
main() {

View file

@ -191,10 +191,10 @@ void testUnsendable(name, func) {
});
Expect.throws(() {
noReply.sendPort.send(func);
}, null, "send direct");
}, (_) => true, "send direct");
Expect.throws(() {
noReply.sendPort.send([func]);
}, null, "send wrapped");
}, (_) => true, "send wrapped");
scheduleMicrotask(() {
noReply.close();
asyncEnd();

View file

@ -2,6 +2,8 @@
# gardening by making it a package.
name: gardening
#version: do-not-upload
environment:
sdk: "^2.7.0"
dependencies:
args:
http:

View file

@ -8,9 +8,6 @@ import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';
/// Version to use if a package doesn't constrain the language version.
final defaultVersion = Version(2, 7, 0);
final repoRoot = p.dirname(p.dirname(p.fromUri(Platform.script)));
final configFilePath = p.join(repoRoot, '.dart_tool/package_config.json');
@ -75,18 +72,14 @@ Iterable<Map<String, String>> makePackageConfigs(
List<String> packageDirs) sync* {
for (var packageDir in packageDirs) {
var version = pubspecLanguageVersion(packageDir);
if (version == null) {
print('Warning: Unknown language version for ${p.basename(packageDir)}.');
version = defaultVersion;
}
var hasLibDirectory = Directory(p.join(packageDir, 'lib')).existsSync();
yield {
'name': p.basename(packageDir),
'rootUri': p.relative(packageDir, from: p.dirname(configFilePath)),
if (hasLibDirectory) 'packageUri': 'lib/',
'languageVersion': '${version.major}.${version.minor}'
if (version != null)
'languageVersion': '${version.major}.${version.minor}'
};
}
}