diff --git a/samples/sample_extension/sample_asynchronous_extension.dart b/samples/sample_extension/sample_asynchronous_extension.dart index 69af1e555e2..d20fc2fba95 100644 --- a/samples/sample_extension/sample_asynchronous_extension.dart +++ b/samples/sample_extension/sample_asynchronous_extension.dart @@ -13,30 +13,25 @@ class RandomArray { static SendPort _port; Future> randomArray(int seed, int length) { - var completer = new Completer(); - var replyPort = new RawReceivePort(); - var args = new List(3); + var completer = Completer>(); + var replyPort = RawReceivePort(); + var args = List(3); args[0] = seed; args[1] = length; args[2] = replyPort.sendPort; _servicePort.send(args); - replyPort.handler = (result) { + replyPort.handler = (List result) { replyPort.close(); if (result != null) { completer.complete(result); } else { - completer.completeError(new Exception("Random array creation failed")); + completer.completeError(Exception('Random array creation failed')); } }; return completer.future; } - SendPort get _servicePort { - if (_port == null) { - _port = _newServicePort(); - } - return _port; - } + SendPort get _servicePort => _port ??= _newServicePort(); - SendPort _newServicePort() native "RandomArray_ServicePort"; + SendPort _newServicePort() native 'RandomArray_ServicePort'; } diff --git a/samples/sample_extension/sample_synchronous_extension.dart b/samples/sample_extension/sample_synchronous_extension.dart index 727cd4cf598..4c746201456 100644 --- a/samples/sample_extension/sample_synchronous_extension.dart +++ b/samples/sample_extension/sample_synchronous_extension.dart @@ -7,6 +7,6 @@ library sample_synchronous_extension; import 'dart-ext:sample_extension'; // The simplest way to call native code: top-level functions. -int systemRand() native "SystemRand"; -int noScopeSystemRand() native "NoScopeSystemRand"; -bool systemSrand(int seed) native "SystemSrand"; +int systemRand() native 'SystemRand'; +int noScopeSystemRand() native 'NoScopeSystemRand'; +bool systemSrand(int seed) native 'SystemSrand'; diff --git a/samples/sample_extension/test/sample_extension_test_helper.dart b/samples/sample_extension/test/sample_extension_test_helper.dart index 157942c928c..48c6cfd7cf3 100644 --- a/samples/sample_extension/test/sample_extension_test_helper.dart +++ b/samples/sample_extension/test/sample_extension_test_helper.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'dart:io'; -import 'dart:isolate'; import "package:expect/expect.dart"; import "package:path/path.dart"; @@ -45,7 +44,6 @@ Future run(String program, List arguments) async { } Future testNativeExtensions(String snapshotKind) async { - String buildDirectory = dirname(Platform.executable); Directory tempDirectory = Directory.systemTemp.createTempSync('sample_extension_'); try { @@ -73,14 +71,14 @@ Future testNativeExtensions(String snapshotKind) async { snapshot = script; } else { snapshot = join(testDirectory, "$test.snapshot"); - List args = new List.from(Platform.executableArguments); + List args = List.from(Platform.executableArguments); args.add('--snapshot=$snapshot'); args.add('--snapshot-kind=$snapshotKind'); args.add(script); await run(Platform.executable, args); } - List args = new List.from(Platform.executableArguments); + List args = List.from(Platform.executableArguments); args.add(snapshot); await run(Platform.executable, args); } diff --git a/samples/sample_extension/test_sample_asynchronous_extension.dart b/samples/sample_extension/test_sample_asynchronous_extension.dart index d8bea7e1cf7..4130f3d3b47 100644 --- a/samples/sample_extension/test_sample_asynchronous_extension.dart +++ b/samples/sample_extension/test_sample_asynchronous_extension.dart @@ -7,17 +7,15 @@ library test_sample_extension; import 'sample_asynchronous_extension.dart'; void check(bool condition, String message) { - if (!condition) { - throw new StateError(message); - } + if (!condition) throw StateError(message); } void main() { - RandomArray r = new RandomArray(); + RandomArray r = RandomArray(); r.randomArray(17, 100).then((list_100) { r.randomArray(17, 200).then((list_200) { for (var i = 0; i < 100; ++i) { - check(list_100[i] == list_200[i], "list_100[i] == list_200[i]"); + check(list_100[i] == list_200[i], 'list_100[i] == list_200[i]'); } }); }); @@ -27,32 +25,26 @@ void main() { r.randomArray(19, 256000).then(checkNormal); } -void checkNormal(List l) { +void checkNormal(List l) { // Count how many times each byte value occurs. Assert that the counts // are all within a reasonable (six-sigma) range. - List counts = new List.filled(256, 0); - for (var e in l) { - counts[e]++; - } - new RandomArray().randomArray(18, 256000).then(checkCorrelation(counts)); + final counts = List.filled(256, 0); + for (var e in l) counts[e]++; + RandomArray().randomArray(18, 256000).then(checkCorrelation(counts)); } -Function checkCorrelation(List counts) { - return (List l) { - List counts_2 = new List.filled(256, 0); - for (var e in l) { - counts_2[e]++; - } - var product = 0; - for (var i = 0; i < 256; ++i) { - check(counts[i] < 1200, "counts[i] < 1200"); - check(counts_2[i] < 1200, "counts_2[i] < 1200"); - check(counts[i] > 800, "counts[i] > 800"); - check(counts[i] > 800, "counts[i] > 800"); +void Function(List) checkCorrelation(List counts) => (l) { + final counts_2 = List.filled(256, 0); + for (var e in l) counts_2[e]++; + var product = 0; + for (var i = 0; i < 256; ++i) { + check(counts[i] < 1200, 'counts[i] < 1200'); + check(counts_2[i] < 1200, 'counts_2[i] < 1200'); + check(counts[i] > 800, 'counts[i] > 800'); + check(counts[i] > 800, 'counts[i] > 800'); - product += counts[i] * counts_2[i]; - } - check(product < 256000000 * 1.001, "product < 256000000 * 1.001"); - check(product > 256000000 * 0.999, "product > 256000000 * 0.999"); - }; -} + product += counts[i] * counts_2[i]; + } + check(product < 256000000 * 1.001, 'product < 256000000 * 1.001'); + check(product > 256000000 * 0.999, 'product > 256000000 * 0.999'); + }; diff --git a/samples/sample_extension/test_sample_synchronous_extension.dart b/samples/sample_extension/test_sample_synchronous_extension.dart index ac177245cea..3e61b313ea7 100644 --- a/samples/sample_extension/test_sample_synchronous_extension.dart +++ b/samples/sample_extension/test_sample_synchronous_extension.dart @@ -7,9 +7,8 @@ library test_sample_extension; import 'sample_synchronous_extension.dart'; void check(bool condition, String message) { - if (!condition) { - throw new StateError(message); - } + if (!condition) throw StateError(message); + print('$message - passed'); } void checkSystemRand() { @@ -17,17 +16,17 @@ void checkSystemRand() { var x1 = systemRand(); var x2 = systemRand(); var x3 = systemRand(); - check(x1 != x2, "x1 != x2"); - check(x1 != x3, "x1 != x3"); - check(x2 != x3, "x2 != x3"); + check(x1 != x2, 'x1 != x2'); + check(x1 != x3, 'x1 != x3'); + check(x2 != x3, 'x2 != x3'); systemSrand(17); - check(x1 == systemRand(), "x1 == systemRand()"); - check(x2 == systemRand(), "x2 == systemRand()"); - check(x3 == systemRand(), "x3 == systemRand()"); + check(x1 == systemRand(), 'x1 == systemRand()'); + check(x2 == systemRand(), 'x2 == systemRand()'); + check(x3 == systemRand(), 'x3 == systemRand()'); systemSrand(18); - check(x1 != systemRand(), "x1 != systemRand()"); - check(x2 != systemRand(), "x2 != systemRand()"); - check(x3 != systemRand(), "x3 != systemRand()"); + check(x1 != systemRand(), 'x1 != systemRand()'); + check(x2 != systemRand(), 'x2 != systemRand()'); + check(x3 != systemRand(), 'x3 != systemRand()'); } void checkNoScopeSystemRand() { @@ -35,17 +34,17 @@ void checkNoScopeSystemRand() { var x1 = noScopeSystemRand(); var x2 = noScopeSystemRand(); var x3 = noScopeSystemRand(); - check(x1 != x2, "x1 != x2"); - check(x1 != x3, "x1 != x3"); - check(x2 != x3, "x2 != x3"); + check(x1 != x2, 'x1 != x2'); + check(x1 != x3, 'x1 != x3'); + check(x2 != x3, 'x2 != x3'); systemSrand(17); - check(x1 == noScopeSystemRand(), "x1 == noScopeSystemRand()"); - check(x2 == noScopeSystemRand(), "x2 == noScopeSystemRand()"); - check(x3 == noScopeSystemRand(), "x3 == noScopeSystemRand()"); + check(x1 == noScopeSystemRand(), 'x1 == noScopeSystemRand()'); + check(x2 == noScopeSystemRand(), 'x2 == noScopeSystemRand()'); + check(x3 == noScopeSystemRand(), 'x3 == noScopeSystemRand()'); systemSrand(18); - check(x1 != noScopeSystemRand(), "x1 != noScopeSystemRand()"); - check(x2 != noScopeSystemRand(), "x2 != noScopeSystemRand()"); - check(x3 != noScopeSystemRand(), "x3 != noScopeSystemRand()"); + check(x1 != noScopeSystemRand(), 'x1 != noScopeSystemRand()'); + check(x2 != noScopeSystemRand(), 'x2 != noScopeSystemRand()'); + check(x3 != noScopeSystemRand(), 'x3 != noScopeSystemRand()'); } void main() { diff --git a/samples/samples.status b/samples/samples.status index 3af1d7e4bdc..cda70a83adf 100644 --- a/samples/samples.status +++ b/samples/samples.status @@ -26,10 +26,13 @@ sample_extension/test/sample_extension_app_snapshot_test: Pass, RuntimeError # I [ !$preview_dart_2 && ($runtime == dart_precompiled || $runtime == vm) ] *: SkipByDesign # Deprecating all Dart1 modes of execution -[ $compiler == app_jitk || $compiler == dartk || $compiler == dartkb || $compiler == dartkp ] +[ $compiler == app_jitk || $compiler == dartkb || $compiler == dartkp ] sample_extension/test/sample_extension_app_snapshot_test: RuntimeError sample_extension/test/sample_extension_test: RuntimeError +[ $compiler == dartk ] +sample_extension/test/sample_extension_app_snapshot_test: RuntimeError + # Skip tests that use dart:io [ $runtime == d8 || $browser ] sample_extension/*: Skip