diff --git a/BUILD.gn b/BUILD.gn index a7d7e22adc3..161b9f5c83d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,6 +29,7 @@ group("runtime") { "runtime/bin:process_test", "runtime/bin:test_extension", "runtime/bin:sample_extension", + "runtime/vm:patched_sdk", ] } @@ -36,6 +37,7 @@ group("runtime_precompiled") { deps = [ "runtime/bin:dart_precompiled_runtime", "runtime/bin:dart_bootstrap($host_toolchain)", + "runtime/vm:patched_sdk", ] } @@ -48,6 +50,7 @@ group("runtime_and_noopt") { "runtime/bin:process_test", "runtime/bin:test_extension", "runtime/bin:sample_extension", + "runtime/vm:patched_sdk", ] } diff --git a/dart.gyp b/dart.gyp index c24fbc7ca6f..1bbf75e28e7 100644 --- a/dart.gyp +++ b/dart.gyp @@ -30,6 +30,7 @@ 'runtime/dart-runtime.gyp:process_test', 'runtime/dart-runtime.gyp:test_extension', 'runtime/dart-runtime.gyp:sample_extension', + 'runtime/dart-runtime.gyp:generate_patched_sdk#host', ], }, { @@ -41,6 +42,7 @@ 'dependencies': [ 'runtime/dart-runtime.gyp:dart_precompiled_runtime', 'runtime/dart-runtime.gyp:dart_bootstrap#host', + 'runtime/dart-runtime.gyp:generate_patched_sdk#host', ], }, { @@ -57,8 +59,10 @@ 'runtime/dart-runtime.gyp:process_test', 'runtime/dart-runtime.gyp:test_extension', 'runtime/dart-runtime.gyp:sample_extension', + 'runtime/dart-runtime.gyp:generate_patched_sdk#host', ], }, + { 'target_name': 'create_sdk', 'type': 'none', diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart index d4aa012467d..ceba8cd0348 100644 --- a/runtime/bin/builtin.dart +++ b/runtime/bin/builtin.dart @@ -1,5 +1,5 @@ // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file -// for details. All rights solveserved. Use of this source code is governed by a +// 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. library builtin; diff --git a/runtime/bin/common_patch.dart b/runtime/bin/common_patch.dart index b485dc9a06b..3e9be62fa2b 100644 --- a/runtime/bin/common_patch.dart +++ b/runtime/bin/common_patch.dart @@ -2,6 +2,8 @@ // 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. +import 'dart:nativewrappers'; + @patch class _IOCrypto { @patch static Uint8List getRandomBytes(int count) native "Crypto_GetRandomBytes"; @@ -10,4 +12,4 @@ _setupHooks() { VMLibraryHooks.eventHandlerSendData = _EventHandler._sendData; VMLibraryHooks.timerMillisecondClock = _EventHandler._timerMillisecondClock; -} \ No newline at end of file +} diff --git a/runtime/bin/eventhandler_patch.dart b/runtime/bin/eventhandler_patch.dart index effe4029164..588a4b82ab1 100644 --- a/runtime/bin/eventhandler_patch.dart +++ b/runtime/bin/eventhandler_patch.dart @@ -2,8 +2,6 @@ // 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. -import 'dart:nativewrappers'; - @patch class _EventHandler { @patch static void _sendData(Object sender, SendPort sendPort, diff --git a/runtime/bin/process_patch.dart b/runtime/bin/process_patch.dart index bfb09db6685..d34a28c8156 100644 --- a/runtime/bin/process_patch.dart +++ b/runtime/bin/process_patch.dart @@ -125,9 +125,9 @@ class _SignalController { } } - @patch static _setSignalHandler(int signal) + static _setSignalHandler(int signal) native "Process_SetSignalHandler"; - @patch static int _clearSignalHandler(int signal) + static int _clearSignalHandler(int signal) native "Process_ClearSignalHandler"; } diff --git a/runtime/bin/stdio_patch.dart b/runtime/bin/stdio_patch.dart index b3dc68eef75..392ae1c03ce 100644 --- a/runtime/bin/stdio_patch.dart +++ b/runtime/bin/stdio_patch.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. @patch class _StdIOUtils { - static Stdin _getStdioInputStream() { + @patch static Stdin _getStdioInputStream() { switch (_getStdioHandleType(0)) { case _STDIO_HANDLE_TYPE_TERMINAL: case _STDIO_HANDLE_TYPE_PIPE: @@ -16,7 +16,7 @@ } } - static _getStdioOutputStream(int fd) { + @patch static _getStdioOutputStream(int fd) { assert(fd == 1 || fd == 2); switch (_getStdioHandleType(fd)) { case _STDIO_HANDLE_TYPE_TERMINAL: @@ -29,12 +29,12 @@ } } - static int _socketType(Socket socket) { + @patch static int _socketType(Socket socket) { if (socket is _Socket) return _nativeSocketType(socket._nativeSocket); return null; } - static int _nativeSocketType(_NativeSocket nativeSocket) { + @patch static int _nativeSocketType(_NativeSocket nativeSocket) { var result = _getSocketType(nativeSocket); if (result is OSError) { throw new FileSystemException( @@ -43,7 +43,7 @@ return result; } - static _getStdioHandleType(int fd) native "File_GetStdioHandleType"; + @patch static _getStdioHandleType(int fd) native "File_GetStdioHandleType"; } @patch class Stdin { diff --git a/runtime/lib/collection_patch.dart b/runtime/lib/collection_patch.dart index ed76535fc7f..0dea1458f3e 100644 --- a/runtime/lib/collection_patch.dart +++ b/runtime/lib/collection_patch.dart @@ -2,10 +2,13 @@ // 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. +import 'dart:typed_data'; +import 'dart:_internal' as internal; + @patch class HashMap { @patch factory HashMap({ bool equals(K key1, K key2), - int hashCode(K key), - bool isValidKey(potentialKey) }) { + int hashCode(K key), + bool isValidKey(potentialKey) }) { if (isValidKey == null) { if (hashCode == null) { if (equals == null) { diff --git a/runtime/lib/collection_sources.gypi b/runtime/lib/collection_sources.gypi index 0e1e21e2e39..857698070ae 100644 --- a/runtime/lib/collection_sources.gypi +++ b/runtime/lib/collection_sources.gypi @@ -4,6 +4,8 @@ { 'sources': [ + # collection_patch.dart needs to be the first dart file because it contains + # imports. 'collection_patch.dart', 'compact_hash.dart', 'linked_hash_map.cc', diff --git a/runtime/lib/compact_hash.dart b/runtime/lib/compact_hash.dart index 9912d07f2af..86ec9d83acf 100644 --- a/runtime/lib/compact_hash.dart +++ b/runtime/lib/compact_hash.dart @@ -2,9 +2,6 @@ // 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. -import 'dart:typed_data'; -import 'dart:_internal' as internal; - // Hash table with open addressing that separates the index from keys/values. abstract class _HashFieldBase { diff --git a/runtime/lib/core_patch.dart b/runtime/lib/core_patch.dart index f06c98b29ef..29357aec4d8 100644 --- a/runtime/lib/core_patch.dart +++ b/runtime/lib/core_patch.dart @@ -2,8 +2,13 @@ // 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. +import "dart:async"; +import "dart:collection" show LinkedList, LinkedListEntry; +import 'dart:convert' show ASCII, JSON; +import "dart:isolate"; import "dart:math"; import "dart:typed_data"; +import 'dart:_internal' as internal; // Equivalent of calling FATAL from C++ code. _fatal(msg) native "DartCore_fatal"; diff --git a/runtime/lib/developer.dart b/runtime/lib/developer.dart index ec3d38b621c..4c6ea7d3216 100644 --- a/runtime/lib/developer.dart +++ b/runtime/lib/developer.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:isolate'; +import 'dart:_internal'; @patch bool debugger({bool when: true, String message}) native "Developer_debugger"; diff --git a/runtime/lib/developer_sources.gypi b/runtime/lib/developer_sources.gypi index e3f1ea65878..896f2e1ab5f 100644 --- a/runtime/lib/developer_sources.gypi +++ b/runtime/lib/developer_sources.gypi @@ -7,6 +7,8 @@ { 'sources': [ 'developer.cc', + # developer.dart needs to be the first dart file because it contains + # imports. 'developer.dart', 'profiler.cc', 'profiler.dart', diff --git a/runtime/lib/errors_patch.dart b/runtime/lib/errors_patch.dart index 654dfa3e902..bf0405922f5 100644 --- a/runtime/lib/errors_patch.dart +++ b/runtime/lib/errors_patch.dart @@ -2,9 +2,6 @@ // 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. -import 'dart:_internal' as internal; -import 'dart:convert' show JSON; - @patch class Error { @patch static String _objectToString(Object object) { return Object._toString(object); @@ -206,6 +203,7 @@ class _InternalError { // that no information is available. final int _invocation_type; + @patch NoSuchMethodError(Object this._receiver, Symbol this._memberName, List this._arguments, diff --git a/runtime/lib/integers_patch.dart b/runtime/lib/integers_patch.dart index 67db1767ecc..6f8b38456ef 100644 --- a/runtime/lib/integers_patch.dart +++ b/runtime/lib/integers_patch.dart @@ -5,8 +5,6 @@ // VM implementation of int. -import 'dart:_internal' as internal; - @patch class int { @patch const factory int.fromEnvironment(String name, diff --git a/runtime/lib/lib_prefix.dart b/runtime/lib/lib_prefix.dart index f457b020f8a..1b0e87d79dc 100644 --- a/runtime/lib/lib_prefix.dart +++ b/runtime/lib/lib_prefix.dart @@ -2,9 +2,6 @@ // 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. -import "dart:async"; -import "dart:isolate"; - // This type corresponds to the VM-internal class LibraryPrefix. class _LibraryPrefix { bool _load() native "LibraryPrefix_load"; diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart index 8fdd7ba751b..0305f128913 100644 --- a/runtime/lib/mirrors_impl.dart +++ b/runtime/lib/mirrors_impl.dart @@ -4,9 +4,6 @@ // VM-specific implementation of the dart:mirrors library. -import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; -import "dart:async" show Future; - var dirty = false; final emptyList = new UnmodifiableListView([]); final emptyMap = new UnmodifiableMapView({}); diff --git a/runtime/lib/mirrors_patch.dart b/runtime/lib/mirrors_patch.dart index 2e2da5ba892..03bd1b6eca5 100644 --- a/runtime/lib/mirrors_patch.dart +++ b/runtime/lib/mirrors_patch.dart @@ -2,6 +2,8 @@ // 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. +import "dart:async" show Future; +import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; import "dart:_internal" as internal; /** diff --git a/runtime/lib/mirrors_sources.gypi b/runtime/lib/mirrors_sources.gypi index 295ab856b39..46da0828d8a 100644 --- a/runtime/lib/mirrors_sources.gypi +++ b/runtime/lib/mirrors_sources.gypi @@ -8,6 +8,8 @@ 'sources': [ 'mirrors.cc', 'mirrors.h', + # mirrors_patch.dart needs to be the first dart file because it contains + # imports. 'mirrors_patch.dart', 'mirrors_impl.dart', 'mirror_reference.dart', diff --git a/runtime/lib/null_patch.dart b/runtime/lib/null_patch.dart index 312804e6b84..0f22e67e567 100644 --- a/runtime/lib/null_patch.dart +++ b/runtime/lib/null_patch.dart @@ -5,14 +5,7 @@ // Dart core library. @patch class Null { - - factory Null._uninstantiable() { - throw new UnsupportedError("class Null cannot be instantiated"); - } - static const _HASH_CODE = 2011; // The year Dart was announced and a prime. int get hashCode => _HASH_CODE; int get _identityHashCode => _HASH_CODE; - - String toString() => 'null'; } diff --git a/runtime/lib/object_patch.dart b/runtime/lib/object_patch.dart index 4fb4db5a899..d83ba13a34a 100644 --- a/runtime/lib/object_patch.dart +++ b/runtime/lib/object_patch.dart @@ -5,7 +5,7 @@ @patch class Object { // The VM has its own implementation of equals. - bool operator ==(other) native "Object_equals"; + @patch bool operator ==(other) native "Object_equals"; // Helpers used to implement hashCode. If a hashCode is used, we remember it // in a weak table in the VM. A new hashCode value is calculated using a diff --git a/runtime/lib/profiler.dart b/runtime/lib/profiler.dart index 2a085c2438d..b60760a4c01 100644 --- a/runtime/lib/profiler.dart +++ b/runtime/lib/profiler.dart @@ -2,8 +2,6 @@ // 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. -import 'dart:_internal'; - @patch class UserTag { @patch factory UserTag(String label) { return new _UserTag(label); diff --git a/runtime/lib/regexp_patch.dart b/runtime/lib/regexp_patch.dart index 7e8bc194998..a9ccd55527e 100644 --- a/runtime/lib/regexp_patch.dart +++ b/runtime/lib/regexp_patch.dart @@ -2,8 +2,6 @@ // 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. -import "dart:collection" show LinkedList, LinkedListEntry; - @patch class RegExp { @patch factory RegExp(String source, {bool multiLine: false, diff --git a/runtime/lib/timeline.dart b/runtime/lib/timeline.dart index da5760eb556..b2aa16506e5 100644 --- a/runtime/lib/timeline.dart +++ b/runtime/lib/timeline.dart @@ -2,8 +2,6 @@ // 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. -import 'dart:_internal'; - @patch bool _isDartStreamEnabled() native "Timeline_isDartStreamEnabled"; @patch int _getTraceClock() native "Timeline_getTraceClock"; diff --git a/runtime/lib/typed_data.dart b/runtime/lib/typed_data.dart index c010555e214..0875fbc989e 100644 --- a/runtime/lib/typed_data.dart +++ b/runtime/lib/typed_data.dart @@ -2,6 +2,9 @@ // 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. +// Unlike the other SDK libraries, this file is not a patch that is applied to +// dart:typed_data. Instead, it completely replaces the implementation from the +// SDK. library dart.typed_data; import "dart:_internal"; diff --git a/runtime/lib/uri_patch.dart b/runtime/lib/uri_patch.dart index 0ce6b11b168..27e5efda7ec 100644 --- a/runtime/lib/uri_patch.dart +++ b/runtime/lib/uri_patch.dart @@ -2,8 +2,6 @@ // 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. -import "dart:convert" show ASCII; - // VM implementation of Uri. typedef Uri _UriBaseClosure(); diff --git a/runtime/tools/concatenate_patches.py b/runtime/tools/concatenate_patches.py new file mode 100644 index 00000000000..1653066c291 --- /dev/null +++ b/runtime/tools/concatenate_patches.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# Copyright (c) 2016, 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. + +from optparse import OptionParser + +def writePatch(output_file_name, input_file_names): + dart_file_names = filter(lambda name: name.endswith('.dart'), + input_file_names) + with open(output_file_name, 'w') as output_file: + for dart_file_name in dart_file_names: + with open(dart_file_name, 'r') as dart_file: + output_file.write(dart_file.read()) + + +def main(): + parser = OptionParser() + parser.add_option('--output', action='store', type='string', + help='output file path') + (options, args) = parser.parse_args() + if not options.output: + parser.error('missing --output option\n') + if len(args) == 0: + parser.error('no input files given\n') + writePatch(options.output, args) + + +if __name__ == '__main__': + main() diff --git a/runtime/vm/BUILD.gn b/runtime/vm/BUILD.gn index d7edae64617..562f750024e 100644 --- a/runtime/vm/BUILD.gn +++ b/runtime/vm/BUILD.gn @@ -141,17 +141,13 @@ static_library("libdart_vm_nosnapshot_with_precompiler") { } -template("generate_library_source") { - assert(defined(invoker.libname), "Need libname in $target_name") +template("process_library_source") { assert(defined(invoker.filename), "Need a filename in $target_name") - assert(defined(invoker.kind), "Need kind in $target_name") assert(defined(invoker.output), "Need output in $target_name") assert(defined(invoker.path), "Need path in $target_name") action(target_name) { visibility = [ ":*" ] # Only targets in this file can see this. - libname = invoker.libname filename = invoker.filename - kind = invoker.kind path = invoker.path lib_sources_gypi = @@ -162,20 +158,37 @@ template("generate_library_source") { lib_sources = rebase_path(lib_sources_gypi.sources, ".", path) - script = "../tools/gen_library_src_paths.py" - inputs = [ - "../tools/gen_library_src_paths.py", - "../lib/libgen_in.cc", - ] + script = invoker.script + inputs = invoker.inputs + [script] inputs += lib_sources - outputs = [ invoker.output, ] + outputs = [invoker.output] + args = invoker.args + rebase_path(lib_sources, root_build_dir) + } +} + + +template("generate_library_source") { + assert(defined(invoker.libname), "Need libname in $target_name") + assert(defined(invoker.filename), "Need a filename in $target_name") + assert(defined(invoker.kind), "Need kind in $target_name") + assert(defined(invoker.output), "Need output in $target_name") + assert(defined(invoker.path), "Need path in $target_name") + + process_library_source(target_name) { + libname = invoker.libname + filename = invoker.filename + kind = invoker.kind + output = invoker.output + path = invoker.path + script = "../tools/gen_library_src_paths.py" + inputs = ["../lib/libgen_in.cc"] args = [ "--output", rebase_path(invoker.output, root_build_dir), "--input_cc", rebase_path("../lib/libgen_in.cc", root_build_dir), "--include", "vm/bootstrap.h", "--var_name", "dart::Bootstrap::${libname}_${kind}_paths_", - "--library_name", "dart:${libname}",] + - rebase_path(lib_sources, root_build_dir) + "--library_name", "dart:${libname}", + ] } } @@ -299,3 +312,104 @@ generate_core_libraries("core_libraries") { ["_vmservice", "vmservice", true, "../../sdk/lib/vmservice", "../lib"], ] } + + +template("concatenate_patch") { + assert(defined(invoker.libname), "Need a name in $target_name") + assert(defined(invoker.dir), "Need a dir in $target_name") + assert(defined(invoker.output), "Need an output in $target_name") + + process_library_source(target_name) { + output = invoker.output + path = "../${invoker.dir}" + filename = invoker.libname + script = "../tools/concatenate_patches.py" + args = [ "--output", rebase_path(output, root_build_dir)] + inputs = [] + } +} + + +template("generate_patched_sdk") { + assert(defined(invoker.libraries), "Need libraries in $target_name") + + concatenation_target_names = [] + concatenation_files = [] + + # Concatenate vm library patches. + foreach(library, invoker.libraries) { + name = library[1] + + target_output = "$target_gen_dir/patches/${name}_patch.dart" + concatenate_patch("concatenate_${name}_patch") { + libname = name + dir = library[0] + output = target_output + } + concatenation_target_names += [ ":concatenate_${name}_patch" ] + concatenation_files += [ target_output ] + } + + # Build the patched sdk out of the concatenated patches and the special + # libraries. + action(target_name) { + deps = concatenation_target_names + + patches_dir = "$target_gen_dir/patches" + patched_sdk_dir = "$target_gen_dir/patched_sdk" + + script = "../../tools/patch_sdk.py" + + # We list all files which make up the sdk (modulo patches) and get them back + # as a GN list object. + shared_sdk_sources = exec_script( + "../../tools/list_dart_files.py", ["../../sdk/lib"], "list lines") + + # We list the `patch_sdk.dart` tool here because the [script] (which is + # implicitly an input) will call it. + inputs = [ "../../tools/patch_sdk.dart" ] + # Files below are not patches, they will not be in [concatenation_files] but + # the `patch_sdk.dart` script will copy them into the patched sdk. + inputs += [ + "../lib/typed_data.dart", + "../bin/builtin.dart", + "../bin/vmservice/vmservice_io.dart", + "../bin/vmservice/loader.dart", + "../bin/vmservice/server.dart", + ] + # Add all the normal sdk sources. + inputs += shared_sdk_sources + # Add all the concatenated patch files. + inputs += concatenation_files + + outputs = [ + # Instead of listing all outputs we list a single well-known one. + "${patched_sdk_dir}/lib/core/core.dart", + ] + + args = [ + "vm", + rebase_path("../../sdk"), + rebase_path(patches_dir, root_build_dir), + rebase_path(patched_sdk_dir, root_build_dir), + ] + } +} + + +generate_patched_sdk("patched_sdk") { + libraries = [ + ["lib", "async"], + ["lib", "collection"], + ["lib", "convert"], + ["lib", "core"], + ["lib", "developer"], + ["lib", "internal"], + ["lib", "isolate"], + ["lib", "math"], + ["lib", "mirrors"], + ["lib", "profiler"], + ["lib", "vmservice"], + ["bin", "io"], + ] +} diff --git a/runtime/vm/vm.gypi b/runtime/vm/vm.gypi index a08a1b8bb5a..04e4abdd23d 100644 --- a/runtime/vm/vm.gypi +++ b/runtime/vm/vm.gypi @@ -967,6 +967,10 @@ ] }, { + # Unlike the other libraries in the SDK, dart:typed_data is not + # implemented as a patch applied to the base SDK implementation. + # Instead the VM has a complete replacement library and the + # implementation in the SDK is ignored. 'target_name': 'generate_typed_data_cc_file', 'type': 'none', 'toolsets':['host'], @@ -1234,5 +1238,453 @@ }, ] }, + { + 'target_name': 'generate_patched_sdk', + 'type': 'none', + 'toolsets': ['host'], + 'dependencies': [ + 'generate_async_library_patch', + 'generate_collection_library_patch', + 'generate_convert_library_patch', + 'generate_core_library_patch', + 'generate_developer_library_patch', + 'generate_internal_library_patch', + 'generate_io_library_patch', + 'generate_isolate_library_patch', + 'generate_math_library_patch', + 'generate_mirrors_library_patch', + 'generate_profiler_library_patch', + 'generate_vmservice_library_patch', + ], + 'actions': [ + { + 'action_name': 'patch_sdk', + 'inputs': [ + ' C; +test1() => D; + +main() { + var c = new C(); + var d = new D(); + Expect.isTrue(test0() == C); + Expect.isTrue(test1() == D); + Expect.isTrue(c is C); + Expect.isTrue(c is! D); + Expect.isTrue(d is C); + Expect.isTrue(d is D); + Expect.isTrue(c as C == c); + Expect.isTrue(d as C == d); + Expect.isTrue(d as D == d); +} diff --git a/tests/kernel/unsorted/block_scope_test.dart b/tests/kernel/unsorted/block_scope_test.dart new file mode 100644 index 00000000000..ae54352a81e --- /dev/null +++ b/tests/kernel/unsorted/block_scope_test.dart @@ -0,0 +1,60 @@ +// Copyright (c) 2016, 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. + +// Tests of block scoping. + +import 'expect.dart'; + +bool oracle() => true; + +test0() { + var x = 'outer', y = x; + Expect.isTrue(x == 'outer'); + Expect.isTrue(y == 'outer'); + { var x = 'inner'; + Expect.isTrue(x == 'inner'); + Expect.isTrue(y == 'outer'); + } + Expect.isTrue(x == 'outer'); + Expect.isTrue(y == 'outer'); + + if (oracle()) { + var y = 'inner'; + Expect.isTrue(x == 'outer'); + Expect.isTrue(y == 'inner'); + } else { + Expect.isTrue(false); + } + Expect.isTrue(x == 'outer'); + Expect.isTrue(y == 'outer'); +} + +var x = 'toplevel'; + +test1() { + var y = 'outer'; + Expect.isTrue(x == 'toplevel'); + Expect.isTrue(y == 'outer'); + { var x = 'inner'; + Expect.isTrue(x == 'inner'); + Expect.isTrue(y == 'outer'); + } + Expect.isTrue(x == 'toplevel'); + Expect.isTrue(y == 'outer'); + + if (oracle()) { + var y = 'inner'; + Expect.isTrue(x == 'toplevel'); + Expect.isTrue(y == 'inner'); + } else { + Expect.isTrue(false); + } + Expect.isTrue(x == 'toplevel'); + Expect.isTrue(y == 'outer'); +} + +main() { + test0(); + test1(); +} diff --git a/tests/kernel/unsorted/breakable_statement_test.dart b/tests/kernel/unsorted/breakable_statement_test.dart new file mode 100644 index 00000000000..277a32c3e7a --- /dev/null +++ b/tests/kernel/unsorted/breakable_statement_test.dart @@ -0,0 +1,81 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +testFor() { + int current; + for (int i = 0; i < 100; i++) { + current = i; + if (i > 41) break; + } + Expect.isTrue(current == 42); +} + +testWhile() { + int i = 0; + while (i < 100) { + if (++i > 41) break; + } + Expect.isTrue(i == 42); +} + +testDoWhile() { + int i = 0; + do { + if (++i > 41) break; + } while (i < 100); + Expect.isTrue(i == 42); +} + +testLabledBreakOutermost() { + int i = 0; + outer: { + middle: { + while (i < 100) { + if (++i > 41) break outer; + } + i++; + } + i++; + } + Expect.isTrue(i == 42); +} + +testLabledBreakMiddle() { + int i = 0; + outer: { + middle: { + while (i < 100) { + if (++i > 41) break middle; + } + i++; + } + i++; + } + Expect.isTrue(i == 43); +} + +testLabledBreakInner() { + int i = 0; + outer: { + middle: { + while (i < 100) { + if (++i > 41) break; + } + i++; + } + i++; + } + Expect.isTrue(i == 44); +} + +main() { + testFor(); + testWhile(); + testDoWhile(); + testLabledBreakOutermost(); + testLabledBreakMiddle(); + testLabledBreakInner(); +} diff --git a/tests/kernel/unsorted/closures_regression_test.dart b/tests/kernel/unsorted/closures_regression_test.dart new file mode 100644 index 00000000000..ac45e1bc4ca --- /dev/null +++ b/tests/kernel/unsorted/closures_regression_test.dart @@ -0,0 +1,22 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +f(fun) => fun(); +class A { + identity(arg) { + return f(() { + print(this); + return f(() { + return this; + }); + }); + } +} + +main() { + var a = new A(); + Expect.isTrue(identical(a.identity(42), a)); +} diff --git a/tests/kernel/unsorted/closures_test.dart b/tests/kernel/unsorted/closures_test.dart new file mode 100644 index 00000000000..da1279404f4 --- /dev/null +++ b/tests/kernel/unsorted/closures_test.dart @@ -0,0 +1,65 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class Base { + int constant1000() => 1000; +} + +class Foo extends Base { + final int base; + Foo(this.base); + + nestedAdderFunction(a, b, c, d, e) { + var result = a + b; + return () { + var result2 = c + d; + return () { + return base + result + result2 + e; + }; + }; + } + + nestedAdderFunction2(a, b, c, d, e) { + var result = a + b; + return () { + var base = super.constant1000; + var result2 = c + d; + return () { + return base() + result + result2 + e; + }; + }; + } +} + +nestedAdderFunction(a, b, c, d, e) { + var result = a + b; + return () { + var result2 = c + d; + return () { + return result + result2 + e; + }; + }; +} + +main() { + Expect.isTrue(nestedAdderFunction(1, 2, 3, 4, 5)()() == 15); + + var foo = new Foo(100); + Expect.isTrue(foo.nestedAdderFunction(1, 2, 3, 4, 5)()() == 115); + Expect.isTrue(foo.nestedAdderFunction2(1, 2, 3, 4, 5)()() == 1015); + + var funs = []; + for (int i = 0; i < 3; i++) { + funs.add(() => i); + } + Expect.isTrue((funs[0]() + funs[1]() + funs[2]()) == 3); + + var funs2 = []; + for (var i in [0, 1, 2]) { + funs2.add(() => i); + } + Expect.isTrue((funs2[0]() + funs2[1]() + funs2[2]()) == 3); +} diff --git a/tests/kernel/unsorted/conditional_test.dart b/tests/kernel/unsorted/conditional_test.dart new file mode 100644 index 00000000000..c5df2c33e33 --- /dev/null +++ b/tests/kernel/unsorted/conditional_test.dart @@ -0,0 +1,142 @@ +// Copyright (c) 2016, 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. + +// Tests of conditional expressions and statements and negation. + +import 'expect.dart'; + +mkTrue() => true; +mkFalse() => false; + +check(b) { + Expect.isTrue(b); + return b; +} + +main() { + // Check that ?: gets the right answer. + Expect.isTrue((mkTrue() ? 0 : 1) == 0); + Expect.isTrue((mkFalse() ? 0 : 1) == 1); + // Check that it doesn't evaluate all subexpressions. + mkTrue() ? Expect.isTrue(true) : Expect.isTrue(false); + mkFalse() ? Expect.isTrue(false) : Expect.isTrue(true); + + // Check that && and || get the right answers. + Expect.isTrue(mkTrue() && mkTrue()); + Expect.isTrue(!(mkTrue() && mkFalse())); + Expect.isTrue(!(mkFalse() && mkTrue())); + Expect.isTrue(!(mkFalse() && mkFalse())); + Expect.isTrue(mkTrue() || mkTrue()); + Expect.isTrue(mkTrue() || mkFalse()); + Expect.isTrue(mkFalse() || mkTrue()); + Expect.isTrue(!(mkFalse() || mkFalse())); + + // Check that they don't evaluate both subexpressions. + mkTrue() && check(true); + mkFalse() && check(false); + mkTrue() || check(true); + mkFalse() || check(true); + + // Check that if works. + if (mkTrue()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + if (mkFalse()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + if (!mkTrue()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + if (!mkFalse()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + + // Check that ?:, &&, and || work for control flow. + if (mkTrue() ? mkTrue() : mkFalse()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + if (mkTrue() ? mkFalse() : mkTrue()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + if (mkFalse() ? mkTrue() : mkFalse()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + if (mkFalse() ? mkFalse() : mkTrue()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + if (mkTrue() && mkTrue()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + if (mkTrue() && mkFalse()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + if (mkFalse() && mkTrue()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + if (mkFalse() && mkFalse()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + if (mkTrue() || mkTrue()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + if (mkTrue() || mkFalse()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + if (mkFalse() || mkTrue()) { + Expect.isTrue(true); + } else { + Expect.isTrue(false); + } + if (mkFalse() || mkFalse()) { + Expect.isTrue(false); + } else { + Expect.isTrue(true); + } + + // Test empty else branches. + if (mkTrue()) { + Expect.isTrue(true); + } + if (mkFalse()) { + Expect.isTrue(false); + } + + var x = 0; + if (mkTrue()) { + x = 1; + } + Expect.isTrue(x == 1); + if (mkFalse()) { + x = 2; + } + Expect.isTrue(x == 1); +} diff --git a/tests/kernel/unsorted/constant_evaluator_regression_test.dart b/tests/kernel/unsorted/constant_evaluator_regression_test.dart new file mode 100644 index 00000000000..176344e4964 --- /dev/null +++ b/tests/kernel/unsorted/constant_evaluator_regression_test.dart @@ -0,0 +1,11 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +const X = const bool.fromEnvironment('foobar'); + +main() { + Expect.isTrue(X == false); +} diff --git a/tests/kernel/unsorted/constant_expressions_test.dart b/tests/kernel/unsorted/constant_expressions_test.dart new file mode 100644 index 00000000000..0ddd9a34a07 --- /dev/null +++ b/tests/kernel/unsorted/constant_expressions_test.dart @@ -0,0 +1,100 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +const int42 = 40 + 2; +const stringAB = 'a' + 'b'; +const stringAB2 = 'a' + 'b'; +const list123 = const [1, 2, 3]; +const mapABC = const {'a' : 'b', 'b': 'c'}; + +const boxInt42 = const Box(int42); +const boxStringAB = const Box(stringAB); + +class Box { + final value; + const Box(this.value); +} + +returnPositional([a = const Box('posi' + 'tional')]) => a; + +returnNamed({a: const Box('nam' + 'ed')}) => a; + +returnSwitchCasedValue(value) { + switch (value) { + case const Box(42): return 42; + case const Box('abc'): return 'abc'; + case const Box(const Box('abc')): return const Box('abc'); + default: return 'default'; + } +} + +testConstantExpressions() { + Expect.isTrue(identical(const Box(40 + 2), const Box(40 + 2))); + Expect.isTrue(identical(const Box('a' + 'b'), const Box('ab'))); + Expect.isTrue(identical(const Box(const Box(40 + 2)), + const Box(const Box(42)))); + Expect.isTrue(identical(const Box(const Box('a' + 'b')), + const Box(const Box('ab')))); +} + +testConstantFieldValues() { + Expect.isTrue(identical(42, int42)); + Expect.isTrue(identical(stringAB, stringAB2)); + Expect.isTrue(identical(const Box(42), boxInt42)); + Expect.isTrue(identical(const Box('ab'), boxStringAB)); +} + +testConstantFunctionParameters() { + Expect.isTrue(identical(const Box('positional'), returnPositional())); + Expect.isTrue(identical(const Box('named'), returnNamed())); + Expect.isTrue(identical(const Box('abc'), + returnPositional(const Box('abc')))); + Expect.isTrue(identical(const Box('def'), + returnNamed(a: const Box('def')))); +} + +testConstantSwitchExpressions() { + Expect.isTrue(returnSwitchCasedValue(const Box(42)) == 42); + Expect.isTrue(returnSwitchCasedValue(const Box('abc')) == 'abc'); + Expect.isTrue(returnSwitchCasedValue(const Box(const Box('abc'))) + == const Box('abc')); + Expect.isTrue(returnSwitchCasedValue(const Box('go-to-default')) + == 'default'); +} + +testConstantLocalVariables() { + const a = 'a'; + const b = a + 'b'; + const c = b + 'c'; + const box = const Box(c); + Expect.isTrue(identical(const Box('abc'), box)); +} + +testComplextConstLiterals() { + Expect.isTrue(identical(const [1, 2, 3], const [1, 2, 3])); + Expect.isTrue(identical(const [1, 2, 3], list123)); + Expect.isTrue(identical(const {'a': 'b', 'b': 'c'}, const {'a': 'b', 'b': 'c'})); + Expect.isTrue(identical(const {'a': 'b', 'b': 'c'}, mapABC)); + + Expect.isTrue(mapABC['a'] == 'b'); + Expect.isTrue(mapABC['b'] == 'c'); + Expect.isTrue(mapABC.length == 2); + + Expect.isTrue(list123[0] == 1); + Expect.isTrue(list123[1] == 2); + Expect.isTrue(list123[2] == 3); + Expect.isTrue(list123.length == 3); +} + +main() { + testConstantExpressions(); + testConstantFieldValues(); + testConstantFunctionParameters(); + testConstantSwitchExpressions(); + testComplextConstLiterals(); + testConstantExpressions(); + testConstantLocalVariables(); +} diff --git a/tests/kernel/unsorted/expect.dart b/tests/kernel/unsorted/expect.dart new file mode 100644 index 00000000000..e1a215f9ec6 --- /dev/null +++ b/tests/kernel/unsorted/expect.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2016, 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. + +import 'dart:io' as io; + +// We use this class until we support more language features to use +// `package:expect`. +class Expect { + static void isTrue(bool condition) { + if (!condition) { + print("Expect.isTrue(cond) failed. io.exit(1)ing"); + io.exit(1); + } + } +} diff --git a/tests/kernel/unsorted/factory_regression_test.dart b/tests/kernel/unsorted/factory_regression_test.dart new file mode 100644 index 00000000000..8e79390bbc2 --- /dev/null +++ b/tests/kernel/unsorted/factory_regression_test.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2016, 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. + +import 'dart:typed_data'; + +import 'expect.dart'; + +var list = [1, 2, 3]; + +class Foo { + final value; + Foo(this.value) {} + + factory Foo.fac(value) { + return new Foo(value); + } +} + +main() { + Expect.isTrue(new Uint8List.fromList(list)[1] == 2); + Expect.isTrue(new Foo.fac(10).value == 10); +} diff --git a/tests/kernel/unsorted/field_dispatcher_test.dart b/tests/kernel/unsorted/field_dispatcher_test.dart new file mode 100644 index 00000000000..233c341b7a3 --- /dev/null +++ b/tests/kernel/unsorted/field_dispatcher_test.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + Function fun; + A(this.fun); +} + +globalFunctionPositional(int a, [int b = 42]) => a + b; + +globalFunctionNamed(int a, {int b: 42}) => a + b; + +class Foo { + int base; + + Foo(this.base); + + methodFunctionPositional(int a, [int b = 42]) => base + a + b; + + methodFunctionNamed(int a, {int b: 42}) => base + a + b; +} + +main() { + Expect.isTrue(new A(globalFunctionPositional).fun(1, 2) == 3); + Expect.isTrue(new A(globalFunctionPositional).fun(1) == 43); + Expect.isTrue(new A(globalFunctionNamed).fun(1, b: 2) == 3); + Expect.isTrue(new A(globalFunctionNamed).fun(1) == 43); + + var foo = new Foo(100); + Expect.isTrue(new A(foo.methodFunctionPositional).fun(1, 2) == 103); + Expect.isTrue(new A(foo.methodFunctionPositional).fun(1) == 143); + Expect.isTrue(new A(foo.methodFunctionNamed).fun(1, b: 2) == 103); + Expect.isTrue(new A(foo.methodFunctionNamed).fun(1) == 143); +} diff --git a/tests/kernel/unsorted/finally_contexts_test.dart b/tests/kernel/unsorted/finally_contexts_test.dart new file mode 100644 index 00000000000..c844d809e12 --- /dev/null +++ b/tests/kernel/unsorted/finally_contexts_test.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +// Test that the context depth is correct in the presence of control flow, +// specifically branching and joining in the presence of break. The +// implementation uses the context depth after the else block of an if/then/else +// as the context depth at the join point. This test has an extra context +// allocated in the (untaken) else branch so it tests that compiling the +// (untaken) break properly tracks the context depth. + +test(list) { + // The loops force creation of a new context, otherwise context allocated + // variables might be hoisted to an outer context. + do { + if (list.length > 1) { + do { + var sum = 0; + addem() { + for (var x in list) sum += x; + } + addem(); + Expect.isTrue(sum == 15); + L: if (sum != 15) { + // Unreachable. + do { + var product = 1; + multiplyem() { + for (var x in list) product *= n; + } + multiplyem(); + Expect.isTrue(false); + break L; + } while (false); + } + } while (false); + } + } while (false); + Expect.isTrue(list.length == 5); +} + + +main() { + test([1, 2, 3, 4, 5]); +} diff --git a/tests/kernel/unsorted/for_in_loop_test.dart b/tests/kernel/unsorted/for_in_loop_test.dart new file mode 100644 index 00000000000..223325f1d02 --- /dev/null +++ b/tests/kernel/unsorted/for_in_loop_test.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2016, 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. + +// Tests of for-in loops and list literals. + +import 'expect.dart'; + +fact4() { + var f = 1; + for (var n in [1, 2, 3, 4]) { + f *= n; + } + return f; +} + +fact5() { + var f = 1, n; + for (n in [1, 2, 3, 4, 5]) { + f *= n; + } + return f; +} + +var global; +fact6() { + var f = 1; + for (global in [1, 2, 3, 4, 5, 6]) { + f *= global; + } + return f; +} + +main() { + Expect.isTrue(fact4() == 24); + Expect.isTrue(fact5() == 120); + Expect.isTrue(fact6() == 720); +} diff --git a/tests/kernel/unsorted/getters_and_setters_test.dart b/tests/kernel/unsorted/getters_and_setters_test.dart new file mode 100644 index 00000000000..a5e084aaaa8 --- /dev/null +++ b/tests/kernel/unsorted/getters_and_setters_test.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +var field; + +get getField { + print('B.getField'); + return field; +} + +set setField(value) { + print('B.setField'); + field = value; + return null; +} + +main() { + var result; + + result = (field = 42); + Expect.isTrue(result == 42); + Expect.isTrue(field == 42); + Expect.isTrue(getField == 42); + + result = (setField = 99); + Expect.isTrue(result == 99); + Expect.isTrue(field == 99); + Expect.isTrue(getField == 99); +} diff --git a/tests/kernel/unsorted/global_field_initializer_test.dart b/tests/kernel/unsorted/global_field_initializer_test.dart new file mode 100644 index 00000000000..633ab8e99b8 --- /dev/null +++ b/tests/kernel/unsorted/global_field_initializer_test.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +var intField = 1; +var doubleField = 3.1415; +var stringField = "hello"; +var nullField = null; +var nullField2; +var composed = "hello" + " " + "world"; + +class A { + static var intField = 1; + static var doubleField = 3.1415; + static var stringField = "hello"; + static var nullField = null; + static var nullField2; + static var composed = "hello" + " " + "world"; +} + +main() { + Expect.isTrue(intField == 1); + Expect.isTrue(doubleField == 3.1415); + Expect.isTrue(stringField == "hello"); + Expect.isTrue(nullField == null); + Expect.isTrue(nullField2 == null); + Expect.isTrue(composed == "hello world"); + + Expect.isTrue(A.intField == 1); + Expect.isTrue(A.doubleField == 3.1415); + Expect.isTrue(A.stringField == "hello"); + Expect.isTrue(A.nullField == null); + Expect.isTrue(A.nullField2 == null); + Expect.isTrue(A.composed == "hello world"); +} diff --git a/tests/kernel/unsorted/global_function_test.dart b/tests/kernel/unsorted/global_function_test.dart new file mode 100644 index 00000000000..925ce80cd4f --- /dev/null +++ b/tests/kernel/unsorted/global_function_test.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2016, 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. + +main() { + foo(1, 2); + print('---'); + foo(1, 2, d: 12); + print('---'); + foo(1, 2, c: 11, e: 13); + + print('====='); + + bar(1, 2); + print('---'); + bar(1, 2, 3); + print('---'); + bar(1, 2, 3, 4); +} + +foo(a, b, {c, d, e}) { + print(a); + print(b); + print(c); + print(d); + print(e); +} + +bar(a, b, [c, d]) { + print(a); + print(b); + print(c); + print(d); +} + diff --git a/tests/kernel/unsorted/instance_getters_and_setters_test.dart b/tests/kernel/unsorted/instance_getters_and_setters_test.dart new file mode 100644 index 00000000000..f61ebe53878 --- /dev/null +++ b/tests/kernel/unsorted/instance_getters_and_setters_test.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + var field; + + get getField { + return field; + } + + set setField(value) { + field = value; + return null; + } +} + +main() { + var result; + var a = new A(); + + Expect.isTrue(a.field == null); + Expect.isTrue(a.getField == null); + + result = (a.field = 42); + Expect.isTrue(result == 42); + Expect.isTrue(a.field == 42); + Expect.isTrue(a.getField == 42); + + result = (a.setField = 99); + Expect.isTrue(result == 99); + Expect.isTrue(a.field == 99); + Expect.isTrue(a.getField == 99); +} diff --git a/tests/kernel/unsorted/invocation_errors_test.dart b/tests/kernel/unsorted/invocation_errors_test.dart new file mode 100644 index 00000000000..dca63bc0464 --- /dev/null +++ b/tests/kernel/unsorted/invocation_errors_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2016, 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. + +// Erroneous cases of invocations. + +import 'expect.dart'; + +test0(x) { + print('test0'); +} + +main() { + // Incorrect number of arguments, should be NoSuchMethodError but crashes. + test0(0, 1); +} diff --git a/tests/kernel/unsorted/invocation_test.dart b/tests/kernel/unsorted/invocation_test.dart new file mode 100644 index 00000000000..3e5ec178854 --- /dev/null +++ b/tests/kernel/unsorted/invocation_test.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2016, 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. + +// Tests of invocations. + +import 'expect.dart'; + +test0(x) { + Expect.isTrue(x == 'argument0'); + return 'return0'; +} + +class C0 { + static test1(x) { + Expect.isTrue(x == 'argument1'); + return 'return1'; + } +} + +class C1 { + test2(x) { + Expect.isTrue(x == 'argument2'); + return 'return2'; + } +} + +class C2 { + C2.test3(x) { + Expect.isTrue(x == 'argument3'); + } +} + +main() { + Expect.isTrue(test0('argument0') == 'return0'); + Expect.isTrue(C0.test1('argument1') == 'return1'); + Expect.isTrue(new C1().test2('argument2') == 'return2'); + var c = new C2.test3('argument3'); + Expect.isTrue(c is C2); +} diff --git a/tests/kernel/unsorted/klass_field_initializer_test.dart b/tests/kernel/unsorted/klass_field_initializer_test.dart new file mode 100644 index 00000000000..3ce741e148c --- /dev/null +++ b/tests/kernel/unsorted/klass_field_initializer_test.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + var intField = 1; + var doubleField = 3.1415; + var stringField = "hello"; + var o; + + A(this.o); +} + +class B extends A { + var nullField = null; + var nullField2; + + var n; + var m; + + B(this.n, o) : super(o), m = "m"; +} + +main() { + var o = new B("n", "o"); + Expect.isTrue(o.intField == 1); + Expect.isTrue(o.doubleField == 3.1415); + Expect.isTrue(o.stringField == "hello"); + Expect.isTrue(o.nullField == null); + Expect.isTrue(o.nullField2 == null); + Expect.isTrue(o.m == 'm'); + Expect.isTrue(o.n == 'n'); + Expect.isTrue(o.o == 'o'); +} diff --git a/tests/kernel/unsorted/klass_test.dart b/tests/kernel/unsorted/klass_test.dart new file mode 100644 index 00000000000..27458821308 --- /dev/null +++ b/tests/kernel/unsorted/klass_test.dart @@ -0,0 +1,52 @@ +// Copyright (c) 2016, 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. + +class A { + A() { + print("A"); + } + + hello() { + print("A.hello()"); + } + + hello1(a) { + print("A.hello1()"); + print(a); + } + + foo(a, [b]) { + print("A.foo()"); + print(a); + print(b); + } + + bar(a, {b}) { + print("A.bar()"); + print(a); + print(b); + } +} + +main() { + print("before constructor"); + var a = new A(); + print("============"); + a.hello(); + print('-----(obj):'); + print(a); + print('-----'); + a.hello1(1); + print('-----'); + a.foo(1); + print('-----'); + a.foo(1, 2); + print('-----'); + print("============"); + a.bar(1); + print('-----'); + a.bar(1, b: 2); + print("============"); +} + diff --git a/tests/kernel/unsorted/let_test.dart b/tests/kernel/unsorted/let_test.dart new file mode 100644 index 00000000000..249ec491558 --- /dev/null +++ b/tests/kernel/unsorted/let_test.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +main() { + var a = [1]; + Expect.isTrue((a..add(42))[1] == 42); +} diff --git a/tests/kernel/unsorted/load_store_test.dart b/tests/kernel/unsorted/load_store_test.dart new file mode 100644 index 00000000000..a9ff4c475e0 --- /dev/null +++ b/tests/kernel/unsorted/load_store_test.dart @@ -0,0 +1,64 @@ +// Copyright (c) 2016, 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. + +// Tests of reading and writing to variables. + +import 'expect.dart'; + +test0() { + var x0 = 0, x1; + Expect.isTrue(x0 == 0); + Expect.isTrue(x1 == null); + x0 = 1; + Expect.isTrue(x0 == 1); + Expect.isTrue((x0 = 2) == 2); + Expect.isTrue(x0 == 2); +} + +var x2 = 0, x3; + +test1() { + Expect.isTrue(x2 == 0); + Expect.isTrue(x3 == null); + x2 = 1; + Expect.isTrue(x2 == 1); + Expect.isTrue((x2 = 2) == 2); + Expect.isTrue(x2 == 2); +} + +class C { + static var x4 = 0; + static var x5; +} + +test3() { + Expect.isTrue(C.x4 == 0); + Expect.isTrue(C.x5 == null); + C.x4 = 1; + Expect.isTrue(C.x4 == 1); + Expect.isTrue((C.x4 = 2) == 2); + Expect.isTrue(C.x4 == 2); +} + +class D { + var x6 = 0; + var x7; +} + +test4() { + var d = new D(); + Expect.isTrue(d.x6 == 0); + Expect.isTrue(d.x7 == null); + d.x6 = 1; + Expect.isTrue(d.x6 == 1); + Expect.isTrue((d.x6 = 2) == 2); + Expect.isTrue(d.x6 == 2); +} + +main() { + test0(); + test1(); + test3(); + test4(); +} diff --git a/tests/kernel/unsorted/local_function_test.dart b/tests/kernel/unsorted/local_function_test.dart new file mode 100644 index 00000000000..0584b30fc38 --- /dev/null +++ b/tests/kernel/unsorted/local_function_test.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2016, 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. + +// Tests of function expressions and function statements. + +import 'expect.dart'; + +main() { + var even; + odd(n) => n > 0 && even(n - 1); + even = (n) => n == 0 || odd(n - 1); + + Expect.isTrue(even(0)); + Expect.isTrue(!odd(0)); + + Expect.isTrue(odd(1)); + Expect.isTrue(!even(1)); + + Expect.isTrue(even(42)); + Expect.isTrue(!odd(42)); + + Expect.isTrue(odd(101)); + Expect.isTrue(!even(101)); +} diff --git a/tests/kernel/unsorted/loop_test.dart b/tests/kernel/unsorted/loop_test.dart new file mode 100644 index 00000000000..bf487408d58 --- /dev/null +++ b/tests/kernel/unsorted/loop_test.dart @@ -0,0 +1,91 @@ +// Copyright (c) 2016, 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. + +// Tests of loops. + +import 'expect.dart'; + +fact(n) { + var f = 1; + while (n > 0) { + f *= n; + --n; + } + return f; +} + +fib(n) { + if (n == 0) return 0; + var previous = 0, current = 1; + while (n > 1) { + var temp = current; + current += previous; + previous = temp; + --n; + } + return current; +} + +mkTrue() => true; +mkFalse() => false; + +check(b) { + Expect.isTrue(b); + return b; +} + +test0() { + while (mkTrue()) { + Expect.isTrue(true); + return; + } + Expect.isTrue(false); +} + +test1() { + while (mkFalse()) { + Expect.isTrue(false); + } + Expect.isTrue(true); +} + +test2() { + do { + Expect.isTrue(true); + } while (mkFalse()); + Expect.isTrue(true); +} + +test3() { + do { + Expect.isTrue(true); + return; + } while (check(false)); + Expect.isTrue(false); +} + +main() { + Expect.isTrue(fact(0) == 1); + Expect.isTrue(fact(1) == 1); + Expect.isTrue(fact(5) == 120); + Expect.isTrue(fact(42) == + 1405006117752879898543142606244511569936384000000000); + Expect.isTrue(fact(3.14159) == 1.0874982674320444); + + Expect.isTrue(fib(0) == 0); + Expect.isTrue(fib(1) == 1); + Expect.isTrue(fib(2) == 1); + Expect.isTrue(fib(3) == 2); + Expect.isTrue(fib(4) == 3); + Expect.isTrue(fib(5) == 5); + Expect.isTrue(fib(6) == 8); + Expect.isTrue(fib(7) == 13); + Expect.isTrue(fib(42) == 267914296); + Expect.isTrue(fib(3.14159) == 3); + + test0(); + test1(); + test2(); + test3(); +} diff --git a/tests/kernel/unsorted/mapliteral_test.dart b/tests/kernel/unsorted/mapliteral_test.dart new file mode 100644 index 00000000000..d92a2d7fe5e --- /dev/null +++ b/tests/kernel/unsorted/mapliteral_test.dart @@ -0,0 +1,27 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +main() { + var map = { + 'k1': 'v1', + 'k2': 'v2', + 1: 2, + 1.5 : 1.2, + 3: 3.14, + }; + + Expect.isTrue(map.length == 5); + + map['foo'] = 'bar'; + + Expect.isTrue(map['k1'] == 'v1'); + Expect.isTrue(map['k2'] == 'v2'); + Expect.isTrue(map[1] == 2); + Expect.isTrue(map[1.5] == 1.2); + Expect.isTrue(map[3] == 3.14); + Expect.isTrue(map['foo'] == 'bar'); + Expect.isTrue(map.length == 6); +} diff --git a/tests/kernel/unsorted/mixin_test.dart b/tests/kernel/unsorted/mixin_test.dart new file mode 100644 index 00000000000..58253d46f2b --- /dev/null +++ b/tests/kernel/unsorted/mixin_test.dart @@ -0,0 +1,64 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class Base { + baseFoo() { + print('Base.baseFoo()'); + return 1; + } + + foo() { + print('Base.foo()'); + return 1; + } +} + +class Mixin { + mixinFoo() { + print('Mixin.mixinFoo()'); + return 2; + } + + foo() { + print('Mixin.foo()'); + return 2; + } +} + +class Mixin2 { + mixin2Foo() { + print('Mixin2.mixin2Foo()'); + return 3; + } + + foo() { + print('Mixin2.foo()'); + return 3; + } +} + +class Sub extends Base with Mixin, Mixin2 { + subFoo() { + print('Sub.subFoo()'); + return 4; + } + + foo() { + print('Sub.foo()'); + return 4; + } +} + +main() { + var o = new Sub(); + + Expect.isTrue(o.baseFoo() == 1); + Expect.isTrue(o.mixinFoo() == 2); + Expect.isTrue(o.mixin2Foo() == 3); + Expect.isTrue(o.subFoo() == 4); + Expect.isTrue(o.foo() == 4); +} + diff --git a/tests/kernel/unsorted/nsm_dispatcher_test.dart b/tests/kernel/unsorted/nsm_dispatcher_test.dart new file mode 100644 index 00000000000..d08b2ec2100 --- /dev/null +++ b/tests/kernel/unsorted/nsm_dispatcher_test.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + noSuchMethod(Invocation invocation) { + var s = '|${invocation.memberName}|'; + for (var a in invocation.positionalArguments) { + s = '$s$a|'; + } + invocation.namedArguments.forEach((Symbol k, v) { + s = '$s$k/$v|'; + }); + print(s); + return s; + } +} + +main() { + var o = new A(); + Expect.isTrue(o.fun() == '|Symbol("fun")|'); + Expect.isTrue(o.fun(1) == '|Symbol("fun")|1|'); + Expect.isTrue(o.fun(1, 2) == '|Symbol("fun")|1|2|'); + Expect.isTrue(o.fun(1, b: 2) == + '|Symbol("fun")|1|Symbol("b")/2|'); + Expect.isTrue(o.fun(1, a: 1, b: 2) == + '|Symbol("fun")|1|Symbol("a")/1|Symbol("b")/2|'); + Expect.isTrue(o.fun(1, b: 2, a: 1) == + '|Symbol("fun")|1|Symbol("a")/1|Symbol("b")/2|'); +} diff --git a/tests/kernel/unsorted/nullable_operator_test.dart b/tests/kernel/unsorted/nullable_operator_test.dart new file mode 100644 index 00000000000..2643a83c9b8 --- /dev/null +++ b/tests/kernel/unsorted/nullable_operator_test.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +mkOne() => 1; +mkNull() => null; + +main() { + Expect.isTrue((mkOne() ?? 2) == 1); + Expect.isTrue((mkNull() ?? 2) == 2); +} diff --git a/tests/kernel/unsorted/rethrow_test.dart b/tests/kernel/unsorted/rethrow_test.dart new file mode 100644 index 00000000000..04a5a844cf1 --- /dev/null +++ b/tests/kernel/unsorted/rethrow_test.dart @@ -0,0 +1,67 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +testNormalRethrow() { + var x = 0; + try { + try { + throw x++; + } catch (e) { + Expect.isTrue(e == 0); + x++; + rethrow; + } + } catch (e) { + Expect.isTrue(e == 0); + x++; + } + Expect.isTrue(x == 3); +} + +testNormalRethrow2() { + var x = 0; + try { + try { + throw x++; + } on int catch (e) { + Expect.isTrue(e == 0); + x++; + rethrow; + } + } catch (e) { + Expect.isTrue(e == 0); + x++; + } + Expect.isTrue(x == 3); +} + +testRethrowWithinTryRethrow() { + var x = 0; + try { + try { + throw x++; + } on int catch (e) { + Expect.isTrue(e == 0); + x++; + try { + x++; + rethrow; + } finally { + x++; + } + } + } catch (e) { + Expect.isTrue(e == 0); + x++; + } + Expect.isTrue(x == 5); +} + +main() { + testNormalRethrow(); + testNormalRethrow2(); + testRethrowWithinTryRethrow(); +} diff --git a/tests/kernel/unsorted/return_test.dart b/tests/kernel/unsorted/return_test.dart new file mode 100644 index 00000000000..61920b38b72 --- /dev/null +++ b/tests/kernel/unsorted/return_test.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2016, 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. + +// Tests of return (and imports, literals, ==, and static methods). + +import 'expect.dart'; + +test0() {} + +test1() { return; } + +test3() { return 3; } + +test4() => 4; + +test5() { + return 5; + Expect.isTrue(false); +} + +main() { + Expect.isTrue(test0() == null); + Expect.isTrue(test1() == null); + Expect.isTrue(test3() == 3); + Expect.isTrue(test4() == 4); + Expect.isTrue(test5() == 5); +} diff --git a/tests/kernel/unsorted/simple_literal_test.dart b/tests/kernel/unsorted/simple_literal_test.dart new file mode 100644 index 00000000000..c8b8c2d7f89 --- /dev/null +++ b/tests/kernel/unsorted/simple_literal_test.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2016, 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. + +// Tests of literals (and imports, return, ==, and static methods). +import 'expect.dart'; + +test0() { + return 'Hello, world!'; +} + +test1() { + return 42; +} + +test2() { + return 2.71828; +} + +test3() { + return 6.022e23; +} + +test4() { + return true; +} + +test5() { + return false; +} + +test6() { + return 1405006117752879898543142606244511569936384000000000; +} + +main() { + Expect.isTrue(test0() == 'Hello, world!'); + Expect.isTrue(test1() == 42); + Expect.isTrue(test2() == 2.71828); + Expect.isTrue(test3() == 6.022e23); + Expect.isTrue(test4()); + Expect.isTrue(test5() == false); + Expect.isTrue( + test6() == 1405006117752879898543142606244511569936384000000000); +} diff --git a/tests/kernel/unsorted/string_buffer_test.dart b/tests/kernel/unsorted/string_buffer_test.dart new file mode 100644 index 00000000000..a89aee66e2f --- /dev/null +++ b/tests/kernel/unsorted/string_buffer_test.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2016, 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. + +main() { + var sb = new StringBuffer(); + sb.writeln('hello world :)'); + print(sb); +} diff --git a/tests/kernel/unsorted/string_concatenation_test.dart b/tests/kernel/unsorted/string_concatenation_test.dart new file mode 100644 index 00000000000..53eae4e96a4 --- /dev/null +++ b/tests/kernel/unsorted/string_concatenation_test.dart @@ -0,0 +1,13 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + toString() => 'hello'; +} + +main() { + Expect.isTrue('begin ${new A()} end' == 'begin hello end'); +} diff --git a/tests/kernel/unsorted/super_initializer_test.dart b/tests/kernel/unsorted/super_initializer_test.dart new file mode 100644 index 00000000000..fb669df4ec5 --- /dev/null +++ b/tests/kernel/unsorted/super_initializer_test.dart @@ -0,0 +1,48 @@ +// Copyright (c) 2016, 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.md file. + +import 'expect.dart'; + +String log; +init() { log = ''; } +logit(msg) { return log = '$log$msg'; } + +class Base { + var b; + Base.arg0() : b = logit('b') { + logit('B'); + } + Base.arg1(a) : b = logit('b') { + logit('B'); + } + Base.arg2(a, b) : b = logit('b') { + logit('B'); + } +} + +class Sub extends Base { + var x; + var s; + Sub.arg0() : x = logit('x'), super.arg0(), s = logit('s') { + logit('S'); + } + Sub.arg1(a) : x = logit('x'), super.arg1(logit('1')), s = logit('s') { + logit('S'); + } + Sub.arg2(a, b) : x = logit('x'), super.arg2(logit('1'), logit('2')), s = logit('s') { + logit('S'); + } +} + +test(fun(), String result) { + init(); + fun(); + Expect.isTrue(log == result); +} + +main() { + test(() => new Sub.arg0(), 'xsbBS'); + test(() => new Sub.arg1(1), 'x1sbBS'); + test(() => new Sub.arg2(1, 2), 'x12sbBS'); +} diff --git a/tests/kernel/unsorted/super_mixin_test.dart b/tests/kernel/unsorted/super_mixin_test.dart new file mode 100644 index 00000000000..97e53564e89 --- /dev/null +++ b/tests/kernel/unsorted/super_mixin_test.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class Base { + var field; + + method(x) { + print(x); + return x; + } + + set setter(x) { + print(x); + field = x; + } +} + +class Mixin { + method(x) { + return super.method(x + 'Mixin'); + } + + set setter(x) { + super.setter = x + 'Mixin'; + } +} + +class Sub extends Base with Mixin { +} + +main() { + var object = new Sub(); + Expect.isTrue(object.method('x') == 'xMixin'); + object.setter = 'y'; + Expect.isTrue(object.field == 'yMixin'); +} diff --git a/tests/kernel/unsorted/super_test.dart b/tests/kernel/unsorted/super_test.dart new file mode 100644 index 00000000000..e2fc34f9730 --- /dev/null +++ b/tests/kernel/unsorted/super_test.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + var field = 9; + var called = false; + + superMethod() { + Expect.isTrue(field == 10); + called = true; + return true; + } +} + +class B extends A { + doit() { + Expect.isTrue((super.field = 10) == 10); + Expect.isTrue(super.superMethod()); + if (called) { + Expect.isTrue((super.field = 11) == 11); + } + return super.field; + } +} + +class C extends B { + set field(v) { + throw 'should not happen'; + } +} + +main() { + var c = new C(); + Expect.isTrue(c.field == 9); + Expect.isTrue(c.doit() == 11); + Expect.isTrue(c.field == 11); +} diff --git a/tests/kernel/unsorted/superclass_test.dart b/tests/kernel/unsorted/superclass_test.dart new file mode 100644 index 00000000000..ac459c332eb --- /dev/null +++ b/tests/kernel/unsorted/superclass_test.dart @@ -0,0 +1,64 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + A() { + print("A"); + } + + hello() { + print("A.hello()"); + return 1; + } + + hello1(a) { + print("A.hello1()"); + print(a); + return 1; + } + + foo(a, [b]) { + print("A.foo()"); + print(a); + print(b); + return 1; + } + + bar(a, {b}) { + print("A.bar()"); + print(a); + print(b); + return 1; + } +} + +class B extends A { + hello() { + print("B.hello()"); + return 2; + } + + bar(a, {b}) { + print("B.bar()"); + print(a); + print(b); + return 2; + } +} + +main() { + var o = new B(); + + // Base class methods. + Expect.isTrue(o.hello1(1) == 1); + Expect.isTrue(o.foo(1) == 1); + Expect.isTrue(o.foo(1, 2) == 1); + + // Overwritten methods. + Expect.isTrue(o.hello() == 2); + Expect.isTrue(o.bar(1) == 2); + Expect.isTrue(o.bar(1, b: 2) == 2); +} diff --git a/tests/kernel/unsorted/switch_case_test.dart b/tests/kernel/unsorted/switch_case_test.dart new file mode 100644 index 00000000000..1d6e3940c37 --- /dev/null +++ b/tests/kernel/unsorted/switch_case_test.dart @@ -0,0 +1,174 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +mkOne() => 1; +mkTwo() => 2; + +testNormal() { + int result; + switch(mkOne()) { + case 0: + result = 0; + break; + case 1: + result = 1; + break; + case 2: + result = 2; + break; + default: + result = 3; + break; + } + Expect.isTrue(result == 1); +} + +testDefault() { + int result; + switch(null) { + case 0: + result = 0; + break; + case 1: + result = 1; + break; + case 2: + result = 2; + break; + default: + result = 3; + break; + } + Expect.isTrue(result == 3); +} + +testFallThrough() { + int result; + switch(mkOne()) { + case 0: + result = 0; + break; + case 1: + case 2: + result = 2; + break; + default: + result = 3; + break; + } + Expect.isTrue(result == 2); +} + +testContinue() { + int result; + switch(mkTwo()) { + case 0: + result = 0; + break; + + setitto1: + case 1: + result = 1; + continue setitto3; + + case 2: + result = 2; + continue setitto1; + + setitto3: + default: + result = 3; + break; + } + Expect.isTrue(result == 3); +} + +testOnlyDefault() { + int result; + switch(mkTwo()) { + default: + result = 42; + } + Expect.isTrue(result == 42); +} + +testOnlyDefaultWithBreak() { + int result; + switch(mkTwo()) { + default: + result = 42; + } + Expect.isTrue(result == 42); +} + +String testReturn() { + switch(mkOne()) { + case 0: return "bad"; + case 1: return "good"; + default: return "bad"; + } +} + +regressionTest() { + Expect.isTrue(regressionTestHelper(0, 0) == -1); + Expect.isTrue(regressionTestHelper(4, 0) == -1); + Expect.isTrue(regressionTestHelper(4, 1) == 42); +} + +regressionTestHelper(i, j) { + switch (i) { + case 4: + switch (j) { + case 1: + return 42; + } + } + return -1; +} + +regressionTest2() { + var state = 1; + while (state < 2) { + switch (state) { + case 1: + state++; + break; + case 3: + case 4: + // We will translate this currently to an empty [Fragment] which can + // cause issues if we would like to append/prepend to it. + assert(false); + } + } + return [1]; +} + +regressionTest3() { + f(x) { + switch (x) { + case 1: + return 2; + case 2: + } + throw new UnsupportedError("Unexpected constant kind."); + } + Expect.isTrue(f(1) == 2); +} + +main() { + testNormal(); + testDefault(); + testFallThrough(); + testContinue(); + testOnlyDefault(); + testOnlyDefaultWithBreak(); + regressionTest(); + regressionTest2(); + regressionTest3(); + + var result = testReturn(); + Expect.isTrue(result == "good"); +} diff --git a/tests/kernel/unsorted/symbol_literal_test.dart b/tests/kernel/unsorted/symbol_literal_test.dart new file mode 100644 index 00000000000..53af588fde5 --- /dev/null +++ b/tests/kernel/unsorted/symbol_literal_test.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +main() { + Expect.isTrue('${#abc}' == 'Symbol("abc")'); + Expect.isTrue('${#abc.xzy}' == 'Symbol("abc.xzy")'); +} diff --git a/tests/kernel/unsorted/this_capture_test.dart b/tests/kernel/unsorted/this_capture_test.dart new file mode 100644 index 00000000000..52faffdaf3f --- /dev/null +++ b/tests/kernel/unsorted/this_capture_test.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class Foo { + capture() { + return () { + return this; + }; + } + + captureFirst(a, b) { + return () { + print(a); + return this; + }; + } + + captureLast(a, b) { + return () { + print(b); + return this; + }; + } +} + +main() { + var foo = new Foo(); + Expect.isTrue(identical(foo, (foo.capture())())); + Expect.isTrue(identical(foo, (foo.captureFirst(1, 2))())); + Expect.isTrue(identical(foo, (foo.captureLast(1, 2))())); +} diff --git a/tests/kernel/unsorted/this_test.dart b/tests/kernel/unsorted/this_test.dart new file mode 100644 index 00000000000..06a0ce61f17 --- /dev/null +++ b/tests/kernel/unsorted/this_test.dart @@ -0,0 +1,15 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class A { + getThis() => this; +} + +main() { + var a = new A(); + Expect.isTrue(a == a.getThis()); + Expect.isTrue(identical(a, a.getThis())); +} diff --git a/tests/kernel/unsorted/throw_try_catch_test.dart b/tests/kernel/unsorted/throw_try_catch_test.dart new file mode 100644 index 00000000000..69ebbeafbf0 --- /dev/null +++ b/tests/kernel/unsorted/throw_try_catch_test.dart @@ -0,0 +1,190 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +testSimpleThrowCatch() { + var x = 1; + try { + throw x++; + } on int catch (e) { + Expect.isTrue(e == 1); + Expect.isTrue(x == 2); + x++; + } + Expect.isTrue(x == 3); +} + +testNestedThrowCatch() { + var x = 1; + try { + throw x++; + } catch (e) { + Expect.isTrue(e == 1); + Expect.isTrue(x == 2); + x++; + + try { + throw x++; + } catch (e) { + Expect.isTrue(e == 3); + Expect.isTrue(x == 4); + x++; + } + } + Expect.isTrue(x == 5); +} + +testNestedThrowCatch2() { + var x = 1; + try { + try { + throw x++; + } catch (e) { + Expect.isTrue(e == 1); + Expect.isTrue(x == 2); + x++; + } + throw x++; + } catch (e) { + Expect.isTrue(e == 3); + Expect.isTrue(x == 4); + x++; + } + Expect.isTrue(x == 5); +} + +testSiblingThrowCatch() { + var x = 1; + try { + throw x++; + } catch (e) { + Expect.isTrue(e == 1); + Expect.isTrue(x == 2); + x++; + } + try { + throw x++; + } catch (e) { + Expect.isTrue(e == 3); + Expect.isTrue(x == 4); + x++; + } + + Expect.isTrue(x == 5); +} + +testTypedCatch() { + var good = false; + try { + throw 1; + } on int catch (e) { + Expect.isTrue(e == 1); + good = true; + } on String catch (_) { + Expect.isTrue(false); + } + Expect.isTrue(good); +} + +testTypedCatch2() { + var good = false; + try { + throw 'a'; + } on int catch (_) { + Expect.isTrue(false); + } on String catch (e) { + Expect.isTrue(e == 'a'); + good = true; + } + Expect.isTrue(good); +} + +testThrowNull() { + var good = false; + try { + throw null; + } on NullThrownError catch (_) { + good = true; + } + Expect.isTrue(good); +} + +testFinally() { + var x = 0; + try { + throw x++; + } catch (_) { + x++; + } finally { + x++; + } + Expect.isTrue(x == 3); +} + +testFinally2() { + var x = 0; + try { + try { + throw x++; + } catch (_) { + x++; + } finally { + x++; + } + } finally { + x++; + } + Expect.isTrue(x == 4); +} + +testFinally3() { + try { + var x = 0; + try { + throw x++; + } finally { + x++; + } + Expect.isTrue(x == 2); + } catch (_) {} +} + +testSuccessfulBody() { + var x = 0; + try { + x++; + } finally { + x++; + } + Expect.isTrue(x == 2); +} + +testSuccessfulBody2() { + var x = 0; + try { + try { + x++; + } finally { + x++; + throw 1; + } + } on int {} + Expect.isTrue(x == 2); +} + +main() { + testSimpleThrowCatch(); + testNestedThrowCatch(); + testNestedThrowCatch2(); + testSiblingThrowCatch(); + testTypedCatch(); + testTypedCatch2(); + testThrowNull(); + testFinally(); + testFinally2(); + testFinally3(); + testSuccessfulBody(); + testSuccessfulBody2(); +} diff --git a/tests/kernel/unsorted/try_context_test.dart b/tests/kernel/unsorted/try_context_test.dart new file mode 100644 index 00000000000..f836c89416e --- /dev/null +++ b/tests/kernel/unsorted/try_context_test.dart @@ -0,0 +1,91 @@ +// Copyright (c) 2016, 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. + +import 'package:expect/expect.dart'; + +throwValue(val) => throw val; + +f1() { + var a = 0; + var b = 0; + var c = 0; + var d = 0; + for (var i = 0; i < 10; i++) { + try { + for (var j = 0; j < 11; j++) { + try { + capture() => [i, j, a, b, c, d]; + throwValue(j == 10 ? "${j}" : j); + } on num catch (e) { + a += j; + b -= e; + } + } + } catch (e) { + c++; + d += int.parse(e); + } + } + return [a, b, c, d]; +} + + +f2() { + var a = 0; + var b = 0; + var c = 0; + var d = 0; + for (var i = 0; i < 10; i++) { + try { + for (var j = 0; j < 11; j++) { + try { + capture() => [i, j, a, b, c, d]; + throwValue(j == 10 ? "${j}" : j); + } on num catch (e) { + a += j; + b -= e; + } + } + } catch (e) { + capture() => e; + c++; + d += int.parse(e); + } + } + return [a, b, c, d]; +} + + +f3() { + var a = 0; + var b = 0; + var c = 0; + var d = 0; + for (var i = 0; i < 10; i++) { + try { + for (var j = 0; j < 11; j++) { + try { + capture() => [i, j, a, b, c, d]; + throwValue(j == 10 ? "${j}" : j); + } on num catch (e) { + a += j; + b -= e; + } + } + } catch (e) { + capture() => e; + c++; + d += int.parse(e); + continue; + } + } + return [a, b, c, d]; +} + + +main() { + Expect.listEquals([450, -450, 10, 100], f1()); + Expect.listEquals([450, -450, 10, 100], f2()); + Expect.listEquals([450, -450, 10, 100], f3()); +} diff --git a/tests/kernel/unsorted/try_finally_test.dart b/tests/kernel/unsorted/try_finally_test.dart new file mode 100644 index 00000000000..3eddd4ff723 --- /dev/null +++ b/tests/kernel/unsorted/try_finally_test.dart @@ -0,0 +1,158 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +testSimpleBreak() { + var x = 1; + while (true) { + try { + x++; + break; + } finally { + x++; + break; + } + } + return x; +} + +testReturnFinally() { + try { + return 1; + } finally { + return 42; + } +} + +testNestedReturnFinally() { + try { + try { + return 1; + } finally { + return 2; + } + } finally { + return 42; + } +} + +testReturnInsideLoop() { + while (true) { + try { + print("hello"); + } finally { + return 42; + } + } +} + +testStopContinueInsideLoop() { + while (true) { + try { + continue; + } finally { + return 42; + } + } +} + +testStopBreakInsideLoop() { + var foo = 1; + while (true) { + try { + if (foo == 1) { + // 1st iteration we break. + break; + } else if (foo == 2) { + // 2nd iteration we return. + return 42; + } + } finally { + // 1st iteration we overrwrite break with continue. + if (foo == 1) { + foo++; + continue; + } else { + // Let return work + } + } + } + return foo; +} + +testStopBreakInsideLoop2() { + var foo = 1; + while (true) { + try { + if (foo == 1) { + // 1st iteration we break. + break; + } else if (foo == 2) { + // 2nd iteration we return. + return -1; + } + } finally { + // 1st iteration we overrwrite break with continue. + if (foo == 1) { + foo++; + continue; + } else { + // 2nd iteration we overrwrite return with break. + foo = 42; + break; + } + } + } + return foo; +} + +testStopContinueInsideSwitch() { + var foo = 1; + switch (foo) { + jump5: + case 5: + return -1; + + case 1: + try { + continue jump5; + } finally { + return 42; + } + } +} + +testStopContinueInsideSwitch2() { + var foo = 1; + switch (foo) { + jump5: + case 5: + return -1; + + jump42: + case 5: + return 42; + + case 1: + try { + continue jump5; + } finally { + continue jump42; + } + } +} + +main() { + Expect.isTrue(testSimpleBreak() == 3); + Expect.isTrue(testReturnFinally() == 42); + Expect.isTrue(testNestedReturnFinally() == 42); + Expect.isTrue(testReturnInsideLoop() == 42); + Expect.isTrue(testStopContinueInsideLoop() == 42); + Expect.isTrue(testStopBreakInsideLoop() == 42); + Expect.isTrue(testStopBreakInsideLoop2() == 42); + Expect.isTrue(testStopContinueInsideLoop() == 42); + Expect.isTrue(testStopContinueInsideSwitch() == 42); + Expect.isTrue(testStopContinueInsideSwitch2() == 42); +} diff --git a/tests/kernel/unsorted/type_args_regression_test.dart b/tests/kernel/unsorted/type_args_regression_test.dart new file mode 100644 index 00000000000..4546530d18c --- /dev/null +++ b/tests/kernel/unsorted/type_args_regression_test.dart @@ -0,0 +1,22 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class Box { + T value; + + Box(this.value); + + factory Box.a(T v) => new Box(v); + factory Box.b(T v) = Box; + factory Box.c(T v) => new Box(v); +} + +main() { + Expect.isTrue(new Box(1).value == 1); + Expect.isTrue(new Box.a(1).value == 1); + Expect.isTrue(new Box.b(1).value == 1); + Expect.isTrue(new Box.c(1).value == 1); +} diff --git a/tests/kernel/unsorted/types_test.dart b/tests/kernel/unsorted/types_test.dart new file mode 100644 index 00000000000..d560217f558 --- /dev/null +++ b/tests/kernel/unsorted/types_test.dart @@ -0,0 +1,202 @@ +// Copyright (c) 2016, 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. + +import 'expect.dart'; + +class TypeTester { + const TypeTester(); + bool isCorrectType(object) => object is T; +} + +class ClosureTypeTester { + const ClosureTypeTester(); + bool isCorrectType(object) => (() => object is T)(); +} + +class Base { + final A a; + final B b; + const Base(this.a, this.b); + const factory Base.fac(A a, B b) = Base; +} + +class Sub1 extends Base { + final D d; + const Sub1(C a, this.d) : super(a, a); + const factory Sub1.fac(C a, D d) = Sub1; +} + +class Sub2 extends Base { + const Sub2(C a, D b) : super(b, a); + const factory Sub2.fac(C a, D b) = Sub2; +} + +class G { } +class I { } +class A implements I { } +class B extends A { } +class C {} + +testConstantLiteralTypes() { + Expect.isTrue(const [1] is List); + Expect.isTrue(const [1] is List); + Expect.isTrue(const [1] is List); + Expect.isTrue(const [1] is List); + Expect.isTrue(const [1] is List); + Expect.isTrue(!(const [1] is List)); + Expect.isTrue(const {"a": 1} is Map); + Expect.isTrue(const {"a": 1} is Map); + Expect.isTrue(const {"a": 1} is Map); + Expect.isTrue(const {"a": 1} is Map); + Expect.isTrue(const {"a": 1} is Map); + Expect.isTrue(!(const {"a": 1} is Map)); +} + +testNonConstantLiteralTypes() { + Expect.isTrue([1] is List); + Expect.isTrue([1] is List); + Expect.isTrue([1] is List); + Expect.isTrue([1] is List); + Expect.isTrue([1] is List); + Expect.isTrue(!([1] is List)); +} + +testParametrizedClass() { + Expect.isTrue(new Base(1, 1) is Base); + Expect.isTrue(new Base(1, 1) is Base); + Expect.isTrue(new Base(1, 1) is Base); + Expect.isTrue(!(new Base(1, 1) is Base)); + Expect.isTrue(!(new Base(1, 1) is Base)); + Expect.isTrue(new Sub1(1, "1") is Base); + Expect.isTrue(new Sub1(1, "1") is Base); + Expect.isTrue(new Sub1(1, "1") is Sub1); + Expect.isTrue(new Sub1(1, "1") is Sub1); + Expect.isTrue(!(new Sub1(1, "1") is Base)); + Expect.isTrue(!(new Sub1(1, "1") is Base)); + Expect.isTrue(!(new Sub1(1, "1") is Sub1)); + Expect.isTrue(new Sub2(1, "1") is Base); + Expect.isTrue(new Sub2(1, "1") is Base); + Expect.isTrue(new Sub2(1, "1") is Sub2); + Expect.isTrue(new Sub2(1, "1") is Sub2); + Expect.isTrue(!(new Sub2(1, "1") is Base)); + Expect.isTrue(!(new Sub2(1, "1") is Base)); + Expect.isTrue(!(new Sub2(1, "1") is Sub2)); +} + +testTypeTester() { + Expect.isTrue(new TypeTester().isCorrectType(10)); + Expect.isTrue(!new TypeTester().isCorrectType("abc")); + Expect.isTrue(new TypeTester>().isCorrectType([1])); + Expect.isTrue(new TypeTester>().isCorrectType([1])); + Expect.isTrue(!new TypeTester>().isCorrectType(["1"])); + Expect.isTrue(new TypeTester>() + .isCorrectType(new Sub2(1, "1"))); + Expect.isTrue(new TypeTester>() + .isCorrectType(new Sub2(1, "1"))); +} + +testClosureTypeTester() { + Expect.isTrue(new ClosureTypeTester().isCorrectType(10)); + Expect.isTrue(!new ClosureTypeTester().isCorrectType("abc")); + Expect.isTrue(new ClosureTypeTester>().isCorrectType([1])); + Expect.isTrue(new ClosureTypeTester>().isCorrectType([1])); + Expect.isTrue(!new ClosureTypeTester>() + .isCorrectType(["1"])); + Expect.isTrue(new ClosureTypeTester>() + .isCorrectType(new Sub2(1, "1"))); + Expect.isTrue(new ClosureTypeTester>() + .isCorrectType(new Sub2(1, "1"))); +} + +testConstTypeArguments() { + Expect.isTrue(const Sub1(1, "1") is Sub1); + Expect.isTrue(const Sub1.fac(1, "1") is Sub1); + Expect.isTrue(!(const Sub1(1, "1") is Sub1)); + Expect.isTrue(!(const Sub1.fac(1, "1") is Sub1)); + + Expect.isTrue(const ClosureTypeTester>>() + .isCorrectType( + const >[const Base(1, "2")])); + Expect.isTrue(const ClosureTypeTester>>() + .isCorrectType( + const >[const Base.fac(1, "2")])); + Expect.isTrue(!const ClosureTypeTester>>() + .isCorrectType( + const >[const Base("1", "2")])); + Expect.isTrue(!const ClosureTypeTester>>() + .isCorrectType( + const >[const Base.fac("1", "2")])); + + Expect.isTrue(const TypeTester>() + .isCorrectType(const Sub2(1, "1"))); + Expect.isTrue(const TypeTester>() + .isCorrectType(const Sub2.fac(1, "1"))); + Expect.isTrue(!const TypeTester>() + .isCorrectType(const Sub2("a", "b"))); + Expect.isTrue(!const TypeTester>() + .isCorrectType(const Sub2.fac("a", "b"))); +} + +testNoBound() { + new G(); + new G(); + new G(); + new G(); + new G(); + new G(); + new G(); +} + +testSubtypeChecker() { + Expect.isTrue(new TypeTester().isCorrectType(1)); + Expect.isTrue(new TypeTester().isCorrectType(1.0)); + Expect.isTrue(new TypeTester().isCorrectType(new B())); + Expect.isTrue(new TypeTester().isCorrectType(new C())); + Expect.isTrue(new TypeTester().isCorrectType(new A())); +} + +testFunctionTypes() { + fun(int x, String y) => "${x}${y}"; + Expect.isTrue(fun is FunctionType); + Expect.isTrue(nan is FunctionType); + Expect.isTrue(nan is Function); +} + +num nan(double d, Pattern p) => double.NAN; + +typedef int FunctionType(num _, Pattern __); + + +testLiteralTypeArguments() { + Expect.isTrue(new Foo().foo() is List); + Expect.isTrue(new Foo().bar() is Map); +} + +class Foo { + foo() => []; + bar() => {}; +} + +regressionTest1() { + Expect.isTrue(!StaticTypeTester.isInt('abc')); +} + +class StaticTypeTester { + static isInt(x) => x is int; +} + +main() { + testConstantLiteralTypes(); + testNonConstantLiteralTypes(); + testParametrizedClass(); + testTypeTester(); + testClosureTypeTester(); + testConstTypeArguments(); + testNoBound(); + testSubtypeChecker(); + testFunctionTypes(); + testLiteralTypeArguments(); + regressionTest1(); +} + diff --git a/tests/language/language_kernel.status b/tests/language/language_kernel.status new file mode 100644 index 00000000000..a65d43082d4 --- /dev/null +++ b/tests/language/language_kernel.status @@ -0,0 +1,720 @@ +# Copyright (c) 2016, 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. + +# These tests currently take too long. Remove when they are fixed. +[ $compiler == dartk || $compiler == rasta ] +large_class_declaration_test: Skip +large_implicit_getter_test: Skip +larger_implicit_getter_test: Skip + +# Our buildbot is currently running dartk tests without +# `$kernel_transformers == continuation` because the await/async transformer +# creates new classes defined in patch files and dartk doesn't handle patch +# files yet. + +# dartk: JIT failures +[ $compiler == dartk && $runtime == vm ] +accessor_conflict_export2_test: RuntimeError +accessor_conflict_export_test: RuntimeError +accessor_conflict_import2_test: RuntimeError +accessor_conflict_import_prefixed2_test: RuntimeError +accessor_conflict_import_prefixed_test: RuntimeError +accessor_conflict_import_test: RuntimeError +assertion_test: RuntimeError +async_break_in_finally_test: RuntimeError +async_control_structures_test: RuntimeError +async_star_cancel_and_throw_in_finally_test: RuntimeError +async_star_cancel_while_paused_test: RuntimeError +async_star_regression_fisk_test: Crash +async_star_stream_take_test: Timeout +async_star_take_reyield_test: Timeout +async_star_test: Crash +async_throw_in_catch_test/forceAwait: RuntimeError +async_throw_in_catch_test/none: RuntimeError +asyncstar_throw_in_catch_test: Timeout +asyncstar_yield_test: Timeout +asyncstar_yieldstar_test: Timeout +await_exceptions_test: RuntimeError +await_future_test: RuntimeError +await_regression_test: RuntimeError +bad_constructor_test/05: CompileTimeError +bad_raw_string_negative_test: Fail +cha_deopt1_test: RuntimeError +cha_deopt2_test: RuntimeError +cha_deopt3_test: RuntimeError +closure_type_variable_test: RuntimeError +closures_initializer_test: RuntimeError +compile_time_constant12_test: Crash +compile_time_constant_k_test/01: RuntimeError +compile_time_constant_k_test/02: RuntimeError +compile_time_constant_k_test/03: RuntimeError +compile_time_constant_o_test/01: RuntimeError +compile_time_constant_o_test/02: RuntimeError +config_import_test: RuntimeError +conflicting_type_variable_and_setter_test: CompileTimeError +const_dynamic_type_literal_test/02: RuntimeError +const_error_multiply_initialized_test/02: RuntimeError +const_error_multiply_initialized_test/04: RuntimeError +const_evaluation_test/01: RuntimeError +const_for_in_variable_test/01: MissingCompileTimeError +const_locals_test: RuntimeError +const_nested_test: RuntimeError +const_string_test: RuntimeError +constructor2_test: RuntimeError +constructor3_test: RuntimeError +constructor5_test: RuntimeError +constructor6_test: RuntimeError +constructor_duplicate_final_test/01: MissingRuntimeError +constructor_duplicate_final_test/02: MissingRuntimeError +constructor_duplicate_final_test/03: MissingCompileTimeError +constructor_named_arguments_test/01: Crash +cyclic_type2_test: CompileTimeError +cyclic_type_test/00: RuntimeError +cyclic_type_test/01: RuntimeError +cyclic_type_test/02: CompileTimeError +cyclic_type_test/03: RuntimeError +cyclic_type_test/04: CompileTimeError +cyclic_type_variable_test/01: Crash +cyclic_type_variable_test/02: Crash +cyclic_type_variable_test/03: Crash +cyclic_type_variable_test/04: Crash +cyclic_type_variable_test/none: Crash +deep_nesting1_negative_test: Crash +deep_nesting2_negative_test: Crash +deferred_call_empty_before_load_test: RuntimeError +deferred_closurize_load_library_test: Crash +deferred_constant_list_test: RuntimeError +deferred_constraints_constants_test/none: RuntimeError +deferred_constraints_constants_test/reference_after_load: RuntimeError +deferred_constraints_type_annotation_test/as_operation: RuntimeError +deferred_constraints_type_annotation_test/catch_check: RuntimeError +deferred_constraints_type_annotation_test/is_check: RuntimeError +deferred_constraints_type_annotation_test/new: RuntimeError +deferred_constraints_type_annotation_test/new_before_load: RuntimeError +deferred_constraints_type_annotation_test/new_generic1: RuntimeError +deferred_constraints_type_annotation_test/new_generic2: RuntimeError +deferred_constraints_type_annotation_test/new_generic3: RuntimeError +deferred_constraints_type_annotation_test/none: RuntimeError +deferred_constraints_type_annotation_test/static_method: RuntimeError +deferred_constraints_type_annotation_test/type_annotation1: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic1: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic2: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic3: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic4: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_non_deferred: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_null: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_top_level: RuntimeError +deferred_function_type_test: RuntimeError +deferred_global_test: RuntimeError +deferred_import_core_test: RuntimeError +deferred_inheritance_constraints_test/redirecting_constructor: RuntimeError +deferred_inlined_test: RuntimeError +deferred_load_constants_test/none: RuntimeError +deferred_load_inval_code_test: RuntimeError +deferred_load_library_wrong_args_test/none: RuntimeError +deferred_mixin_test: RuntimeError +deferred_no_such_method_test: RuntimeError +deferred_not_loaded_check_test: RuntimeError +deferred_only_constant_test: RuntimeError +deferred_optimized_test: RuntimeError +deferred_redirecting_factory_test: RuntimeError +deferred_regression_22995_test: RuntimeError +deferred_shadow_load_library_test: RuntimeError +deferred_shared_and_unshared_classes_test: RuntimeError +deferred_static_seperate_test: RuntimeError +deferred_super_dependency_test/01: RuntimeError +deferred_type_dependency_test/as: RuntimeError +deferred_type_dependency_test/is: RuntimeError +deferred_type_dependency_test/none: RuntimeError +deferred_type_dependency_test/type_annotation: RuntimeError +duplicate_export_negative_test: Fail +enum_duplicate_test/01: RuntimeError +enum_duplicate_test/02: RuntimeError +enum_duplicate_test/none: RuntimeError +enum_mirror_test: RuntimeError +enum_private_test/01: RuntimeError +enum_private_test/02: RuntimeError +enum_private_test/none: RuntimeError +enum_syntax_test/05: MissingCompileTimeError +enum_syntax_test/06: MissingCompileTimeError +enum_test: RuntimeError +evaluation_redirecting_constructor_test: RuntimeError +example_constructor_test: RuntimeError +execute_finally8_test: RuntimeError +execute_finally9_test: RuntimeError +export_double_same_main_test: Crash +export_main_test: Crash +external_test/10: MissingRuntimeError +external_test/13: MissingRuntimeError +external_test/20: MissingRuntimeError +external_test/21: MissingCompileTimeError +external_test/24: MissingCompileTimeError +external_test/25: MissingCompileTimeError +f_bounded_equality_test: RuntimeError +field_initialization_order_test: RuntimeError +final_field_initialization_order_test: RuntimeError +final_super_field_set_test/01: RuntimeError +final_syntax_test/01: MissingCompileTimeError +final_syntax_test/02: MissingCompileTimeError +final_syntax_test/03: MissingCompileTimeError +final_syntax_test/04: MissingCompileTimeError +fixed_type_variable2_test/02: RuntimeError +fixed_type_variable2_test/04: RuntimeError +fixed_type_variable2_test/06: RuntimeError +fixed_type_variable_test/01: RuntimeError +fixed_type_variable_test/02: RuntimeError +fixed_type_variable_test/03: RuntimeError +fixed_type_variable_test/04: RuntimeError +fixed_type_variable_test/05: RuntimeError +fixed_type_variable_test/06: RuntimeError +for2_test: RuntimeError +for_variable_capture_test: RuntimeError +forwarding_factory_constructor_default_values_test: RuntimeError +function_subtype2_test: RuntimeError +function_subtype_bound_closure3_test: RuntimeError +function_subtype_bound_closure4_test: RuntimeError +function_subtype_cast1_test: RuntimeError +function_subtype_inline0_test: RuntimeError +function_subtype_local3_test: RuntimeError +function_subtype_local4_test: RuntimeError +function_subtype_not1_test: RuntimeError +function_type_alias2_test: RuntimeError +function_type_alias3_test: RuntimeError +function_type_alias4_test: RuntimeError +generic2_test: RuntimeError +generic_closure_test: RuntimeError +generic_creation_test: RuntimeError +generic_field_mixin2_test: RuntimeError +generic_field_mixin4_test: RuntimeError +generic_field_mixin5_test: RuntimeError +generic_functions_test: CompileTimeError +generic_inheritance_test: RuntimeError +generic_local_functions_test: CompileTimeError +generic_methods_function_type_test: CompileTimeError +generic_methods_new_test: CompileTimeError +generic_methods_test: CompileTimeError +generic_methods_type_expression_test: CompileTimeError +generic_sends_test: CompileTimeError +generic_test: RuntimeError +getter_closure_execution_order_test: RuntimeError +getter_setter_in_lib_test: RuntimeError +inferrer_closure_test: RuntimeError +initializing_formal_access_test: CompileTimeError +initializing_formal_capture_test: CompileTimeError +initializing_formal_final_test: CompileTimeError +initializing_formal_type_test: CompileTimeError +instance_creation_in_function_annotation_test: RuntimeError +invocation_mirror_test: RuntimeError +is_not_class2_test: RuntimeError +issue13474_test: RuntimeError +issue23244_test: Crash +issue_1751477_test: RuntimeError +least_upper_bound_expansive_test/01: CompileTimeError +least_upper_bound_expansive_test/02: CompileTimeError +least_upper_bound_expansive_test/03: CompileTimeError +least_upper_bound_expansive_test/04: CompileTimeError +least_upper_bound_expansive_test/05: CompileTimeError +least_upper_bound_expansive_test/06: CompileTimeError +least_upper_bound_expansive_test/07: CompileTimeError +least_upper_bound_expansive_test/08: CompileTimeError +least_upper_bound_expansive_test/09: CompileTimeError +least_upper_bound_expansive_test/10: CompileTimeError +least_upper_bound_expansive_test/11: CompileTimeError +least_upper_bound_expansive_test/12: CompileTimeError +least_upper_bound_expansive_test/none: CompileTimeError +library_env_test/has_html_support: RuntimeError +library_env_test/has_no_io_support: RuntimeError +library_env_test/has_no_mirror_support: RuntimeError +list_literal4_test: RuntimeError +main_not_a_function_test/01: Crash +malformed_test/none: RuntimeError +map_literal3_test: RuntimeError +map_literal4_test: RuntimeError +map_literal6_test: RuntimeError +metadata_test: CompileTimeError +method_override_test: RuntimeError +mixin_generic_test: RuntimeError +mixin_illegal_super_use_test/01: MissingCompileTimeError +mixin_illegal_super_use_test/02: MissingCompileTimeError +mixin_illegal_super_use_test/03: MissingCompileTimeError +mixin_illegal_super_use_test/04: MissingCompileTimeError +mixin_illegal_super_use_test/05: MissingCompileTimeError +mixin_illegal_super_use_test/06: MissingCompileTimeError +mixin_illegal_super_use_test/07: MissingCompileTimeError +mixin_illegal_super_use_test/08: MissingCompileTimeError +mixin_illegal_super_use_test/09: MissingCompileTimeError +mixin_illegal_super_use_test/10: MissingCompileTimeError +mixin_illegal_super_use_test/11: MissingCompileTimeError +mixin_illegal_superclass_test/01: MissingCompileTimeError +mixin_illegal_superclass_test/02: MissingCompileTimeError +mixin_illegal_superclass_test/03: MissingCompileTimeError +mixin_illegal_superclass_test/04: MissingCompileTimeError +mixin_illegal_superclass_test/05: MissingCompileTimeError +mixin_illegal_superclass_test/06: MissingCompileTimeError +mixin_illegal_superclass_test/07: MissingCompileTimeError +mixin_illegal_superclass_test/08: MissingCompileTimeError +mixin_illegal_superclass_test/09: MissingCompileTimeError +mixin_illegal_superclass_test/10: MissingCompileTimeError +mixin_illegal_superclass_test/11: MissingCompileTimeError +mixin_illegal_superclass_test/12: MissingCompileTimeError +mixin_illegal_superclass_test/13: MissingCompileTimeError +mixin_illegal_superclass_test/14: MissingCompileTimeError +mixin_illegal_superclass_test/15: MissingCompileTimeError +mixin_illegal_superclass_test/16: MissingCompileTimeError +mixin_illegal_superclass_test/17: MissingCompileTimeError +mixin_illegal_superclass_test/18: MissingCompileTimeError +mixin_illegal_superclass_test/19: MissingCompileTimeError +mixin_illegal_superclass_test/20: MissingCompileTimeError +mixin_illegal_superclass_test/21: MissingCompileTimeError +mixin_illegal_superclass_test/22: MissingCompileTimeError +mixin_illegal_superclass_test/23: MissingCompileTimeError +mixin_illegal_superclass_test/24: MissingCompileTimeError +mixin_illegal_superclass_test/25: MissingCompileTimeError +mixin_illegal_superclass_test/26: MissingCompileTimeError +mixin_illegal_superclass_test/27: MissingCompileTimeError +mixin_illegal_superclass_test/28: MissingCompileTimeError +mixin_illegal_superclass_test/29: MissingCompileTimeError +mixin_illegal_superclass_test/30: MissingCompileTimeError +mixin_illegal_syntax_test/13: CompileTimeError +mixin_illegal_syntax_test/none: CompileTimeError +mixin_mixin2_test: RuntimeError +mixin_mixin3_test: RuntimeError +mixin_mixin4_test: RuntimeError +mixin_mixin5_test: RuntimeError +mixin_mixin_bound2_test: RuntimeError +mixin_mixin_bound_test: RuntimeError +mixin_super_test: RuntimeError +mixin_type_parameters_simple_test: RuntimeError +mixin_type_parameters_super_extends_test: RuntimeError +mixin_type_parameters_super_test: RuntimeError +multiline_newline_test/01: CompileTimeError +multiline_newline_test/02: CompileTimeError +multiline_newline_test/03: CompileTimeError +multiline_newline_test/04: MissingCompileTimeError +multiline_newline_test/05: MissingCompileTimeError +multiline_newline_test/06: MissingCompileTimeError +multiline_newline_test/none: RuntimeError +named_parameters_type_test/01: MissingRuntimeError +named_parameters_type_test/02: MissingRuntimeError +named_parameters_type_test/03: MissingRuntimeError +no_main_test/01: Crash +not_enough_positional_arguments_test/01: CompileTimeError +not_enough_positional_arguments_test/02: Crash +not_enough_positional_arguments_test/05: Crash +null_test/none: RuntimeError +number_identifier_test/05: RuntimeError +positional_parameters_type_test/01: MissingRuntimeError +positional_parameters_type_test/02: MissingRuntimeError +prefix10_negative_test: Fail +prefix16_test: RuntimeError +prefix21_test: RuntimeError +redirecting_constructor_initializer_test: RuntimeError +redirecting_factory_default_values_test/none: RuntimeError +redirecting_factory_reflection_test: RuntimeError +regress_18713_test: RuntimeError +regress_22443_test: RuntimeError +regress_22700_test: RuntimeError +regress_23408_test: RuntimeError +regress_27164_test: CompileTimeError +regress_r24720_test: RuntimeError +reify_typevar_static_test/00: MissingCompileTimeError +reify_typevar_test: RuntimeError +script1_negative_test: Fail +script2_negative_test: Fail +setter_no_getter_call_test/none: RuntimeError +static_setter_get_test/01: RuntimeError +super_call3_test/01: Crash +super_call4_test: RuntimeError +super_getter_setter_test: RuntimeError +super_no_such_method1_test/01: RuntimeError +super_no_such_method2_test/01: RuntimeError +super_no_such_method3_test/01: RuntimeError +super_no_such_method4_test/01: RuntimeError +super_no_such_method5_test/01: RuntimeError +super_operator_index3_test: RuntimeError +super_operator_index4_test: RuntimeError +super_operator_index5_test: RuntimeError +super_operator_index6_test: RuntimeError +super_operator_index7_test: RuntimeError +super_operator_index8_test: RuntimeError +super_test: RuntimeError +switch7_negative_test: Fail +switch_try_catch_test: RuntimeError +sync_generator3_test/test2: RuntimeError +tearoff_basic_test: CompileTimeError +tearoff_constructor_basic_test: CompileTimeError +throw8_test: RuntimeError +try_catch_on_syntax_test/10: MissingRuntimeError +try_catch_on_syntax_test/11: MissingRuntimeError +try_finally_regress_25654_test: RuntimeError +type_checks_in_factory_method_test: RuntimeError +type_parameter_literal_test: RuntimeError +type_parameter_test/04: Crash +type_variable_conflict2_test/02: MissingCompileTimeError +type_variable_conflict2_test/06: MissingCompileTimeError +type_variable_conflict2_test/08: MissingCompileTimeError +type_variable_conflict2_test/10: MissingCompileTimeError +type_variable_function_type_test: RuntimeError +vm/debug_break_enabled_vm_test/01: CompileTimeError +vm/debug_break_enabled_vm_test/none: CompileTimeError +vm/optimized_guarded_field_isolates_test: Crash +vm/reflect_core_vm_test: CompileTimeError +vm/type_cast_vm_test: RuntimeError +vm/type_vm_test: RuntimeError + +# dartk: precompilation failures +[ $compiler == dartkp && $runtime == dart_precompiled ] +accessor_conflict_export2_test: RuntimeError +accessor_conflict_export_test: RuntimeError +accessor_conflict_import2_test: RuntimeError +accessor_conflict_import_prefixed2_test: RuntimeError +accessor_conflict_import_prefixed_test: RuntimeError +accessor_conflict_import_test: RuntimeError +assertion_test: RuntimeError +async_break_in_finally_test: RuntimeError +async_control_structures_test: RuntimeError +async_star_cancel_and_throw_in_finally_test: RuntimeError +async_star_cancel_while_paused_test: RuntimeError +async_star_regression_fisk_test: Crash +async_star_stream_take_test: Timeout +async_star_take_reyield_test: Timeout +async_star_test: Crash +async_throw_in_catch_test/forceAwait: RuntimeError +async_throw_in_catch_test/none: RuntimeError +asyncstar_throw_in_catch_test: Timeout +asyncstar_yield_test: Timeout +asyncstar_yieldstar_test: Timeout +await_exceptions_test: RuntimeError +await_future_test: RuntimeError +await_regression_test: RuntimeError +bad_constructor_test/05: CompileTimeError +bad_raw_string_negative_test: Fail +cha_deopt1_test: RuntimeError +cha_deopt2_test: RuntimeError +cha_deopt3_test: RuntimeError +closure_type_variable_test: RuntimeError +closures_initializer_test: RuntimeError +compile_time_constant12_test: Crash +compile_time_constant_k_test/01: RuntimeError +compile_time_constant_k_test/02: RuntimeError +compile_time_constant_k_test/03: RuntimeError +compile_time_constant_o_test/01: RuntimeError +compile_time_constant_o_test/02: RuntimeError +config_import_test: RuntimeError +conflicting_type_variable_and_setter_test: CompileTimeError +const_dynamic_type_literal_test/02: RuntimeError +const_error_multiply_initialized_test/02: RuntimeError +const_error_multiply_initialized_test/04: RuntimeError +const_evaluation_test/01: Crash +const_for_in_variable_test/01: MissingCompileTimeError +const_nested_test: RuntimeError +constructor2_test: RuntimeError +constructor3_test: RuntimeError +constructor5_test: RuntimeError +constructor6_test: RuntimeError +constructor_duplicate_final_test/01: MissingRuntimeError +constructor_duplicate_final_test/02: MissingRuntimeError +constructor_duplicate_final_test/03: MissingCompileTimeError +constructor_named_arguments_test/01: Crash +cyclic_type2_test: CompileTimeError +cyclic_type_test/00: RuntimeError +cyclic_type_test/01: RuntimeError +cyclic_type_test/02: CompileTimeError +cyclic_type_test/03: RuntimeError +cyclic_type_test/04: CompileTimeError +cyclic_type_variable_test/01: Crash +cyclic_type_variable_test/02: Crash +cyclic_type_variable_test/03: Crash +cyclic_type_variable_test/04: Crash +cyclic_type_variable_test/none: Crash +deep_nesting1_negative_test: Crash +deep_nesting2_negative_test: Crash +deferred_call_empty_before_load_test: RuntimeError +deferred_closurize_load_library_test: Crash +deferred_constant_list_test: RuntimeError +deferred_constraints_constants_test/none: RuntimeError +deferred_constraints_constants_test/reference_after_load: RuntimeError +deferred_constraints_type_annotation_test/as_operation: RuntimeError +deferred_constraints_type_annotation_test/catch_check: RuntimeError +deferred_constraints_type_annotation_test/is_check: RuntimeError +deferred_constraints_type_annotation_test/new: RuntimeError +deferred_constraints_type_annotation_test/new_before_load: RuntimeError +deferred_constraints_type_annotation_test/new_generic1: RuntimeError +deferred_constraints_type_annotation_test/new_generic2: RuntimeError +deferred_constraints_type_annotation_test/new_generic3: RuntimeError +deferred_constraints_type_annotation_test/none: RuntimeError +deferred_constraints_type_annotation_test/static_method: RuntimeError +deferred_constraints_type_annotation_test/type_annotation1: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic1: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic2: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic3: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_generic4: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_non_deferred: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_null: RuntimeError +deferred_constraints_type_annotation_test/type_annotation_top_level: RuntimeError +deferred_function_type_test: RuntimeError +deferred_global_test: RuntimeError +deferred_import_core_test: RuntimeError +deferred_inheritance_constraints_test/redirecting_constructor: RuntimeError +deferred_inlined_test: RuntimeError +deferred_load_constants_test/none: RuntimeError +deferred_load_inval_code_test: RuntimeError +deferred_load_library_wrong_args_test/none: RuntimeError +deferred_mixin_test: RuntimeError +deferred_no_such_method_test: RuntimeError +deferred_not_loaded_check_test: RuntimeError +deferred_only_constant_test: RuntimeError +deferred_optimized_test: RuntimeError +deferred_redirecting_factory_test: RuntimeError +deferred_regression_22995_test: RuntimeError +deferred_shadow_load_library_test: RuntimeError +deferred_shared_and_unshared_classes_test: RuntimeError +deferred_static_seperate_test: RuntimeError +deferred_super_dependency_test/01: RuntimeError +deferred_type_dependency_test/as: RuntimeError +deferred_type_dependency_test/is: RuntimeError +deferred_type_dependency_test/none: RuntimeError +deferred_type_dependency_test/type_annotation: RuntimeError +duplicate_export_negative_test: Fail +enum_duplicate_test/01: RuntimeError +enum_duplicate_test/02: RuntimeError +enum_duplicate_test/none: RuntimeError +enum_mirror_test: RuntimeError +enum_private_test/01: RuntimeError +enum_private_test/02: RuntimeError +enum_private_test/none: RuntimeError +enum_syntax_test/06: MissingCompileTimeError +enum_test: RuntimeError +evaluation_redirecting_constructor_test: RuntimeError +example_constructor_test: RuntimeError +execute_finally8_test: RuntimeError +execute_finally9_test: RuntimeError +export_double_same_main_test: Crash +export_main_test: Crash +external_test/10: MissingRuntimeError +external_test/13: MissingRuntimeError +external_test/20: MissingRuntimeError +external_test/21: MissingCompileTimeError +external_test/24: MissingCompileTimeError +external_test/25: MissingCompileTimeError +f_bounded_equality_test: RuntimeError +field_initialization_order_test: RuntimeError +final_field_initialization_order_test: RuntimeError +final_super_field_set_test/01: RuntimeError +final_syntax_test/01: MissingCompileTimeError +final_syntax_test/02: MissingCompileTimeError +final_syntax_test/03: MissingCompileTimeError +final_syntax_test/04: MissingCompileTimeError +fixed_type_variable2_test/02: RuntimeError +fixed_type_variable2_test/04: RuntimeError +fixed_type_variable2_test/06: RuntimeError +fixed_type_variable_test/01: RuntimeError +fixed_type_variable_test/02: RuntimeError +fixed_type_variable_test/03: RuntimeError +fixed_type_variable_test/04: RuntimeError +fixed_type_variable_test/05: RuntimeError +fixed_type_variable_test/06: RuntimeError +for2_test: RuntimeError +for_variable_capture_test: RuntimeError +forwarding_factory_constructor_default_values_test: RuntimeError +full_stacktrace1_test: RuntimeError +full_stacktrace2_test: RuntimeError +full_stacktrace3_test: RuntimeError +function_subtype2_test: RuntimeError +function_subtype_bound_closure3_test: RuntimeError +function_subtype_bound_closure4_test: RuntimeError +function_subtype_cast1_test: RuntimeError +function_subtype_inline0_test: RuntimeError +function_subtype_local3_test: RuntimeError +function_subtype_local4_test: RuntimeError +function_subtype_not1_test: RuntimeError +function_type_alias2_test: RuntimeError +function_type_alias3_test: RuntimeError +function_type_alias4_test: RuntimeError +generic2_test: RuntimeError +generic_closure_test: RuntimeError +generic_creation_test: RuntimeError +generic_field_mixin2_test: RuntimeError +generic_field_mixin4_test: RuntimeError +generic_field_mixin5_test: RuntimeError +generic_functions_test: CompileTimeError +generic_inheritance_test: RuntimeError +generic_local_functions_test: CompileTimeError +generic_methods_function_type_test: CompileTimeError +generic_methods_new_test: CompileTimeError +generic_methods_test: CompileTimeError +generic_methods_type_expression_test: CompileTimeError +generic_sends_test: CompileTimeError +generic_test: RuntimeError +getter_closure_execution_order_test: RuntimeError +getter_setter_in_lib_test: RuntimeError +if_null_assignment_static_test/35: Crash +inferrer_closure_test: RuntimeError +initializing_formal_access_test: CompileTimeError +initializing_formal_capture_test: CompileTimeError +initializing_formal_final_test: CompileTimeError +initializing_formal_type_test: CompileTimeError +instance_creation_in_function_annotation_test: Crash +invocation_mirror_invoke_on2_test: Crash +invocation_mirror_test: Crash +is_not_class2_test: RuntimeError +issue13474_test: RuntimeError +issue21079_test: Crash +issue22800_test: Crash +issue_1751477_test: RuntimeError +large_class_declaration_test: Timeout +least_upper_bound_expansive_test/01: CompileTimeError +least_upper_bound_expansive_test/02: CompileTimeError +least_upper_bound_expansive_test/03: CompileTimeError +least_upper_bound_expansive_test/04: CompileTimeError +least_upper_bound_expansive_test/05: CompileTimeError +least_upper_bound_expansive_test/06: CompileTimeError +least_upper_bound_expansive_test/07: CompileTimeError +least_upper_bound_expansive_test/08: CompileTimeError +least_upper_bound_expansive_test/09: CompileTimeError +least_upper_bound_expansive_test/10: CompileTimeError +least_upper_bound_expansive_test/11: CompileTimeError +least_upper_bound_expansive_test/12: CompileTimeError +least_upper_bound_expansive_test/none: CompileTimeError +library_env_test/has_html_support: RuntimeError +library_env_test/has_mirror_support: RuntimeError +library_env_test/has_no_io_support: RuntimeError +list_literal4_test: RuntimeError +main_not_a_function_test/01: Crash +malformed_test/none: RuntimeError +map_literal3_test: RuntimeError +map_literal4_test: RuntimeError +map_literal6_test: RuntimeError +metadata_test: CompileTimeError +method_override_test: RuntimeError +mixin_generic_test: RuntimeError +mixin_illegal_super_use_test/01: MissingCompileTimeError +mixin_illegal_super_use_test/02: MissingCompileTimeError +mixin_illegal_super_use_test/03: MissingCompileTimeError +mixin_illegal_super_use_test/04: MissingCompileTimeError +mixin_illegal_super_use_test/05: MissingCompileTimeError +mixin_illegal_super_use_test/06: MissingCompileTimeError +mixin_illegal_super_use_test/07: MissingCompileTimeError +mixin_illegal_super_use_test/08: MissingCompileTimeError +mixin_illegal_super_use_test/09: MissingCompileTimeError +mixin_illegal_super_use_test/10: MissingCompileTimeError +mixin_illegal_super_use_test/11: MissingCompileTimeError +mixin_illegal_superclass_test/01: MissingCompileTimeError +mixin_illegal_superclass_test/02: MissingCompileTimeError +mixin_illegal_superclass_test/03: MissingCompileTimeError +mixin_illegal_superclass_test/04: MissingCompileTimeError +mixin_illegal_superclass_test/05: MissingCompileTimeError +mixin_illegal_superclass_test/06: MissingCompileTimeError +mixin_illegal_superclass_test/07: MissingCompileTimeError +mixin_illegal_superclass_test/08: MissingCompileTimeError +mixin_illegal_superclass_test/09: MissingCompileTimeError +mixin_illegal_superclass_test/10: MissingCompileTimeError +mixin_illegal_superclass_test/11: MissingCompileTimeError +mixin_illegal_superclass_test/12: MissingCompileTimeError +mixin_illegal_superclass_test/13: MissingCompileTimeError +mixin_illegal_superclass_test/14: MissingCompileTimeError +mixin_illegal_superclass_test/15: MissingCompileTimeError +mixin_illegal_superclass_test/16: MissingCompileTimeError +mixin_illegal_superclass_test/17: MissingCompileTimeError +mixin_illegal_superclass_test/18: MissingCompileTimeError +mixin_illegal_superclass_test/19: MissingCompileTimeError +mixin_illegal_superclass_test/20: MissingCompileTimeError +mixin_illegal_superclass_test/21: MissingCompileTimeError +mixin_illegal_superclass_test/22: MissingCompileTimeError +mixin_illegal_superclass_test/23: MissingCompileTimeError +mixin_illegal_superclass_test/24: MissingCompileTimeError +mixin_illegal_superclass_test/25: MissingCompileTimeError +mixin_illegal_superclass_test/26: MissingCompileTimeError +mixin_illegal_superclass_test/27: MissingCompileTimeError +mixin_illegal_superclass_test/28: MissingCompileTimeError +mixin_illegal_superclass_test/29: MissingCompileTimeError +mixin_illegal_superclass_test/30: MissingCompileTimeError +mixin_illegal_syntax_test/13: CompileTimeError +mixin_illegal_syntax_test/none: CompileTimeError +mixin_mixin2_test: RuntimeError +mixin_mixin3_test: RuntimeError +mixin_mixin4_test: RuntimeError +mixin_mixin5_test: RuntimeError +mixin_mixin_bound2_test: RuntimeError +mixin_mixin_bound_test: RuntimeError +mixin_super_test: RuntimeError +mixin_type_parameters_simple_test: RuntimeError +mixin_type_parameters_super_extends_test: RuntimeError +mixin_type_parameters_super_test: RuntimeError +multiline_newline_test/01: CompileTimeError +multiline_newline_test/02: CompileTimeError +multiline_newline_test/03: CompileTimeError +multiline_newline_test/04: MissingCompileTimeError +multiline_newline_test/05: MissingCompileTimeError +multiline_newline_test/06: MissingCompileTimeError +multiline_newline_test/none: RuntimeError +named_parameters_type_test/01: MissingRuntimeError +named_parameters_type_test/02: MissingRuntimeError +named_parameters_type_test/03: MissingRuntimeError +no_main_test/01: Crash +not_enough_positional_arguments_test/01: CompileTimeError +not_enough_positional_arguments_test/02: MissingRuntimeError +not_enough_positional_arguments_test/05: Crash +null_test/none: RuntimeError +number_identifier_test/05: RuntimeError +positional_parameters_type_test/01: MissingRuntimeError +positional_parameters_type_test/02: MissingRuntimeError +prefix10_negative_test: Fail +prefix16_test: RuntimeError +prefix21_test: RuntimeError +redirecting_constructor_initializer_test: RuntimeError +redirecting_factory_default_values_test/none: RuntimeError +redirecting_factory_reflection_test: Crash +regress_18535_test: Crash +regress_18713_test: RuntimeError +regress_22443_test: RuntimeError +regress_22700_test: RuntimeError +regress_22777_test: Crash +regress_23408_test: RuntimeError +regress_26175_test: Crash +regress_27164_test: CompileTimeError +regress_r24720_test: RuntimeError +reify_typevar_test: RuntimeError +script1_negative_test: Fail +script2_negative_test: Fail +setter_no_getter_call_test/none: RuntimeError +stack_trace_test: RuntimeError +stacktrace_rethrow_error_test/none: RuntimeError +stacktrace_rethrow_error_test/withtraceparameter: RuntimeError +stacktrace_rethrow_nonerror_test: RuntimeError +static_setter_get_test/01: RuntimeError +super_call3_test/01: Crash +super_call4_test: RuntimeError +super_getter_setter_test: RuntimeError +super_no_such_method1_test/01: RuntimeError +super_no_such_method2_test/01: RuntimeError +super_no_such_method3_test/01: RuntimeError +super_no_such_method4_test/01: RuntimeError +super_no_such_method5_test/01: RuntimeError +super_operator_index3_test: RuntimeError +super_operator_index4_test: RuntimeError +super_operator_index5_test: RuntimeError +super_operator_index6_test: RuntimeError +super_operator_index7_test: RuntimeError +super_operator_index8_test: RuntimeError +super_test: RuntimeError +switch7_negative_test: Fail +switch_try_catch_test: RuntimeError +sync_generator3_test/test2: RuntimeError +tearoff_basic_test: CompileTimeError +tearoff_constructor_basic_test: CompileTimeError +throw8_test: RuntimeError +try_catch_on_syntax_test/10: MissingRuntimeError +try_catch_on_syntax_test/11: MissingRuntimeError +try_finally_regress_25654_test: RuntimeError +type_checks_in_factory_method_test: RuntimeError +type_parameter_literal_test: RuntimeError +type_parameter_test/04: Crash +type_variable_conflict2_test/02: MissingCompileTimeError +type_variable_function_type_test: RuntimeError +vm/debug_break_enabled_vm_test/01: CompileTimeError +vm/debug_break_enabled_vm_test/none: CompileTimeError +vm/reflect_core_vm_test: CompileTimeError +vm/type_cast_vm_test: RuntimeError +vm/type_vm_test: RuntimeError \ No newline at end of file diff --git a/tools/patch_sdk.dart b/tools/patch_sdk.dart new file mode 100644 index 00000000000..6406a50cf80 --- /dev/null +++ b/tools/patch_sdk.dart @@ -0,0 +1,536 @@ +#!/usr/bin/env dart +// Copyright (c) 2015, 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. + +/// Command line tool to merge the SDK libraries and our patch files. +/// This is currently designed as an offline tool, but we could automate it. + +import 'dart:io'; +import 'dart:math' as math; + +import 'package:analyzer/analyzer.dart'; +import 'package:analyzer/src/generated/sdk.dart'; +import 'package:path/path.dart' as path; + +void main(List argv) { + var base = path.fromUri(Platform.script); + var dartDir = path.dirname(path.dirname(path.absolute(base))); + + if (argv.length != 4 || + !argv.isEmpty && argv.first != 'vm' && argv.first != 'ddc') { + var self = path.relative(base); + print('Usage: $self MODE SDK_DIR PATCH_DIR OUTPUT_DIR'); + print('MODE must be one of ddc or vm.'); + + var toolDir = path.relative(path.dirname(base)); + var sdkExample = path.join(toolDir, 'input_sdk'); + var patchExample = path.join(sdkExample, 'patch'); + var outExample = + path.relative(path.normalize(path.join('gen', 'patched_sdk'))); + print('For example:'); + print('\$ $self ddc $sdkExample $patchExample $outExample'); + + var repositoryDir = path.relative(path.dirname(path.dirname(base))); + sdkExample = path.relative(path.join(repositoryDir, 'sdk')); + patchExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64', + 'obj', 'gen', 'patch')); + outExample = path.relative(path.join(repositoryDir, 'out', 'DebugX64', + 'obj', 'gen', 'patched_sdk')); + print('or:'); + print('\$ $self vm $sdkExample $patchExample $outExample'); + + exit(1); + } + + var mode = argv[0]; + var input = argv[1]; + var sdkLibIn = path.join(input, 'lib'); + var patchIn = argv[2]; + var sdkOut = path.join(argv[3], 'lib'); + + var privateIn = path.join(input, 'private'); + var INTERNAL_PATH = '_internal/compiler/js_lib/'; + + // Copy and patch libraries.dart and version + var libContents = new File(path.join(sdkLibIn, '_internal', + 'sdk_library_metadata', 'lib', 'libraries.dart')).readAsStringSync(); + var patchedLibContents = libContents; + if (mode == 'vm') { + libContents = libContents.replaceAll( + ' libraries = const {', + ''' libraries = const { + + "_builtin": const LibraryInfo( + "_builtin/_builtin.dart", + categories: "Client,Server", + implementation: true, + documented: false, + platforms: VM_PLATFORM), + + "profiler": const LibraryInfo( + "profiler/profiler.dart", + maturity: Maturity.DEPRECATED, + documented: false), + + "_vmservice": const LibraryInfo( + "vmservice/vmservice.dart", + implementation: true, + documented: false, + platforms: VM_PLATFORM), + + "vmservice_io": const LibraryInfo( + "vmservice_io/vmservice_io.dart", + implementation: true, + documented: false, + platforms: VM_PLATFORM), + +'''); + } + _writeSync( + path.join( + sdkOut, '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'), + libContents); + if (mode == 'ddc') { + _writeSync(path.join(sdkOut, '..', 'version'), + new File(path.join(sdkLibIn, '..', 'version')).readAsStringSync()); + } + + // Parse libraries.dart + var sdkLibraries = _getSdkLibraries(libContents); + + // Enumerate core libraries and apply patches + for (SdkLibrary library in sdkLibraries) { + // TODO(jmesserly): analyzer does not handle the default case of + // "both platforms" correctly, and treats it as being supported on neither. + // So instead we skip explicitly marked as either VM or dart2js libs. + if (mode == 'ddc' ? libary.isVmLibrary : library.isDart2JsLibrary) { + continue; + } + + var libraryOut = path.join(sdkLibIn, library.path); + var libraryIn; + if (mode == 'vm' && library.path.contains('typed_data.dart')) { + // dart:typed_data is unlike the other libraries in the SDK. The VM does + // not apply a patch to the base SDK implementation of the library. + // Instead, the VM provides a replacement implementation and ignores the + // sources in the SDK. + libraryIn = + path.join(dartDir, 'runtime', 'lib', 'typed_data.dart'); + } else if (mode == 'ddc' && library.path.contains(INTERNAL_PATH)) { + libraryIn = + path.join(privateIn, library.path.replaceAll(INTERNAL_PATH, '')); + } else { + libraryIn = libraryOut; + } + + var libraryFile = new File(libraryIn); + if (libraryFile.existsSync()) { + var outPaths = [libraryOut]; + var libraryContents = libraryFile.readAsStringSync(); + + int inputModifyTime = + libraryFile.lastModifiedSync().millisecondsSinceEpoch; + var partFiles = []; + for (var part in parseDirectives(libraryContents).directives) { + if (part is PartDirective) { + var partPath = part.uri.stringValue; + outPaths.add(path.join(path.dirname(libraryOut), partPath)); + + var partFile = new File(path.join(path.dirname(libraryIn), partPath)); + partFiles.add(partFile); + inputModifyTime = math.max(inputModifyTime, + partFile.lastModifiedSync().millisecondsSinceEpoch); + } + } + + // See if we can find a patch file. + var patchPath = path.join( + patchIn, path.basenameWithoutExtension(libraryIn) + '_patch.dart'); + + var patchFile = new File(patchPath); + bool patchExists = patchFile.existsSync(); + if (patchExists) { + inputModifyTime = math.max(inputModifyTime, + patchFile.lastModifiedSync().millisecondsSinceEpoch); + } + + // Compute output paths + outPaths = outPaths + .map((p) => path.join(sdkOut, path.relative(p, from: sdkLibIn))) + .toList(); + + // Compare output modify time with input modify time. + bool needsUpdate = false; + for (var outPath in outPaths) { + var outFile = new File(outPath); + if (!outFile.existsSync() || + outFile.lastModifiedSync().millisecondsSinceEpoch < + inputModifyTime) { + needsUpdate = true; + break; + } + } + + if (needsUpdate) { + var contents = [libraryContents]; + contents.addAll(partFiles.map((f) => f.readAsStringSync())); + if (patchExists) { + var patchContents = patchFile.readAsStringSync(); + contents = _patchLibrary( + patchFile.toString(), contents, patchContents); + } + + for (var i = 0; i < outPaths.length; i++) { + if (path.basename(outPaths[i]) == 'internal.dart') { + contents[i] += ''' + +/// Marks a function as an external implementation ("native" in the Dart VM). +/// +/// Provides a backend-specific String that can be used to identify the +/// function's implementation +class ExternalName { + final String name; + const ExternalName(this.name); +} +'''; + } + + _writeSync(outPaths[i], contents[i]); + } + } + } + } + if (mode == 'vm') { + + for (var tuple in [['_builtin', 'builtin.dart']]) { + var vmLibrary = tuple[0]; + var dartFile = tuple[1]; + + // The "dart:_builtin" library is only available for the DartVM. + var builtinLibraryIn = path.join(dartDir, 'runtime', 'bin', dartFile); + var builtinLibraryOut = path.join(sdkOut, vmLibrary, '${vmLibrary}.dart'); + _writeSync(builtinLibraryOut, new File(builtinLibraryIn).readAsStringSync()); + } + + for (var file in ['loader.dart', 'server.dart', 'vmservice_io.dart']) { + var libraryIn = path.join(dartDir, 'runtime', 'bin', 'vmservice', file); + var libraryOut = path.join(sdkOut, 'vmservice_io', file); + _writeSync(libraryOut, new File(libraryIn).readAsStringSync()); + } + } +} + +/// Writes a file, creating the directory if needed. +void _writeSync(String filePath, String contents) { + var outDir = new Directory(path.dirname(filePath)); + if (!outDir.existsSync()) outDir.createSync(recursive: true); + + new File(filePath).writeAsStringSync(contents); +} + +/// Merges dart:* library code with code from *_patch.dart file. +/// +/// Takes a list of the library's parts contents, with the main library contents +/// first in the list, and the contents of the patch file. +/// +/// The result will have `@patch` implementations merged into the correct place +/// (e.g. the class or top-level function declaration) and all other +/// declarations introduced by the patch will be placed into the main library +/// file. +/// +/// This is purely a syntactic transformation. Unlike dart2js patch files, there +/// is no semantic meaning given to the *_patch files, and they do not magically +/// get their own library scope, etc. +/// +/// Editorializing: the dart2js approach requires a Dart front end such as +/// package:analyzer to semantically model a feature beyond what is specified +/// in the Dart language. Since this feature is only for the convenience of +/// writing the dart:* libraries, and not a tool given to Dart developers, it +/// seems like a non-ideal situation. Instead we keep the preprocessing simple. +List _patchLibrary(String name, + List partsContents, + String patchContents) { + var results = []; + + // Parse the patch first. We'll need to extract bits of this as we go through + // the other files. + final patchFinder = new PatchFinder.parseAndVisit(name, patchContents); + + // Merge `external` declarations with the corresponding `@patch` code. + for (var partContent in partsContents) { + var partEdits = new StringEditBuffer(partContent); + var partUnit = parseCompilationUnit(partContent); + partUnit.accept(new PatchApplier(partEdits, patchFinder)); + results.add(partEdits); + } + return new List.from(results.map((e) => e.toString())); +} + +/// Merge `@patch` declarations into `external` declarations. +class PatchApplier extends GeneralizingAstVisitor { + final StringEditBuffer edits; + final PatchFinder patch; + + bool _isLibrary = true; // until proven otherwise. + + PatchApplier(this.edits, this.patch); + + @override + visitCompilationUnit(CompilationUnit node) { + super.visitCompilationUnit(node); + if (_isLibrary) _mergeUnpatched(node); + } + + void _merge(AstNode node, int pos) { + var code = patch.contents.substring(node.offset, node.end); + edits.insert(pos, '\n' + code); + } + + /// Merges directives and declarations that are not `@patch` into the library. + void _mergeUnpatched(CompilationUnit unit) { + // Merge imports from the patch + // TODO(jmesserly): remove duplicate imports + + // To patch a library, we must have a library directive + var libDir = unit.directives.first as LibraryDirective; + int importPos = unit.directives + .lastWhere((d) => d is ImportDirective, orElse: () => libDir) + .end; + for (var d in patch.unit.directives.where((d) => d is ImportDirective)) { + _merge(d, importPos); + } + + int partPos = unit.directives.last.end; + for (var d in patch.unit.directives.where((d) => d is PartDirective)) { + _merge(d, partPos); + } + + // Merge declarations from the patch + int declPos = edits.original.length; + for (var d in patch.mergeDeclarations) { + _merge(d, declPos); + } + } + + @override + visitPartOfDirective(PartOfDirective node) { + _isLibrary = false; + } + + @override + visitFunctionDeclaration(FunctionDeclaration node) { + _maybePatch(node); + } + + /// Merge patches and extensions into the class + @override + visitClassDeclaration(ClassDeclaration node) { + node.members.forEach(_maybePatch); + + var mergeMembers = patch.mergeMembers[_qualifiedName(node)]; + if (mergeMembers == null) return; + + // Merge members from the patch + var pos = node.members.last.end; + for (var member in mergeMembers) { + var code = patch.contents.substring(member.offset, member.end); + edits.insert(pos, '\n\n ' + code); + } + } + + void _maybePatch(AstNode node) { + if (node is FieldDeclaration) return; + + var externalKeyword = (node as dynamic).externalKeyword; + if (externalKeyword == null) return; + + var name = _qualifiedName(node); + var patchNode = patch.patches[name]; + if (patchNode == null) { + print('warning: patch not found for $name: $node'); + return; + } + + Annotation patchMeta = patchNode.metadata.lastWhere(_isPatchAnnotation); + int start = patchMeta.endToken.next.offset; + var code = patch.contents.substring(start, patchNode.end); + + // For some node like static fields, the node's offset doesn't include + // the external keyword. Also starting from the keyword lets us preserve + // documentation comments. + edits.replace(externalKeyword.offset, node.end, code); + } +} + +class PatchFinder extends GeneralizingAstVisitor { + final String contents; + final CompilationUnit unit; + + final Map patches = {}; + final Map mergeMembers = >{}; + final List mergeDeclarations = []; + + PatchFinder.parseAndVisit(String name, String contents) + : contents = contents, + unit = parseCompilationUnit(contents, name: name) { + visitCompilationUnit(unit); + } + + @override + visitCompilationUnitMember(CompilationUnitMember node) { + mergeDeclarations.add(node); + } + + @override + visitClassDeclaration(ClassDeclaration node) { + if (_isPatch(node)) { + var members = []; + for (var member in node.members) { + if (_isPatch(member)) { + patches[_qualifiedName(member)] = member; + } else { + members.add(member); + } + } + if (members.isNotEmpty) { + mergeMembers[_qualifiedName(node)] = members; + } + } else { + mergeDeclarations.add(node); + } + } + + @override + visitFunctionDeclaration(FunctionDeclaration node) { + if (_isPatch(node)) { + patches[_qualifiedName(node)] = node; + } else { + mergeDeclarations.add(node); + } + } + + @override + visitFunctionBody(node) {} // skip method bodies +} + +String _qualifiedName(Declaration node) { + var parent = node.parent; + var className = ''; + if (parent is ClassDeclaration) { + className = parent.name.name + '.'; + } + var name = (node as dynamic).name; + name = (name != null ? name.name : ''); + + var accessor = ''; + if (node is MethodDeclaration) { + if (node.isGetter) accessor = 'get:'; + else if (node.isSetter) accessor = 'set:'; + } + return className + accessor + name; +} + +bool _isPatch(AnnotatedNode node) => node.metadata.any(_isPatchAnnotation); + +bool _isPatchAnnotation(Annotation m) => + m.name.name == 'patch' && m.constructorName == null && m.arguments == null; + +/// Editable string buffer. +/// +/// Applies a series of edits (insertions, removals, replacements) using +/// original location information, and composes them into the edited string. +/// +/// For example, starting with a parsed AST with original source locations, +/// this type allows edits to be made without regards to other edits. +class StringEditBuffer { + final String original; + final _edits = <_StringEdit>[]; + + /// Creates a new transaction. + StringEditBuffer(this.original); + + bool get hasEdits => _edits.length > 0; + + /// Edit the original text, replacing text on the range [begin] and + /// exclusive [end] with the [replacement] string. + void replace(int begin, int end, String replacement) { + _edits.add(new _StringEdit(begin, end, replacement)); + } + + /// Insert [string] at [offset]. + /// Equivalent to `replace(offset, offset, string)`. + void insert(int offset, String string) => replace(offset, offset, string); + + /// Remove text from the range [begin] to exclusive [end]. + /// Equivalent to `replace(begin, end, '')`. + void remove(int begin, int end) => replace(begin, end, ''); + + /// Applies all pending [edit]s and returns a new string. + /// + /// This method is non-destructive: it does not discard existing edits or + /// change the [original] string. Further edits can be added and this method + /// can be called again. + /// + /// Throws [UnsupportedError] if the edits were overlapping. If no edits were + /// made, the original string will be returned. + String toString() { + var sb = new StringBuffer(); + if (_edits.length == 0) return original; + + // Sort edits by start location. + _edits.sort(); + + int consumed = 0; + for (var edit in _edits) { + if (consumed > edit.begin) { + sb = new StringBuffer(); + sb.write('overlapping edits. Insert at offset '); + sb.write(edit.begin); + sb.write(' but have consumed '); + sb.write(consumed); + sb.write(' input characters. List of edits:'); + for (var e in _edits) { + sb.write('\n '); + sb.write(e); + } + throw new UnsupportedError(sb.toString()); + } + + // Add characters from the original string between this edit and the last + // one, if any. + var betweenEdits = original.substring(consumed, edit.begin); + sb.write(betweenEdits); + sb.write(edit.replace); + consumed = edit.end; + } + + // Add any text from the end of the original string that was not replaced. + sb.write(original.substring(consumed)); + return sb.toString(); + } +} + +class _StringEdit implements Comparable<_StringEdit> { + final int begin; + final int end; + final String replace; + + _StringEdit(this.begin, this.end, this.replace); + + int get length => end - begin; + + String toString() => '(Edit @ $begin,$end: "$replace")'; + + int compareTo(_StringEdit other) { + int diff = begin - other.begin; + if (diff != 0) return diff; + return end - other.end; + } +} + +List _getSdkLibraries(String contents) { + var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true); + parseCompilationUnit(contents).accept(libraryBuilder); + return libraryBuilder.librariesMap.sdkLibraries; +} diff --git a/tools/patch_sdk.py b/tools/patch_sdk.py new file mode 100644 index 00000000000..bfc83273320 --- /dev/null +++ b/tools/patch_sdk.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# Copyright (c) 2016, 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. + +import os +import subprocess +import sys +import utils + +def main(): + dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart') + dart_file = os.path.join(os.path.dirname(__file__), 'patch_sdk.dart') + subprocess.check_call([dart, dart_file] + sys.argv[1:]); + +if __name__ == '__main__': + main() diff --git a/tools/testing/dart/co19_test_config.dart b/tools/testing/dart/co19_test_config.dart index c331f93d8aa..9dc55fa48e4 100644 --- a/tools/testing/dart/co19_test_config.dart +++ b/tools/testing/dart/co19_test_config.dart @@ -17,7 +17,8 @@ class Co19TestSuite extends StandardTestSuite { "tests/co19/co19-analyzer2.status", "tests/co19/co19-runtime.status", "tests/co19/co19-dart2js.status", - "tests/co19/co19-dartium.status" + "tests/co19/co19-dartium.status", + "tests/co19/co19-kernel.status" ]); bool isTestFile(String filename) => _testRegExp.hasMatch(filename); diff --git a/tools/testing/dart/compiler_configuration.dart b/tools/testing/dart/compiler_configuration.dart index 49368ce1cc6..2ad03e4cab9 100644 --- a/tools/testing/dart/compiler_configuration.dart +++ b/tools/testing/dart/compiler_configuration.dart @@ -89,6 +89,19 @@ abstract class CompilerConfiguration { arch: configuration['arch'], useBlobs: useBlobs, isAndroid: configuration['system'] == 'android'); + case 'dartk': + return ComposedCompilerConfiguration.createDartKConfiguration( + isHostChecked: isHostChecked, + kernel_transformers: configuration['kernel_transformers'], + useSdk: useSdk); + case 'dartkp': + return ComposedCompilerConfiguration.createDartKPConfiguration( + isHostChecked: isHostChecked, + arch: configuration['arch'], + useBlobs: useBlobs, + isAndroid: configuration['system'] == 'android', + kernel_transformers: configuration['kernel_transformers'], + useSdk: useSdk); case 'none': return new NoneCompilerConfiguration( isDebug: isDebug, @@ -199,6 +212,257 @@ class NoneCompilerConfiguration extends CompilerConfiguration { } } +/// The "dartk" compiler. +class DartKCompilerConfiguration extends CompilerConfiguration { + DartKCompilerConfiguration({bool isHostChecked, bool useSdk}) + : super._subclass(isHostChecked: isHostChecked, useSdk: useSdk); + + @override + String computeCompilerPath(String buildDir) { + return 'third_party/pkg/kernel/bin/dartk.dart'; + } + + CompilationCommand computeCompilationCommand( + String outputFileName, + String buildDir, + CommandBuilder commandBuilder, + List arguments, + Map environmentOverrides) { + var extraArguments = [ + '--sdk', + '$buildDir/obj/gen/patched_sdk', + '--link', + '--target=vm', + '--out', + outputFileName + ]; + return commandBuilder.getKernelCompilationCommand( + 'dartk', + outputFileName, + true, + bootstrapDependencies(buildDir), + computeCompilerPath(buildDir), + []..addAll(arguments)..addAll(extraArguments), + environmentOverrides); + } + + CommandArtifact computeCompilationArtifact( + String buildDir, + String tempDir, + CommandBuilder commandBuilder, + List arguments, + Map environmentOverrides) { + return new CommandArtifact([ + this.computeCompilationCommand('$tempDir/out.dill', buildDir, + CommandBuilder.instance, arguments, environmentOverrides) + ], '$tempDir/out.dill', 'application/dart'); + } +} + +typedef List CompilerArgumentsFunction( + List globalArguments, + String previousCompilerOutput); + +class PipelineCommand { + final CompilerConfiguration compilerConfiguration; + final CompilerArgumentsFunction _argumentsFunction; + + PipelineCommand._(this.compilerConfiguration, this._argumentsFunction); + + factory PipelineCommand.runWithGlobalArguments(CompilerConfiguration conf) { + return new PipelineCommand._(conf, (List globalArguments, + String previousOutput) { + assert(previousOutput == null); + return globalArguments; + }); + } + + factory PipelineCommand.runWithDartOrKernelFile(CompilerConfiguration conf) { + return new PipelineCommand._(conf, (List globalArguments, + String previousOutput) { + var filtered = globalArguments + .where((String name) => name.endsWith('.dart') || + name.endsWith('.dill')) + .toList(); + assert(filtered.length == 1); + return filtered; + }); + } + + factory PipelineCommand.runWithPreviousKernelOutput( + CompilerConfiguration conf) { + return new PipelineCommand._(conf, (List globalArguments, + String previousOutput) { + assert(previousOutput.endsWith('.dill')); + return [previousOutput]; + }); + } + + List extractArguments(List globalArguments, + String previousOutput) { + return _argumentsFunction(globalArguments, previousOutput); + } +} + +class ComposedCompilerConfiguration extends CompilerConfiguration { + final List pipelineCommands; + + ComposedCompilerConfiguration(this.pipelineCommands) + : super._subclass(); + + CommandArtifact computeCompilationArtifact( + String buildDir, + String tempDir, + CommandBuilder commandBuilder, + List globalArguments, + Map environmentOverrides) { + + List allCommands = []; + + // The first compilation command is as usual. + var arguments = pipelineCommands[0].extractArguments(globalArguments, null); + CommandArtifact artifact = + pipelineCommands[0].compilerConfiguration.computeCompilationArtifact( + buildDir, tempDir, commandBuilder, arguments, environmentOverrides); + allCommands.addAll(artifact.commands); + + // The following compilation commands are based on the output of the + // previous one. + for (int i = 1; i < pipelineCommands.length; i++) { + PipelineCommand pc = pipelineCommands[i]; + + arguments = pc.extractArguments(globalArguments, artifact.filename); + artifact = pc.compilerConfiguration.computeCompilationArtifact( + buildDir, tempDir, commandBuilder, arguments, environmentOverrides); + + allCommands.addAll(artifact.commands); + } + + return new CommandArtifact( + allCommands, artifact.filename, artifact.mimeType); + } + + List computeCompilerArguments(vmOptions, sharedOptions, args) { + // The result will be passed as an input to [extractArguments] + // (i.e. the arguments to the [PipelineCommand]). + return new List.from(sharedOptions)..addAll(args); + } + + List computeRuntimeArguments( + RuntimeConfiguration runtimeConfiguration, + String buildDir, + TestInformation info, + List vmOptions, + List sharedOptions, + List originalArguments, + CommandArtifact artifact) { + return [artifact.filename]; + } + + static ComposedCompilerConfiguration createDartKPConfiguration( + {bool isHostChecked, String arch, bool useBlobs, bool isAndroid, + String kernel_transformers, bool useSdk}) { + var nested = []; + + // Compile with dartk. + nested.add(new PipelineCommand.runWithGlobalArguments( + new DartKCompilerConfiguration(isHostChecked: isHostChecked, + useSdk: useSdk))); + + // Run zero or more transformations. + addKernelTransformations(nested, kernel_transformers); + + // Run the normal precompiler. + nested.add(new PipelineCommand.runWithPreviousKernelOutput( + new PrecompilerCompilerConfiguration( + arch: arch, useBlobs: useBlobs, isAndroid: isAndroid))); + + return new ComposedCompilerConfiguration(nested); + } + + static ComposedCompilerConfiguration createDartKConfiguration( + {bool isHostChecked, bool useSdk, String kernel_transformers}) { + var nested = []; + + // Compile with dartk. + nested.add(new PipelineCommand.runWithGlobalArguments( + new DartKCompilerConfiguration(isHostChecked: isHostChecked, + useSdk: useSdk))); + + // Run zero or more transformations. + addKernelTransformations(nested, kernel_transformers); + + return new ComposedCompilerConfiguration(nested); + } + + static void addKernelTransformations(List nested, + String kernel_transformers) { + if (kernel_transformers != null && kernel_transformers.length > 0) { + List names = kernel_transformers.split(','); + for (var name in names) { + var transformation = new KernelTransformation(name); + nested.add(nested.isEmpty + ? new PipelineCommand.runWithDartOrKernelFile(transformation) + : new PipelineCommand.runWithPreviousKernelOutput(transformation)); + } + } + } +} + +class KernelTransformation extends CompilerConfiguration { + final String transformation; + + KernelTransformation(this.transformation) : super._subclass(); + + CommandArtifact computeCompilationArtifact( + String buildDir, + String tempDir, + CommandBuilder commandBuilder, + List arguments, + Map environmentOverrides) { + assert(arguments.length == 1); + assert(arguments.last.contains('/')); + assert(arguments.last.endsWith('.dill')); + + // The --kernel-transformers=a,b can be specified as + // a = + // a = : + int colonIndex = transformation.indexOf(':'); + String transformationName = transformation; + String executable; + if (colonIndex > 0) { + executable = transformation.substring(colonIndex + 1); + transformationName = transformation.substring(0, colonIndex); + } + + // The transformed output will be always written to a new file in the + // test-specific temporary directory. + var inputFile = arguments.last; + var baseInputFilename = inputFile.substring( + inputFile.lastIndexOf('/') + 1, inputFile.length - '.dill'.length); + var outputFile = '$tempDir/$baseInputFilename.$transformationName.dill'; + + // Use the user-supplied transformer or fall back to `transformer.dart`. + List transformerArguments; + bool useBatchMode = false; + if (executable == null) { + executable = 'third_party/pkg/kernel/bin/transform.dart'; + transformerArguments = + ['-f', 'bin', '-t', transformation, '-o', outputFile, inputFile]; + useBatchMode = true; + } else { + transformerArguments = [inputFile, outputFile]; + } + + var command = commandBuilder.getKernelTransformationCommand( + transformationName, executable, transformerArguments, outputFile, + environmentOverrides, useBatchMode); + + return new CommandArtifact( + [ command ], outputFile, 'application/dart'); + } +} + /// Common configuration for dart2js-based tools, such as, dart2js class Dart2xCompilerConfiguration extends CompilerConfiguration { final String moniker; diff --git a/tools/testing/dart/test_configurations.dart b/tools/testing/dart/test_configurations.dart index f82e62dad59..d9e71280008 100644 --- a/tools/testing/dart/test_configurations.dart +++ b/tools/testing/dart/test_configurations.dart @@ -42,6 +42,7 @@ final TEST_SUITE_DIRECTORIES = [ new Path('tests/corelib'), new Path('tests/html'), new Path('tests/isolate'), + new Path('tests/kernel'), new Path('tests/language'), new Path('tests/lib'), new Path('tests/standalone'), diff --git a/tools/testing/dart/test_options.dart b/tools/testing/dart/test_options.dart index 255564ac5c1..e501d08ba58 100644 --- a/tools/testing/dart/test_options.dart +++ b/tools/testing/dart/test_options.dart @@ -26,6 +26,7 @@ const List defaultTestSelectors = const [ 'pkg', 'analyze_library', 'service', + 'kernel', 'observatory_ui' ]; @@ -75,9 +76,15 @@ class TestOptionsParser { dart2app: dart2appjit: Compile the Dart code into an app snapshot before running test - (only valid with dart_app runtime)''', + (only valid with dart_app runtime) + + dartk: Compile the Dart source into Kernel before running test. + + dartkp: Compiler the Dart source into Kernel and then Kernel into AOT + snapshot before running the test.''', ['-c', '--compiler'], - ['none', 'precompiler', 'dart2js', 'dart2analyzer', 'dart2app', 'dart2appjit'], + ['none', 'precompiler', 'dart2js', 'dart2analyzer', 'dart2app', + 'dart2appjit', 'dartk', 'dartkp'], 'none'), // TODO(antonm): fix the option drt. new _TestOptionSpecification( @@ -155,6 +162,16 @@ class TestOptionsParser { 'simdbc64', ], 'x64'), + new _TestOptionSpecification( + 'kernel_transformers', + 'The kernel transformations to apply in order (separated by comma). ' + 'A transformer can either be just a "name" (in which case it must be ' + 'available in kernel/bin/tansform.dart) or a "name:path" pair ' + '(in which case "path" must point to an executable script which takes' + ' `input-file` and `output-file` as arguments).', + ['--kernel_transformers'], + [], + ''), new _TestOptionSpecification( 'system', 'The operating system to run tests on', @@ -677,6 +694,12 @@ Note: currently only implemented for dart2js.''', case 'precompiler': validRuntimes = const ['dart_precompiled']; break; + case 'dartk': + validRuntimes = const ['vm']; + break; + case 'dartkp': + validRuntimes = const ['dart_precompiled']; + break; case 'none': validRuntimes = const [ 'vm', @@ -687,6 +710,13 @@ Note: currently only implemented for dart2js.''', ]; break; } + var kernelCompilers = const ['dartk', 'dartkp']; + if (config['kernel_transformers']?.length > 0 && + !kernelCompilers.contains(config['compiler'])) { + isValid = false; + print("Warning: The `--kernel_transformers` option can only be used in " + "combination with the ${kernelCompilers.join(', ')} compilers."); + } if (!validRuntimes.contains(config['runtime'])) { isValid = false; print("Warning: combination of compiler '${config['compiler']}' and " @@ -838,9 +868,9 @@ Note: currently only implemented for dart2js.''', if (configuration['package_root'] == null && configuration['packages'] == null) { configuration['packages'] = - TestUtils.dartDirUri.resolve('.packages').toFilePath(); + TestUtils.dartDirUri.resolve('.packages').toFilePath(); } - + // Expand the architectures. if (configuration['arch'].contains(',')) { return _expandHelper('arch', configuration); diff --git a/tools/testing/dart/test_runner.dart b/tools/testing/dart/test_runner.dart index 00a2ebb9b4c..7b1e5965389 100644 --- a/tools/testing/dart/test_runner.dart +++ b/tools/testing/dart/test_runner.dart @@ -221,6 +221,20 @@ class CompilationCommand extends ProcessCommand { deepJsonCompare(_bootstrapDependencies, other._bootstrapDependencies); } +class KernelCompilationCommand extends CompilationCommand { + KernelCompilationCommand._( + String displayName, + String outputFile, + bool neverSkipCompilation, + List bootstrapDependencies, + String executable, + List arguments, + Map environmentOverrides) + : super._(displayName, outputFile, neverSkipCompilation, + bootstrapDependencies, executable, arguments, + environmentOverrides); +} + /// This is just a Pair(String, Map) class with hashCode and operator == class AddFlagsKey { final String flags; @@ -650,6 +664,25 @@ class CommandBuilder { return _getUniqueCommand(command); } + CompilationCommand getKernelCompilationCommand( + String displayName, + outputFile, + neverSkipCompilation, + List bootstrapDependencies, + String executable, + List arguments, + Map environment) { + var command = new KernelCompilationCommand._( + displayName, + outputFile, + neverSkipCompilation, + bootstrapDependencies, + executable, + arguments, + environment); + return _getUniqueCommand(command); + } + AnalysisCommand getAnalysisCommand( String displayName, executable, arguments, environmentOverrides, {String flavor: 'dart2analyzer'}) { @@ -1609,6 +1642,29 @@ class CompilationCommandOutputImpl extends CommandOutputImpl { } } +class KernelCompilationCommandOutputImpl extends CompilationCommandOutputImpl { + KernelCompilationCommandOutputImpl( + Command command, int exitCode, bool timedOut, + List stdout, List stderr, + Duration time, bool compilationSkipped) + : super(command, exitCode, timedOut, stdout, stderr, time, + compilationSkipped); + + bool get canRunDependendCommands { + // See [BatchRunnerProcess]: 0 means success, 1 means compile-time error. + // TODO(asgerf): When the frontend supports it, continue running even if + // there were compile-time errors. See kernel_sdk issue #18. + return !hasCrashed && !timedOut && exitCode == 0; + } + + // If the compiler was able to produce a Kernel IR file we want to run the + // result on the Dart VM. We therefore mark the [KernelCompilationCommand] as + // successful. + // => This ensures we test that the DartVM produces correct CompileTime errors + // as it is supposed to for our test suites. + bool get successful => canRunDependendCommands; +} + class JsCommandlineOutputImpl extends CommandOutputImpl with UnittestSuiteMessagesMixin { JsCommandlineOutputImpl(Command command, int exitCode, bool timedOut, @@ -1683,6 +1739,9 @@ CommandOutput createCommandOutput(Command command, int exitCode, bool timedOut, } else if (command is VmCommand) { return new VmCommandOutputImpl( command, exitCode, timedOut, stdout, stderr, time, pid); + } else if (command is KernelCompilationCommand) { + return new KernelCompilationCommandOutputImpl( + command, exitCode, timedOut, stdout, stderr, time, compilationSkipped); } else if (command is AdbPrecompilationCommand) { return new VmCommandOutputImpl( command, exitCode, timedOut, stdout, stderr, time, pid); @@ -2549,6 +2608,12 @@ class CommandExecutorImpl implements CommandExecutor { if (command is BrowserTestCommand) { return _startBrowserControllerTest(command, timeout); + } else if (command is KernelCompilationCommand) { + // For now, we always run dartk in batch mode. + var name = command.displayName; + assert(name == 'dartk'); + return _getBatchRunner(name) + .runCommand(name, command, timeout, command.arguments); } else if (command is CompilationCommand && dart2jsBatchMode) { return _getBatchRunner("dart2js") .runCommand("dart2js", command, timeout, command.arguments); diff --git a/tools/testing/dart/test_suite.dart b/tools/testing/dart/test_suite.dart index 69f077f8a79..e994822dde2 100644 --- a/tools/testing/dart/test_suite.dart +++ b/tools/testing/dart/test_suite.dart @@ -717,7 +717,8 @@ class StandardTestSuite extends TestSuite { '$directory/$name.status', '$directory/.status', '$directory/${name}_dart2js.status', - '$directory/${name}_analyzer2.status' + '$directory/${name}_analyzer2.status', + '$directory/${name}_kernel.status' ]; return new StandardTestSuite(configuration, name, directory, status_paths, @@ -1675,7 +1676,9 @@ class StandardTestSuite extends TestSuite { * configurations, so it may not use [configuration]. */ Map readOptionsFromFile(Path filePath) { - if (filePath.segments().contains('co19')) { + if (filePath.filename.endsWith('.dill')) { + return optionsFromKernelFile(); + } else if (filePath.segments().contains('co19')) { return readOptionsFromCo19File(filePath); } RegExp testOptionsRegExp = new RegExp(r"// VMOptions=(.*)"); @@ -1801,6 +1804,25 @@ class StandardTestSuite extends TestSuite { }; } + Map optionsFromKernelFile() { + return const { + "vmOptions": const [ const []], + "sharedOptions": const [], + "dartOptions": null, + "packageRoot": null, + "packages": null, + "hasCompileError": false, + "hasRuntimeError": false, + "hasStaticWarning": false, + "otherScripts": const [], + "isMultitest": false, + "isMultiHtmlTest": false, + "subtestNames": const [], + "isolateStubs": '', + "containsDomImport": false, + }; + } + List> getVmOptions(Map optionsFromFile) { var COMPILERS = const ['none', 'precompiler', 'dart2app', 'dart2appjit']; var RUNTIMES = const [