unfork DDC package:async_helper
This code was from the old travis/karma test runner setup, it is no
longer used. Also deletes the old browser test runner files.
Change-Id: I7eab3ebdc709cfc9c48d6f230c73035bc512cea9
Reviewed-on: https://dart-review.googlesource.com/57780
Reviewed-by: Vijay Menon <vsm@google.com>
diff --git a/pkg/dev_compiler/test/browser/language_tests.js b/pkg/dev_compiler/test/browser/language_tests.js
deleted file mode 100644
index 0d33cb0..0000000
--- a/pkg/dev_compiler/test/browser/language_tests.js
+++ /dev/null
@@ -1,796 +0,0 @@
-// 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.
-
-define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require',
- 'test_status'],
- function(dart_sdk, async_helper, expect, unittest, is, require,
- test_status) {
- 'use strict';
-
- async_helper = async_helper.async_helper;
- let minitest = expect.minitest;
- let mochaOnError = window.onerror;
- dart_sdk.dart.trapRuntimeErrors(false);
- dart_sdk.dart.ignoreWhitelistedErrors(false);
- dart_sdk._isolate_helper.startRootIsolate(function() {}, []);
- // Make it easier to debug test failures and required for formatter test that
- // assumes custom formatters are enabled.
- dart_sdk._debugger.registerDevtoolsFormatter();
-
- let html_config = unittest.html_config;
- // Test attributes are a list of strings, or a string for a single
- // attribute. Valid attributes are:
- //
- // 'pass' - test passes (default)
- // 'skip' - don't run the test
- // 'fail' - test fails
- // 'timeout' - test times out
- // 'slow' - use 5s timeout instead of default 2s.
- //
- // Common combinations:
- const pass = 'pass';
- const fail = 'fail';
- const skip_timeout = ['skip', 'timeout'];
-
- // Browsers
- const firefox_fail = is.firefox() ? fail : pass;
- const chrome_fail = is.chrome() ? fail : pass;
-
- // These are typically tests with asynchronous exceptions that our
- // test framework doesn't always catch.
- const flaky = 'skip';
-
- // Tests marked with this are still using the deprecated unittest package
- // because they rely on its support for futures and asynchronous tests, which
- // expect and minitest do not handle.
- // TODO(rnystrom): Move all of these away from using the async test API so
- // they can stop using unittest.
- const async_unittest = ['skip', 'fail'];
-
- // The number of expected unittest errors should be zero but unfortunately
- // there are a lot of broken html unittests.
- let num_expected_unittest_fails = 4;
- let num_expected_unittest_errors = 0;
-
- // TODO(jmesserly): separate StrongModeError from other errors.
- let all_status = {
- 'language': {
- // Flaky on travis (https://github.com/dart-lang/sdk/issues/27224)
- 'async_await_test_03_multi': async_unittest,
-
- 'async_star_pause_test': fail,
- 'async_star_await_pauses_test': skip_timeout,
-
- // TODO(jmesserly): figure out why this test is hanging.
- 'async_star_cancel_and_throw_in_finally_test': skip_timeout,
-
- 'async_star_cancel_while_paused_test': fail,
-
- // TODO(vsm): Re-enable (https://github.com/dart-lang/sdk/issues/28319)
- 'async_star_test_none_multi': async_unittest,
- 'async_star_test_01_multi': async_unittest,
- 'async_star_test_02_multi': async_unittest,
- 'async_star_test_03_multi': async_unittest,
- 'async_star_test_04_multi': async_unittest,
- 'async_star_test_05_multi': async_unittest,
-
- 'async_switch_test': fail,
- 'asyncstar_throw_in_catch_test': ['skip', 'fail'],
- 'await_future_test': skip_timeout,
- 'await_for_test': 'slow',
- 'bit_operations_test_none_multi': fail, // DDC/dart2js canonicalize bitop results to unsigned
- 'branch_canonicalization_test': fail, // JS bit operations truncate to 32 bits.
- 'call_test': fail,
- 'call_closurization_test': fail, // Functions do not expose a "call" method.
- 'call_test': fail,
- 'canonical_const2_test': fail,
- 'canonical_const_test': fail,
- 'compile_time_constant10_test_none_multi': fail,
- 'compile_time_constant_a_test': fail,
- 'compile_time_constant_b_test': fail,
- 'compile_time_constant_d_test': fail,
- 'compile_time_constant_k_test_none_multi': fail,
- 'compile_time_constant_o_test_none_multi': fail,
- 'const_evaluation_test_01_multi': fail,
- 'const_switch_test_02_multi': fail,
- 'const_switch_test_04_multi': fail,
- 'constructor12_test': fail,
- 'covariant_subtyping_with_substitution_test': fail,
- 'custom_await_stack_trace_test': fail,
- 'cyclic_type2_test': fail,
- 'cyclic_type_test_02_multi': fail,
- 'cyclic_type_test_03_multi': fail,
- 'cyclic_type_test_04_multi': fail,
-
- // Deferred libraries are not actually deferred. These tests all test
- // that synchronous access to the library fails.
- 'deferred_call_empty_before_load_test': fail,
- 'deferred_load_library_wrong_args_test_01_multi': fail,
- 'deferred_not_loaded_check_test': fail,
- 'deferred_redirecting_factory_test': fail,
- 'deferred_static_seperate_test': fail,
-
- 'double_int_to_string_test': fail,
- 'dynamic_test': fail,
- 'exception_test': fail,
- 'execute_finally6_test': fail,
- 'expect_test': fail,
- 'extends_test_lib': fail,
- 'f_bounded_quantification3_test': fail,
- 'field_increment_bailout_test': fail,
- 'field_optimization3_test': fail,
- 'first_class_types_test': fail,
- 'flatten_test_01_multi': fail,
- 'flatten_test_04_multi': fail,
- 'flatten_test_05_multi': fail,
- 'flatten_test_08_multi': fail,
- 'flatten_test_09_multi': fail,
- 'flatten_test_12_multi': fail,
- 'for_variable_capture_test': is.firefox('<=50') ? pass : fail,
- 'function_subtype_inline2_test': fail,
- 'function_subtype_named1_test': fail,
- 'function_subtype_named2_test': fail,
- 'function_subtype_optional1_test': fail,
- 'function_subtype_optional2_test': fail,
- 'function_subtype_typearg2_test': fail,
- 'function_subtype_typearg4_test': fail,
- 'function_type_alias6_test_none_multi': fail,
- 'generic_instanceof_test': fail, // runtime strong mode reject
- 'generic_instanceof2_test': fail,
- 'generic_is_check_test': fail,
- 'getter_closure_execution_order_test': fail,
- 'gc_test': 'slow',
- 'identical_closure2_test': fail,
- 'infinite_switch_label_test': fail,
- 'infinity_test': fail,
- 'initializing_formal_final_test': fail,
- 'instance_creation_in_function_annotation_test': fail,
- 'instanceof2_test': fail,
- 'instanceof4_test_01_multi': fail,
- 'instanceof4_test_none_multi': fail,
- 'integer_division_by_zero_test': fail,
- 'issue23244_test': fail,
- 'invocation_mirror_test': fail, // dcall does not correctly detect named arguments
- 'invocation_mirror2_test': fail, // JsInstanceMirror.delegate unimplemented
- 'lazy_static3_test': fail,
- 'least_upper_bound_expansive_test_none_multi': fail,
- 'left_shift_test': fail,
- 'list_is_test': fail,
- 'list_literal3_test': fail,
- 'main_test_03_multi': fail,
- 'many_generic_instanceof_test': fail,
- 'map_literal10_test': fail,
- 'map_literal7_test': fail,
- 'memory_swap_test': skip_timeout,
- 'mint_arithmetic_test': fail,
- 'modulo_test': fail,
- 'named_parameter_clash_test': fail,
- 'named_parameters_passing_falsy_test': is.firefox('<=50') ? fail : pass,
- 'nan_identical_test': fail,
- 'nested_switch_label_test': fail,
- 'number_identifier_test_05_multi': fail,
- 'number_identity2_test': fail,
- 'numbers_test': fail,
- 'regress_16640_test': fail,
- 'regress_22445_test': fail,
- 'regress_22777_test': flaky,
- 'stack_overflow_stacktrace_test': fail,
- 'stack_overflow_test': fail,
- 'stacktrace_test': chrome_fail,
- 'switch_label2_test': fail,
- 'switch_label_test': fail,
- 'switch_try_catch_test': fail,
- 'throwing_lazy_variable_test': fail,
- 'truncdiv_test': fail, // did not throw
- 'try_catch_on_syntax_test_10_multi': fail,
- 'try_catch_on_syntax_test_11_multi': fail,
- 'type_variable_nested_test': fail,
-
- 'bit_operations_test_01_multi': fail,
- 'bit_operations_test_02_multi': fail,
- 'bit_operations_test_03_multi': fail,
- 'bit_operations_test_04_multi': fail,
- 'deferred_load_constants_test_none_multi': fail,
- 'external_test_21_multi': fail,
- 'external_test_24_multi': fail,
- 'multiline_newline_test_04_multi': fail,
- 'multiline_newline_test_05_multi': fail,
- 'multiline_newline_test_06_multi': fail,
- 'multiline_newline_test_none_multi': fail,
-
- // https://github.com/dart-lang/sdk/issues/26124
- 'prefix10_negative_test': fail,
-
- 'library_prefixes_test1': 'skip', // not a test
- 'library_prefixes_test2': 'skip', // not a test
- 'top_level_prefixed_library_test': 'skip', // not a test
-
- },
-
- 'language/function_type': {},
-
- 'language/covariant_override': {},
-
- 'language/function_type': {
- 'function_type50_test': fail,
- 'function_type58_test': fail,
- },
-
- 'codegen': {},
-
- 'corelib_2': {},
-
- 'corelib_2/regexp': {},
-
- 'lib/async': {
- 'async_await_zones_test': fail,
- 'first_regression_test': async_unittest,
- 'future_or_bad_type_test_implements_multi': fail,
- 'future_or_bad_type_test_none_multi': fail,
- 'future_or_non_strong_test': fail,
- 'future_test_none_multi': fail,
- 'future_timeout_test': async_unittest,
- 'intercept_schedule_microtask5_test': async_unittest,
- 'multiple_timer_test': async_unittest,
- 'futures_test': fail,
- 'schedule_microtask2_test': async_unittest,
- 'schedule_microtask3_test': async_unittest,
- 'schedule_microtask5_test': async_unittest,
- 'stream_controller_async_test': async_unittest,
- 'stream_first_where_test': async_unittest,
- 'stream_from_iterable_test': async_unittest,
- 'stream_iterator_test': async_unittest,
- 'stream_join_test': async_unittest,
- 'stream_last_where_test': async_unittest,
- 'stream_periodic2_test': async_unittest,
- 'stream_periodic3_test': async_unittest,
- 'stream_periodic4_test': async_unittest,
- 'stream_periodic5_test': async_unittest,
- 'stream_periodic6_test': async_unittest,
- 'stream_periodic_test': async_unittest,
- 'stream_single_test': async_unittest,
- 'stream_single_to_multi_subscriber_test': async_unittest,
- 'stream_state_helper': async_unittest,
- 'stream_state_nonzero_timer_test': async_unittest,
- 'stream_state_test': async_unittest,
- 'stream_subscription_as_future_test': async_unittest,
- 'stream_subscription_cancel_test': async_unittest,
- 'stream_timeout_test': async_unittest,
- 'stream_transform_test': async_unittest,
- 'stream_transformation_broadcast_test': async_unittest,
- 'stream_transformer_from_handlers_test': fail,
- 'timer_cancel1_test': async_unittest,
- 'timer_cancel2_test': async_unittest,
- 'timer_cancel_test': async_unittest,
- 'timer_isActive_test': async_unittest,
- 'timer_not_available_test': fail,
- 'timer_repeat_test': async_unittest,
- 'timer_test': async_unittest,
- 'zone_error_callback_test': fail,
- 'zone_run_unary_test': fail,
- },
-
- 'lib/collection': {},
-
- 'lib/convert': {
- 'base64_test_01_multi': 'slow',
- 'chunked_conversion_utf85_test': 'slow',
-
- 'encoding_test': skip_timeout,
-
- 'json_utf8_chunk_test': skip_timeout,
- 'latin1_test': skip_timeout,
-
- 'streamed_conversion_json_encode1_test': skip_timeout,
- 'streamed_conversion_json_utf8_decode_test': skip_timeout,
- 'streamed_conversion_json_utf8_encode_test': skip_timeout,
- 'streamed_conversion_utf8_decode_test': skip_timeout,
- 'streamed_conversion_utf8_encode_test': skip_timeout,
- 'utf85_test': skip_timeout,
- },
-
- 'lib/html': {
- 'async_spawnuri_test': async_unittest,
- 'async_test': async_unittest,
-
- // was https://github.com/dart-lang/sdk/issues/27578, needs triage
- 'audiocontext_test': is.chrome('<=54') ? fail : pass,
-
- 'cross_domain_iframe_test': async_unittest,
- 'cssstyledeclaration_test': async_unittest,
- 'css_test': async_unittest,
-
- // This is failing with a range error, I'm guessing because it's looking
- // for a stylesheet and the page has none.
- 'css_rule_list_test': 'fail',
-
- 'custom_element_method_clash_test': async_unittest,
- 'custom_element_name_clash_test': async_unittest,
- 'custom_elements_23127_test': async_unittest,
- 'custom_elements_test': async_unittest,
-
- // Please do not mark this test as fail. If your change breaks this test,
- // please look at the test for instructions on how to generate a new
- // golden file.
- 'debugger_test': firefox_fail,
-
- // https://github.com/dart-lang/sdk/issues/27579.
- 'element_classes_test': 'fail',
- 'element_classes_svg_test': 'fail',
-
- // Failure: 'Expected 56 to be in the inclusive range [111, 160].'.
- 'element_offset_test': 'fail',
-
- 'element_test': async_unittest,
- // This may no longer be a valid test?
- 'element_types_test': is.chrome('<=56') ? pass : fail,
- 'event_customevent_test': async_unittest,
- 'events_test': async_unittest,
- 'fileapi_test': async_unittest,
- 'filereader_test': async_unittest,
- 'fontface_loaded_test': async_unittest,
- 'fontface_test': firefox_fail,
- 'form_data_test': async_unittest,
- 'history_test': async_unittest,
- 'indexeddb_1_test': async_unittest,
- 'indexeddb_2_test': async_unittest,
- 'indexeddb_3_test': async_unittest,
- 'indexeddb_4_test': async_unittest,
- 'indexeddb_5_test': async_unittest,
-
- // was https://github.com/dart-lang/sdk/issues/27578, needs triage
- 'input_element_test': 'fail',
-
- 'interactive_test': async_unittest,
- 'isolates_test': async_unittest,
-
- 'js_interop_1_test': async_unittest,
-
- // The "typed literal" test fails because the object does not have "_c".
- 'js_util_test': 'fail',
- 'keyboard_event_test': async_unittest,
-
- // was https://github.com/dart-lang/sdk/issues/27578, needs triage
- 'mediasource_test': 'fail',
- 'media_stream_test': 'fail',
-
- // https://github.com/dart-lang/sdk/issues/29071
- 'messageevent_test': firefox_fail,
-
- 'mutationobserver_test': async_unittest,
- 'native_gc_test': async_unittest,
- 'postmessage_structured_test': async_unittest,
-
- // this is timing out on Chrome Canary only
- // pinning this skip in case it's a transient canary issue
- 'queryall_test': is.chrome('59') ? ['skip'] : ['slow'], // see sdk #27794
-
- 'request_animation_frame_test': async_unittest,
- 'resource_http_test': async_unittest,
-
- // was https://github.com/dart-lang/sdk/issues/27578, needs triage
- 'rtc_test': is.chrome('<=55') ? fail : pass,
-
- // https://github.com/dart-lang/sdk/issues/29071
- 'serialized_script_value_test': firefox_fail,
-
- 'shadow_dom_test': firefox_fail,
-
- // was https://github.com/dart-lang/sdk/issues/27578, needs triage
- 'speechrecognition_test': firefox_fail,
- 'text_event_test': firefox_fail,
-
- // was https://github.com/dart-lang/sdk/issues/27578, needs triage
- 'touchevent_test': 'fail',
-
- 'transferables_test': async_unittest,
- 'transition_event_test': async_unittest,
- 'url_test': async_unittest,
- 'websocket_test': async_unittest,
- 'websql_test': async_unittest,
- 'wheelevent_test': async_unittest,
- 'worker_api_test': async_unittest,
- 'worker_test': async_unittest,
-
- 'xhr_cross_origin_test': async_unittest,
- 'xhr_test': async_unittest,
-
- // Failing when it gets 3 instead of 42.
- 'js_typed_interop_default_arg_test_default_value_multi': 'fail',
- },
-
- 'lib/html/custom': {
- 'attribute_changed_callback_test': async_unittest,
- 'constructor_calls_created_synchronously_test': async_unittest,
- 'created_callback_test': async_unittest,
- 'entered_left_view_test': async_unittest,
- 'js_custom_test': async_unittest,
- 'mirrors_test': async_unittest,
- 'regress_194523002_test': async_unittest,
- },
-
- 'lib/math': {
- // TODO(het): triage
- 'double_pow_test': fail,
- 'low_test': fail,
- 'pi_test': skip_timeout,
- 'random_big_test': fail,
- },
-
- 'lib/typed_data': {
- // No bigint or int64 support
- 'int32x4_bigint_test': fail,
- 'int64_list_load_store_test': fail,
- 'typed_data_hierarchy_int64_test': fail,
- 'typed_data_list_test': fail,
- },
-
- 'lib/mirrors': {
- 'abstract_class_test_none_multi': fail,
- 'accessor_cache_overflow_test': fail,
- 'basic_types_in_dart_core_test': fail,
- 'class_mirror_location_test': fail,
- 'class_mirror_type_variables_test': fail,
- 'closurization_equivalence_test': fail,
- 'constructor_kinds_test_01_multi': fail,
- 'constructor_kinds_test_none_multi': fail,
- 'constructor_private_name_test': fail,
- 'declarations_type_test': fail,
- 'deferred_mirrors_metadata_test': skip_timeout,
- 'deferred_mirrors_metatarget_test': skip_timeout,
- 'deferred_mirrors_update_test': fail,
- 'empty_test': fail,
- 'equality_test': fail,
- 'fake_function_with_call_test': fail,
- 'field_type_test': fail,
- 'function_type_mirror_test': fail,
- 'generic_f_bounded_test_01_multi': fail,
- 'generic_f_bounded_test_none_multi': fail,
- 'generic_function_typedef_test': fail,
- 'generic_interface_test_none_multi': fail,
- 'generic_local_function_test': fail,
- 'generic_mixin_applications_test': fail,
- 'generic_mixin_test': fail,
- 'generic_superclass_test_01_multi': fail,
- 'generic_superclass_test_none_multi': fail,
- 'generic_type_mirror_test': fail,
- 'generics_double_substitution_test_01_multi': fail,
- 'generics_double_substitution_test_none_multi': fail,
- 'generics_dynamic_test': fail,
- 'generics_special_types_test': fail,
- 'generics_substitution_test': fail,
- 'generics_test_none_multi': fail,
- 'globalized_closures2_test_00_multi': fail,
- 'globalized_closures2_test_none_multi': fail,
- 'globalized_closures_test_00_multi': fail,
- 'globalized_closures_test_none_multi': fail,
- 'hot_get_field_test': fail,
- 'hot_set_field_test': fail,
- 'inherited_metadata_test': fail,
- 'instance_members_unimplemented_interface_test': fail,
- 'instance_members_with_override_test': fail, // JsClassMirror.instanceMembers unimplemented
- 'instantiate_abstract_class_test': fail,
- 'invocation_fuzz_test_emptyarray_multi': fail,
- 'invocation_fuzz_test_false_multi': fail,
- 'invocation_fuzz_test_none_multi': fail,
- 'invocation_fuzz_test_smi_multi': fail,
- 'invocation_fuzz_test_string_multi': fail,
- 'invoke_call_on_closure_test': fail,
- 'invoke_closurization2_test': fail,
- 'invoke_closurization_test': fail,
- 'invoke_import_test': fail,
- 'invoke_named_test_01_multi': fail,
- 'invoke_named_test_none_multi': fail,
- 'invoke_natives_malicious_test': fail,
- 'invoke_private_test': fail,
- 'invoke_private_wrong_library_test': fail,
- 'invoke_test': fail,
- 'invoke_throws_test': fail,
- 'libraries_test': fail,
- 'library_imports_bad_metadata_test_none_multi': fail,
- 'library_metadata_test': fail,
- 'library_uri_io_test': async_unittest,
- 'library_uri_package_test': async_unittest,
- 'list_constructor_test_01_multi': fail,
- 'list_constructor_test_none_multi': fail,
- 'load_library_test': fail,
- 'local_function_is_static_test': fail,
- 'local_isolate_test': fail,
- 'metadata_allowed_values_test_none_multi': fail,
- 'metadata_scope_test_none_multi': fail,
- 'metadata_test': fail,
- 'method_mirror_location_test': fail,
- 'method_mirror_returntype_test': fail,
- 'method_mirror_source_line_ending_test': fail,
- 'method_mirror_source_test': fail,
- 'mirrors_reader_test': fail,
- 'mirrors_used_typedef_declaration_test_01_multi': fail,
- 'mirrors_used_typedef_declaration_test_none_multi': fail,
- 'mixin_test': fail,
- 'null2_test': fail,
- 'null_test': fail,
- 'other_declarations_location_test': fail,
- 'parameter_annotation_mirror_test': fail,
- 'parameter_is_const_test_none_multi': fail,
- 'parameter_metadata_test': fail,
- 'private_class_field_test': fail,
- 'private_symbol_mangling_test': fail,
- 'private_types_test': fail,
- 'reflect_class_test_none_multi': fail,
- 'reflect_runtime_type_test': fail,
- 'reflect_uninstantiated_class_test': fail,
- 'reflected_type_classes_test_none_multi': fail,
- 'reflected_type_function_type_test': fail,
- 'reflected_type_special_types_test': fail,
- 'reflected_type_test_none_multi': fail,
- 'reflected_type_typedefs_test': fail,
- 'reflected_type_typevars_test': fail,
- 'regress_14304_test': fail,
- 'regress_26187_test': fail,
- 'relation_assignable_test': fail,
- 'relation_subtype_test': fail,
- 'set_field_with_final_test': fail,
- 'set_field_with_final_inheritance_test': fail,
- 'symbol_validation_test_01_multi': fail,
- 'symbol_validation_test_none_multi': fail,
- 'to_string_test': fail,
- 'type_argument_is_type_variable_test': fail,
- 'type_variable_is_static_test': fail,
- 'type_variable_owner_test_01_multi': fail,
- 'type_variable_owner_test_none_multi': fail,
- 'typedef_deferred_library_test': fail, // Isolate spawn not support
- 'typedef_library_test': fail,
- 'typedef_metadata_test': fail,
- 'typedef_test': fail,
- 'typevariable_mirror_metadata_test': fail,
- 'unnamed_library_test': fail,
- 'variable_is_const_test_none_multi': fail,
- },
- };
-
- function countMatches(text, regex) {
- let matches = text.match(regex);
- return matches ? matches.length : 0;
- }
- function libraryName(name) {
- return name.replace(/-/g, '$45');
- }
-
- let unittest_tests = [];
- let unittestAccidentallyInitialized = false;
-
- // Pattern for selecting out generated test files in sub-directories
- // of the codegen directory. These are the language, corelib, etc
- // tests
- let languageTestPattern =
- new RegExp('gen/codegen_output/(.*)/([^/]*_test[^/]*)');
- // Pattern for selecting out generated test files in the toplevel
- // codegen directory. These are codegen tests that should be
- // executed.
- let codegenTestPattern =
- new RegExp('gen/codegen_output/([^/]*_test[^/]*)');
- // We need to let Dart unittest control when tests are run not mocha.
- // mocha.allowUncaught(true);
- for (let testFile of allTestFiles) {
- let status_group;
- let name;
- let module;
- let match = languageTestPattern.exec(testFile);
- if (match != null) {
- status_group = match[1];
- name = match[2];
- module = match[0];
- } else if ((match = codegenTestPattern.exec(testFile)) != null) {
- status_group = 'codegen';
- name = match[1];
- module = match[0];
- }
- if (match != null) {
- let status = all_status[status_group];
- if (status == null) throw "No status for '" + status_group + "'";
-
- let expectation = status[name];
- if (expectation == null) expectation = [];
- if (typeof expectation == 'string') expectation = [expectation];
- let has = (tag) => expectation.indexOf(tag) >= 0;
-
- if (has('skip')) {
- let why = 'for unknown reason';
- if (has('timeout')) why = 'known timeout';
- if (has('fail')) why = 'known failure';
- console.debug('Skipping ' + why + ': ' + name);
- continue;
- }
-
- // A few tests are special because they use package:unittest.
- // We run them below.
- let mainLibrary = require(module)[libraryName(name)];
- if (mainLibrary._usesUnittestPackage) {
- unittest_tests.push(() => {
- console.log('Running unittest test ' + testFile);
- mainLibrary.main();
- });
- continue;
- }
-
- var fullName = status_group + '/' + name;
- test(fullName, function(done) { // 'function' to allow `this.timeout`.
- console.debug('Running test: ' + fullName);
-
- // Many tests are async. Currently, tests can indicate this in
- // two different ways. First, `main` can call (in Dart)
- // `async_helper.asyncStart`. We can check if this happened by
- // querying `async_helper.asyncTestStarted` afterward and waiting for
- // the callback if so. Second, `main` can return a `Future`. If so,
- // we wait for that to complete. If neither is true, we assume the
- // test is synchronous.
- //
- // A 'failing' test will throw an exception. This exception may be
- // synchronous (i.e., during `main`) or asynchronous (after `main` in
- // lieu of the callback/future). The latter exceptions are not
- // directly caught. Instead, we intercept `window.onerror` to detect
- // them.
- //
- // Note, if the test is marked 'negative' or 'fail', than pass and fail
- // are effectively inverted: only a success is reported.
- //
- // In all cases, we funnel test completion through the `finish` handler
- // below to handle reporting (based on status) and cleanup state.
- //
- // A test can finish in one of several ways:
- // 1. Synchronous without an error. In this case, `main` returns
- // null and did not set `async_helper`. `finish` is invoked
- // immediately.
- // 2. Synchronous error. `main` throws an error. `finish`
- // is invoked immediately with the error.
- // 3. `Future` without an error. In this case, the future completes
- // and asynchronously invokes `finish`.
- // 4. Via `async_helper` without an error. In this case, the
- // `async_helper` library triggers `finish` via its callback.
- // 5. Asynchronously with an error. In this case, `window.onerror`
- // triggers `finish` with the error.
- // 6. Hangs. In this case, we rely on the underlying mocha framework
- // timeout.
- //
- // TODO(vsm): This currently doesn't handle tests that trigger multiple
- // asynchronous exceptions.
-
- let negative = /negative_test/.test(name) ||
- mainLibrary._expectRuntimeError;
- let fail = has('fail');
-
- function finish(error) {
- // If the test left any lingering detritus in the DOM, blow it away
- // so it doesn't interfere with later tests.
- if (fail) {
- if (negative) {
- if (error) {
- error = new Error(
- "negative test marked as 'fail' " +
- "but passed by throwing:\n" + error);
- }
- } else if (error) {
- error = null
- } else {
- error = new Error("test marked as 'fail' but passed");
- }
- } else if (negative) {
- if (!error) {
- error = new Error("test marked as 'negative' but did not throw");
- } else {
- error = null;
- }
- }
- minitest.finishTests();
- document.body.innerHTML = '';
- console.log("cleared");
- if (error && !(error instanceof Error)) error = new Error(error);
- done(error);
- }
-
- // Intercept uncaught exceptions
- window.onerror = function(message, url, line, column, error) {
- console.warn('Asynchronous error in ' + name + ': ' + message);
- if (!error) {
- error = new Error(message);
- }
- finish(error);
- };
-
- async_helper.asyncTestInitialize(finish);
- if (has('slow')) this.timeout(10000);
-
- var result;
- try {
- var result = mainLibrary.main();
- if (result && !(dart_sdk.async.Future.is(result))) {
- result = null;
- }
- } catch (e) {
- finish(e);
- }
-
- // Ensure this isn't a unittest
- if (!unittestAccidentallyInitialized &&
- unittest.src__test_environment.environment.initialized) {
- // This suppresses duplicate messages for later tests
- unittestAccidentallyInitialized = true;
- finish(new Error('Test ' + name + ' must be marked as a unittest'));
- } else if (!async_helper.asyncTestStarted) {
- if (!result) {
- finish();
- } else {
- result.then(dart_sdk.dart.dynamic)(() => finish(),
- { onError: (e) => finish(e) });
- }
- }
- });
- }
- }
-
- // We run these tests in a mocha test wrapper to avoid the confusing failure
- // case of dart unittests being interleaved with mocha tests.
- // In practice we are really just suppressing all mocha test behavior while
- // Dart unittests run and then re-enabling it when the dart tests complete.
- html_config.useHtmlConfiguration();
- test('run all dart unittests', function(done) { // 'function' to allow `this.timeout`
- // Use the whitelist for all unittests - there may be an error in the framework
- // itself.
- dart_sdk.dart.ignoreWhitelistedErrors(true);
- if (unittest_tests.length == 0) return done();
-
- // TODO(vsm): We're using an old deprecated version of unittest.
- // We need to migrate all tests (in the SDK itself) off of
- // unittest.
-
- // All unittests need to be explicitly marked as such above. If
- // not, the unittest framework will be run in a 'normal' test and
- // left in an inconsistent state at this point triggering spurious
- // failures. This check ensures we're not in such a state. If it fails,
- // we've likely added a new unittest and need to categorize it as such.
- if (unittest.src__test_environment.environment.testCases[dart_sdk.dartx.length] != 0) {
- return done(new Error('Unittest framework in an invalid state'));
- }
-
- this.timeout(100000000);
- this.enableTimeouts(false);
- // Suppress mocha on-error handling because it will mess up unittests.
- window.onerror = function(err, url, line) {
- console.error(err, url, line);
- };
- window.addEventListener('message', (event) => {
- if (event.data == 'unittest-suite-done') {
- window.console.log("Done running unittests");
- let output = document.body.textContent;
- // Restore the Mocha onerror handler in case future tests need to run.
- window.onerror = mochaOnError;
- this.enableTimeouts(true);
- dart_sdk.dart.ignoreWhitelistedErrors(false);
-
- let numErrors = countMatches(output, /\d\s+ERROR/g);
- let numFails = countMatches(output, /\d\s+FAIL/g);
- if (numErrors != num_expected_unittest_errors ||
- numFails != num_expected_unittest_fails) {
- output = "Expected " + num_expected_unittest_fails +
- " fail and " + num_expected_unittest_errors +
- " error unittests, got " + numFails + " fail and " +
- numErrors + "error tests.\n" + output;
- console.error(output);
- done(new Error(output));
- } else {
- console.log(output);
- done();
- }
- }
- });
-
- for (let action of unittest_tests) {
- try {
- action();
- } catch (e) {
- console.error("Caught error tying to setup test:", e);
- }
- }
- });
-});
diff --git a/pkg/dev_compiler/test/browser/runtime_tests.js b/pkg/dev_compiler/test/browser/runtime_tests.js
deleted file mode 100644
index a4b29fe..0000000
--- a/pkg/dev_compiler/test/browser/runtime_tests.js
+++ /dev/null
@@ -1,1254 +0,0 @@
-// 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.
-
-define(['dart_sdk'], function(dart_sdk) {
- const assert = chai.assert;
- const async = dart_sdk.async;
- const core = dart_sdk.core;
- const collection = dart_sdk.collection;
- const dart = dart_sdk.dart;
- const dartx = dart.dartx;
-
- dart.trapRuntimeErrors(false);
-
- suite('ignore', () => {
- "use strict";
-
- let FutureOr = async.FutureOr$;
- let Future = async.Future$;
- let List = core.List$;
-
- setup(() => {
- dart_sdk.dart.ignoreWhitelistedErrors(false);
- });
-
- teardown(() => {
- dart_sdk.dart.ignoreWhitelistedErrors(false);
- });
-
- test('FutureOr', () => {
- let f = Future(dart.dynamic).value(42);
- let l = [1, 2, 3];
-
- assert.throws(() => { dart.as(f, FutureOr(core.int)); });
- assert.throws(() => { dart.as(l, FutureOr(List(core.int)))});
-
- dart_sdk.dart.ignoreWhitelistedErrors(true);
- assert.equal(f, dart.as(f, FutureOr(core.int)));
- assert.equal(l, dart.as(l, FutureOr(List(core.int))));
- });
- });
-
- suite('generic', () => {
- "use strict";
-
- let generic = dart.generic;
-
- test('zero arguments is not allowed', () => {
- assert.throws(() => { generic(function(){}); });
- });
-
- test('dcall noSuchMethod has correct error target', () => {
- assert.throws(() => dart.dcall(42),
- new RegExp('NoSuchMethodError.*\nReceiver: 42', 'm'),
- 'Calls with non-function receiver should throw a NoSuchMethodError' +
- ' with correct target');
-
- // TODO(jmesserly): we should show the name "print" in there somewhere.
- assert.throws(() => dart.dcall(core.print, 1, 2, 3),
- new RegExp('NoSuchMethodError.*\n' +
- "Receiver: Instance of '\\(Object\\) -> void'", 'm'),
- 'Calls with incorrect argument types should throw a NoSuchMethodError' +
- ' with correct target');
- });
-
- test('can throw number', () => {
- try {
- dart.throw(42);
- } catch (e) {
- assert.equal(e, 42);
- }
- });
-
- test('argument count cannot change', () => {
- let SomeType = generic(function(x) { return {x: x}; });
- assert.throws(() => { SomeType(1,2) });
- let obj = {};
- assert.equal(SomeType(obj).x, obj);
- assert.equal(SomeType(obj).x, obj);
- assert.equal(SomeType().x, dart.dynamic);
- });
-
- test('undefined/null are not allowed', () => {
- let SomeType = generic(function(x) {});
- assert.throws(() => { SomeType(void 0) });
- SomeType(1);
- assert.throws(() => { SomeType(void 0) });
- SomeType(1);
- assert.throws(() => { SomeType(null) });
- });
-
- test('result is memoized', () => {
- let t1 = Object.create(null);
- let t2 = Object.create(null);
-
- let count = 0;
- let SomeType = generic(function(x, y) {
- count++;
- return Object.create(null);
- });
-
- let x12 = SomeType(1, 2);
- assert.strictEqual(SomeType(1, 2), x12);
- assert.strictEqual(SomeType(1, 2), x12);
- assert.strictEqual(count, 1);
- let x11 = SomeType(1, 1);
- assert.strictEqual(count, 2);
- assert.strictEqual(SomeType(1, 1), x11);
- assert.strictEqual(count, 2);
- count = 0;
-
- let t1t2 = SomeType(t1, t2);
- assert.strictEqual(count, 1);
- let t2t1 = SomeType(t2, t1);
- assert.strictEqual(count, 2);
- assert.notStrictEqual(t1t2, t2t1);
- assert.strictEqual(SomeType(t1, t2), t1t2);
- assert.strictEqual(SomeType(t2, t1), t2t1);
- assert.strictEqual(SomeType(t1, t2), t1t2);
- count = 0;
-
- // Nothing has been stored on the object
- assert.strictEqual(Object.keys(t1).length, 0);
- assert.strictEqual(Object.keys(t2).length, 0);
- });
-
- test('type constructor is reflectable', () => {
- let SomeType = generic(function(x, y) { return Object.create(null); });
- let someValue = SomeType('hi', 123);
- assert.equal(dart.getGenericClass(someValue), SomeType);
- assert.deepEqual(dart.getGenericArgs(someValue), ['hi', 123]);
- });
-
- test('proper type constructor is called', () => {
- // This tests https://github.com/dart-lang/dev_compiler/issues/178
- let l = dart_sdk._interceptors.JSArray$(core.int).of([1, 2, 3]);
- let s = l[dartx.join]();
- assert.equal(s, '123');
- });
- });
-
-
- suite('instanceOf', () => {
- "use strict";
-
- let expect = assert.equal;
- let generic = dart.generic;
- let intIsNonNullable = false;
- let cast = dart.as;
- let instanceOf = dart.is;
- let strongInstanceOf = dart.strongInstanceOf;
- let getReifiedType = dart.getReifiedType;
- let fnTypeFuzzy = dart.fnTypeFuzzy;
- let typedef = dart.typedef;
- let isSubtype = dart.isSubtype;
-
- let Object = core.Object;
- let String = core.String;
- let dynamic = dart.dynamic;
- let List = core.List;
- let Map = core.Map;
- let Map$ = core.Map$;
- let double = core.double;
- let int = core.int;
- let num = core.num;
- let bool = core.bool;
-
- class A {}
- class B extends A {}
- class C extends B {}
-
- let AA$ = generic((T, U) => {
- class AA extends core.Object {}
- (AA.new = function() {}).prototype = AA.prototype;
- return AA;
- });
- let AA = AA$();
- let BB$ = generic((T, U) => {
- class BB extends AA$(U, T) {}
- (BB.new = function() {}).prototype = BB.prototype;
- return BB;
- });
- let BB = BB$();
- class CC extends BB$(String, List) {}
- (CC.new = function() {}).prototype = CC.prototype;
-
- let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic]));
- let Foo = typedef('Foo', () => fnTypeFuzzy(B, [B, String]));
-
- let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U])))
- let FuncG = FuncG$();
-
- // TODO(vsm): Revisit when we encode types on functions properly.
- // A bar1(C c, String s) => null;
- function bar1(c, s) { return null; }
- dart.fn(bar1, dart.fnType(A, [C, String]));
-
- // bar2(B b, String s) => null;
- function bar2(b, s) { return null; }
- dart.fn(bar2, dart.fnType(dynamic, [B, String]));
-
- // B bar3(B b, Object o) => null;
- function bar3(b, o) { return null; }
- dart.fn(bar3, dart.fnType(B, [B, Object]));
-
- // B bar4(B b, o) => null;
- function bar4(b, o) { return null; }
- dart.fn(bar4, dart.fnType(B, [B, dynamic]));
-
- // C bar5(A a, Object o) => null;
- function bar5(a, o) { return null; }
- dart.fn(bar5, dart.fnType(C, [A, Object]));
-
- // B bar6(B b, String s, String o) => null;
- function bar6(b, s, o) { return null; }
- dart.fn(bar6, dart.fnType(B, [B, String, String]));
-
- // B bar7(B b, String s, [Object o]) => null;
- function bar7(b, s, o) { return null; }
- dart.fn(bar7, dart.fnType(B, [B, String], [Object]));
-
- // B bar8(B b, String s, {Object p}) => null;
- function bar8(b, s, o) { return null; }
- dart.fn(bar8, dart.fnType(B, [B, String], {p: Object}));
-
- let cls1 = dart.fn((c, s) => { return null; },
- dart.fnType(A, [C, String]));
-
- let cls2 = dart.fn((b, s) => { return null; },
- dart.fnType(dynamic, [B, String]));
-
- let cls3 = dart.fn((b, o) => { return null; },
- dart.fnType(B, [B, Object]));
-
- let cls4 = dart.fn((b, o) => { return null; },
- dart.fnType(B, [B, dynamic]));
-
- let cls5 = dart.fn((a, o) => { return null; },
- dart.fnType(C, [A, Object]));
-
- let cls6 = dart.fn((b, s, o) => { return null; },
- dart.fnType(B, [B, String, String]));
-
- let cls7 = dart.fn((b, s, o) => { return null; },
- dart.fnType(B, [B, String], [Object]));
-
- let cls8 =
- dart.fn((b, s, o) => { return null; },
- dart.fnType(B, [B, String], {p: Object}));
-
- function checkType(x, type, expectedTrue) {
- if (expectedTrue === undefined) expectedTrue = true;
- expect(instanceOf(x, type), expectedTrue,
- '"' + x + '" ' +
- (expectedTrue ? 'should' : 'should not') +
- ' be an instance of "' + dart.typeName(type) + '"');
- }
-
- test('int', () => {
- checkType(5, int);
- checkType(5, dynamic);
- checkType(5, Object);
- checkType(5, num);
-
- checkType(5, bool, false);
- checkType(5, String, false);
-
- expect(cast(5, int), 5);
- if (intIsNonNullable) {
- expect(() => cast(null, int), throws);
- } else {
- expect(cast(null, int), null);
- }
- });
-
- test('dynamic', () => {
- checkType(new Object.new(), dynamic);
- checkType(null, dynamic);
-
- expect(cast(null, dynamic), null);
- });
-
- test('Object', () => {
- checkType(new Object.new(), dynamic);
- checkType(null, Object);
-
- expect(cast(null, Object), null);
- });
-
- test('null', () => {
- // Object, dynamic cases are already handled above.
- checkType(null, core.Null);
- checkType(null, core.String, false);
- checkType(null, core.int, false);
- checkType(null, Map, false);
- checkType(void 0, core.Null);
- checkType(void 0, core.Object);
- checkType(void 0, dart.dynamic);
- });
-
- test('String', () => {
- checkType("foo", String);
- checkType("foo", Object);
- checkType("foo", dynamic);
-
- expect(cast(null, String), null);
- });
-
- test('FutureOr', () => {
- let FutureOr = async.FutureOr$;
-
- assert.equal(dart.as(3, FutureOr(int)), 3);
- assert.equal(dart.as(3, FutureOr(double)), 3);
- assert.throws(() => dart.as(3.5, FutureOr(int)));
- assert.equal(dart.as(3.5, FutureOr(double)), 3.5);
- assert.isTrue(dart.is(3, FutureOr(int)));
- assert.isTrue(dart.is(3, FutureOr(double)));
- assert.isFalse(dart.is(3.5, FutureOr(int)));
- assert.isTrue(dart.is(3.5, FutureOr(double)));
-
- assert.equal(dart.as(3, FutureOr(FutureOr(double))), 3);
- assert.isTrue(dart.is(3, FutureOr(FutureOr(double))));
-
- });
-
- test('Map', () => {
- let m1 = Map$(String, String).new();
- let m2 = Map$(Object, Object).new();
- let m3 = Map.new();
- let m4 = collection.HashMap$(dart.dynamic, dart.dynamic).new();
- let m5 = collection.LinkedHashMap.new();
- let m6 = Map$(String, dart.dynamic).new();
-
- // Map<T1,T2> <: Map
- checkType(m1, Map);
- checkType(m1, Object);
-
- // Instance of self
- checkType(m1, getReifiedType(m1));
- checkType(m1, Map$(String, String));
-
- // Covariance on generics
- checkType(m1, getReifiedType(m2));
- checkType(m1, Map$(Object, Object));
-
- // No contravariance on generics.
- checkType(m2, getReifiedType(m1), false);
- checkType(m2, Map$(String, String), false);
-
- // null is! Map
- checkType(null, Map, false);
-
- // Raw generic types
- checkType(m5, Map);
- checkType(m4, Map);
-
- // Is checks
- assert.isFalse(dart.is(m3, Map$(String, String)));
- assert.isFalse(dart.is(m6, Map$(String, String)));
- assert.isTrue(dart.is(m1, Map$(String, String)));
- assert.isFalse(dart.is(m2, Map$(String, String)));
-
- // As checks
- // TODO(vsm): Enable these. We're currently only logging warnings on
- // StrongModeErrors.
- // assert.throws(() => dart.as(m3, Map$(String, String)),
- // dart.StrongModeError);
- // assert.throws(() => dart.as(m6, Map$(String, String)),
- // dart.StrongModeError);
- assert.equal(dart.as(m1, Map$(String, String)), m1);
- // assert.throws(() => dart.as(m2, Map$(String, String)),
- // dart.StrongModeError);
- });
-
- test('constructors', () => {
- class C extends core.Object {
- }
- (C.new = function(x) {}).prototype = C.prototype;
- (C.named = function(x, y) {}).prototype = C.prototype;
- dart.setSignature(C, {
- constructors: () => ({
- new: dart.fnType(C, [core.int]),
- named: dart.fnType(C, [core.int, core.int])
- })
- });
- let getType = dart.classGetConstructorType;
- isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.int]));
- isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.String]), false);
- isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.int]));
- isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.String]), false);
- isSubtype(getType(C, 'named'), dart.fnTypeFuzzy(C, [core.int, core.int]));
- isSubtype(getType(C, 'named'),
- dart.fnTypeFuzzy(C, [core.int, core.String]), false);
- });
-
- test('generic and inheritance', () => {
- let aaraw = new AA.new();
- let aarawtype = getReifiedType(aaraw);
- let aadynamic = new (AA$(dynamic, dynamic).new)();
- let aadynamictype = getReifiedType(aadynamic);
- let aa = new (AA$(String, List).new)();
- let aatype = getReifiedType(aa);
- let bb = new (BB$(String, List).new)();
- let bbtype = getReifiedType(bb);
- let cc = new CC.new();
- let cctype = getReifiedType(cc);
- // We don't allow constructing bad types.
- // This was AA<String> in Dart (wrong number of type args).
- let aabad = new (AA$(dart.dynamic, dart.dynamic).new)();
- let aabadtype = getReifiedType(aabad);
-
- checkType(cc, aatype, false);
- checkType(cc, AA$(String, List), false);
- checkType(cc, bbtype);
- checkType(cc, BB$(String, List));
- checkType(aa, cctype, false);
- checkType(aa, CC, false);
- checkType(aa, bbtype, false);
- checkType(aa, BB$(String, List), false);
- checkType(bb, cctype, false);
- checkType(bb, CC, false);
- checkType(aa, aabadtype);
- checkType(aa, dynamic);
- checkType(aabad, aatype, false);
- checkType(aabad, AA$(String, List), false);
- checkType(aabad, aarawtype);
- checkType(aabad, AA);
- checkType(aaraw, aabadtype);
- checkType(aaraw, AA$(dart.dynamic, dart.dynamic));
- checkType(aaraw, aadynamictype);
- checkType(aaraw, AA$(dynamic, dynamic));
- checkType(aadynamic, aarawtype);
- checkType(aadynamic, AA);
- });
-
- test('void', () => {
- //checkType((x) => x, type((void _(x)) {}));
- });
-
- test('mixins', () => {
- let c = collection;
- var s1 = new (c.SplayTreeSet$(String).new)();
-
- checkType(s1, c.IterableMixin);
- checkType(s1, c.IterableMixin$(String));
- checkType(s1, c.IterableMixin$(int), false);
-
- checkType(s1, c.SetMixin);
- checkType(s1, c.SetMixin$(String));
- checkType(s1, c.SetMixin$(int), false);
- });
-
- test('Type', () => {
- checkType(int, core.Type, true);
- checkType(num, core.Type, true);
- checkType(bool, core.Type, true);
- checkType(String, core.Type, true);
- checkType(dynamic, core.Type, true);
- checkType(Object, core.Type, true);
- checkType(List, core.Type, true);
- checkType(Map, core.Type, true);
- checkType(Map$(int, String), core.Type, true);
- checkType(Func2, core.Type, true);
- checkType(fnTypeFuzzy(dynamic, [dynamic]), core.Type, true);
- checkType(core.Type, core.Type, true);
-
- checkType(3, core.Type, false);
- checkType("hello", core.Type, false);
- })
-
- test('Functions', () => {
- // - return type: Dart is bivariant. We're covariant.
- // - param types: Dart is bivariant. We're contravariant.
- checkType(bar1, Foo, false);
- checkType(cls1, Foo, false);
- checkType(bar1, fnTypeFuzzy(B, [B, String]), false);
- checkType(cls1, fnTypeFuzzy(B, [B, String]), false);
- checkType(bar2, Foo, false);
- checkType(cls2, Foo, false);
- checkType(bar2, fnTypeFuzzy(B, [B, String]), false);
- checkType(cls2, fnTypeFuzzy(B, [B, String]), false);
- checkType(bar3, Foo);
- checkType(cls3, Foo);
- checkType(bar3, fnTypeFuzzy(B, [B, String]));
- checkType(cls3, fnTypeFuzzy(B, [B, String]));
- checkType(bar4, Foo, true);
- checkType(cls4, Foo, true);
- checkType(bar4, fnTypeFuzzy(B, [B, String]), true);
- checkType(cls4, fnTypeFuzzy(B, [B, String]), true);
- checkType(bar5, Foo);
- checkType(cls5, Foo);
- checkType(bar5, fnTypeFuzzy(B, [B, String]));
- checkType(cls5, fnTypeFuzzy(B, [B, String]));
- checkType(bar6, Foo, false);
- checkType(cls6, Foo, false);
- checkType(bar6, fnTypeFuzzy(B, [B, String]), false);
- checkType(cls6, fnTypeFuzzy(B, [B, String]), false);
- checkType(bar7, Foo);
- checkType(cls7, Foo);
- checkType(bar7, fnTypeFuzzy(B, [B, String]));
- checkType(cls7, fnTypeFuzzy(B, [B, String]));
- checkType(bar7, getReifiedType(bar6));
- checkType(cls7, getReifiedType(bar6));
- checkType(bar8, Foo);
- checkType(cls8, Foo);
- checkType(bar8, fnTypeFuzzy(B, [B, String]));
- checkType(cls8, fnTypeFuzzy(B, [B, String]));
- checkType(bar8, getReifiedType(bar6), false);
- checkType(cls8, getReifiedType(bar6), false);
- checkType(bar7, getReifiedType(bar8), false);
- checkType(cls7, getReifiedType(bar8), false);
- checkType(bar8, getReifiedType(bar7), false);
- checkType(cls8, getReifiedType(bar7), false);
-
- // Parameterized typedefs
- checkType(bar1, FuncG$(B, String), false);
- checkType(cls1, FuncG$(B, String), false);
- checkType(bar3, FuncG$(B, String));
- checkType(cls3, FuncG$(B, String));
- });
-
- test('dcall', () => {
- function dd2d(x, y) {return x};
- dart.fn(dd2d);
- function ii2i(x, y) {return x};
- dart.fn(ii2i, dart.fnType(core.int, [core.int, core.int]));
- function ii_2i(x, y) {return x};
- dart.fn(ii_2i, dart.fnType(core.int, [core.int], [core.int]));
- function i_i2i(x, opts) {return x};
- dart.fn(i_i2i,
- dart.fnType(core.int, [core.int], {extra: core.int}));
-
- assert.equal(dart.dcall(dd2d, 0, 1), 0);
- assert.equal(dart.dcall(dd2d, "hello", "world"), "hello");
- assert.throws(() => dart.dcall(dd2d, 0));
- assert.throws(() => dart.dcall(dd2d, 0, 1, 2));
- assert.throws(() => dart.dcall(dd2d, 0, 1, {extra : 3}));
- // This should throw but currently doesn't.
- // assert.throws(() => dart.dcall(dd2d, 0, {extra:3}));
-
- assert.equal(dart.dcall(ii2i, 0, 1), 0);
- assert.throws(() => dart.dcall(ii2i, "hello", "world"));
- assert.throws(() => dart.dcall(ii2i, 0));
- assert.throws(() => dart.dcall(ii2i, 0, 1, 2));
-
- assert.equal(dart.dcall(ii_2i, 0, 1), 0);
- assert.throws(() => dart.dcall(ii_2i, "hello", "world"));
- assert.equal(dart.dcall(ii_2i, 0), 0);
- assert.throws(() => dart.dcall(ii_2i, 0, 1, 2));
-
- assert.throws(() => dart.dcall(i_i2i, 0, 1));
- assert.throws(() => dart.dcall(i_i2i, "hello", "world"));
- assert.equal(dart.dcall(i_i2i, 0), 0);
- assert.throws(() => dart.dcall(i_i2i, 0, 1, 2));
- assert.equal(dart.dcall(i_i2i, 0, {extra: 3}), 0);
- });
-
- test('dsend', () => {
- class Tester extends core.Object {
- m(x, y) {return x;}
- call(x) {return x;}
- static s(x, y) { return x;}
- }
- (Tester.new = function() {
- this.f = dart.fn(x => x,
- dart.fnType(core.int, [core.int]));
- this.me = this;
- }).prototype = Tester.prototype;
- dart.setSignature(Tester, {
- methods: () => ({
- m: dart.fnType(core.int, [core.int, core.int]),
- call: dart.fnType(core.int, [core.int])
- }),
- statics: () => ({
- s: dart.fnType(core.String, [core.String])
- }),
- names: ['s']
- })
- let o = new Tester.new();
-
- // Method send
- assert.equal(dart.dsend(o, 'm', 3, 4), 3);
- assert.equal(dart.dsend(o, 'm', null, 4), null);
- assert.throws(() => dart.dsend(o, 'm', 3));
- assert.throws(() => dart.dsend(o, 'm', "hello", "world"));
- assert.throws(() => dart.dsend(o, 'q', 3));
-
- // Method send through a field
- assert.equal(dart.dsend(o, 'f', 3), 3);
- assert.equal(dart.dsend(o, 'f', null), null);
- assert.throws(() => dart.dsend(o, 'f', "hello"));
- assert.throws(() => dart.dsend(o, 'f', 3, 4));
-
- // Static method call
- assert.equal(dart.dcall(Tester.s, "hello"), "hello");
- assert.equal(dart.dcall(Tester.s, null), null);
- assert.throws(() => dart.dcall(Tester.s, "hello", "world"));
- assert.throws(() => dart.dcall(Tester.s, 0, 1));
-
- // Calling an object with a call method
- assert.equal(dart.dcall(o, 3), 3);
- assert.equal(dart.dcall(o, null), null);
- assert.throws(() => dart.dcall(o, "hello"));
- assert.throws(() => dart.dcall(o, 3, 4));
-
- // Calling through a field containing an object with a call method
- assert.equal(dart.dsend(o, 'me', 3), 3);
- assert.equal(dart.dsend(o, 'me', null), null);
- assert.throws(() => dart.dsend(o, 'me', "hello"));
- assert.throws(() => dart.dsend(o, 'me', 3, 4));
- });
-
- test('Types on top level functions', () => {
- // Test some generated code
- // Test the lazy path
- checkType(core.identityHashCode,
- dart.fnTypeFuzzy(core.int, [core.Object]));
- // Test the normal path
- checkType(core.identical,
- dart.fnTypeFuzzy(core.bool,
- [core.Object, core.Object]));
-
- // Hand crafted tests
- // All dynamic
- function dd2d(x, y) {return x};
- dart.fn(dd2d);
- checkType(dd2d, dart.fnTypeFuzzy(dart.dynamic,
- [dart.dynamic, dart.dynamic]));
-
- // Set the type eagerly
- function ii2i(x, y) {return x};
- dart.fn(ii2i, dart.fnType(core.int, [core.int, core.int]));
- checkType(ii2i, dart.fnTypeFuzzy(core.int,
- [core.int, core.int]));
-
- // Set the type lazily
- function ss2s(x, y) {return x};
- var coreString;
- dart.lazyFn(ss2s,
- () => dart.fnType(coreString,
- [coreString, coreString]));
- coreString = core.String;
- checkType(ss2s, dart.fnTypeFuzzy(core.String,
- [core.String, core.String]));
-
- // Optional types
- function ii_2i(x, y) {return x};
- dart.fn(ii_2i, dart.fnType(core.int, [core.int], [core.int]));
- checkType(ii_2i, dart.fnTypeFuzzy(core.int, [core.int],
- [core.int]));
- checkType(ii_2i, dart.fnTypeFuzzy(core.int, [core.int,
- core.int]));
- checkType(ii_2i, dart.fnTypeFuzzy(core.int, [], [core.int,
- core.int]),
- false);
- checkType(ii_2i, dart.fnTypeFuzzy(core.int, [core.int],
- {extra: core.int}), false);
-
- // Named types
- function i_i2i(x, opts) {return x};
- dart.fn(i_i2i, dart.fnType(core.int, [core.int],
- {extra: core.int}));
- checkType(i_i2i, dart.fnTypeFuzzy(core.int, [core.int],
- {extra: core.int}));
- checkType(i_i2i, dart.fnTypeFuzzy(core.int,
- [core.int, core.int]), false);
- checkType(i_i2i, dart.fnTypeFuzzy(core.int, [core.int], {}));
- checkType(i_i2i,
- dart.fnTypeFuzzy(core.int, [], {extra: core.int,
- also: core.int}), false);
- checkType(i_i2i,
- dart.fnTypeFuzzy(core.int, [core.int], [core.int]), false);
- });
-
- test('Method tearoffs', () => {
- let c = collection;
- // Tear off of an inherited method
- let map = Map$(core.int, core.String).new();
- checkType(dart.bind(map, 'toString'),
- dart.fnTypeFuzzy(String, []));
- checkType(dart.bind(map, 'toString'),
- dart.fnTypeFuzzy(int, []), false, true);
-
- // Tear off of a method directly on the object
- let smap = new (c.SplayTreeMap$(core.int, core.String).new)();
- checkType(dart.bind(smap, 'forEach'),
- dart.fnTypeFuzzy(dart.void,
- [dart.fnTypeFuzzy(dart.void, [core.int, core.String])]));
- checkType(dart.bind(smap, 'forEach'),
- dart.fnTypeFuzzy(dart.void,
- [dart.fnTypeFuzzy(dart.void,
- [core.String, core.String])]), false, true);
-
- // Tear off of a mixed in method
- let mapB = new (c.MapBase$(core.int, core.int).new)();
- checkType(dart.bind(mapB, 'forEach'),
- dart.fnTypeFuzzy(dart.void, [
- dart.fnTypeFuzzy(dart.void, [core.int, core.int])]));
- checkType(dart.bind(mapB, 'forEach'),
- dart.fnTypeFuzzy(dart.void, [
- dart.fnTypeFuzzy(dart.void, [core.int, core.String])]),
- false, true);
-
- // Tear off of a method with a symbol name
- let listB = new (c.ListBase$(core.int).new)();
- // List.add is reified as taking Object
- checkType(dart.bind(listB, dartx.add),
- dart.fnTypeFuzzy(dart.void, [core.int]));
- checkType(dart.bind(listB, dartx.add),
- dart.fnTypeFuzzy(dart.void, [core.String]), true);
- checkType(dart.bind(listB, dartx.removeAt),
- dart.fnTypeFuzzy(dart.void, [core.String]), false);
-
- // Tear off of a static method
- checkType(c.ListBase.listToString,
- dart.fnTypeFuzzy(core.String, [core.List]));
- checkType(c.ListBase.listToString,
- dart.fnTypeFuzzy(core.String, [core.String]), false);
-
- // Tear-off of extension methods on primitives
- checkType(dart.bind(3.0, dartx.floor),
- dart.fnTypeFuzzy(core.int, []));
- checkType(dart.bind(3.0, dartx.floor),
- dart.fnTypeFuzzy(core.String, []), false);
- checkType(dart.bind("", dartx.endsWith),
- dart.fnTypeFuzzy(core.bool, [core.String]));
- checkType(dart.bind("", dartx.endsWith),
- dart.fnTypeFuzzy(core.bool, [core.int]), false);
-
- // Tear off a mixin method
- class Base {
- m(x) {return x;}
- };
- dart.setSignature(Base, {
- methods: () => ({
- m: dart.fnType(core.int, [core.int]),
- })
- });
-
- class M1 {
- m(x) {return x;}
- };
- dart.setSignature(M1, {
- methods: () => ({
- m: dart.fnType(core.num, [core.int]),
- })
- });
-
- class M2 {
- m(x) {return x;}
- };
- dart.setSignature(M2, {
- methods: () => ({
- m: dart.fnType(core.Object, [core.int]),
- })
- });
-
- class O extends dart.mixin(Base, M1, M2) {}
- (O.new = function() {}).prototype = O.prototype;
- dart.setSignature(O, {});
- var obj = new O.new();
- var m = dart.bind(obj, 'm');
- checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
- checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false);
-
- // Test inherited signatures
- class P extends O {
- m(x) {return x;};
- };
- (P.new = function() {}).prototype = P.prototype;
- dart.setSignature(P, {});
- var obj = new P.new();
- var m = dart.bind(obj, 'm');
- checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
- checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false);
- });
-
- test('Object members', () => {
- let nullHash = dart.hashCode(null);
- assert.equal(nullHash, 0);
- let nullString = dart.toString(null);
- assert.equal(nullString, 'null');
-
- let map = Map.new();
- let mapHash = dart.hashCode(map);
- checkType(mapHash, core.int);
- assert.equal(mapHash, map.hashCode);
-
- let mapString = dart.toString(map);
- assert.equal(mapString, map.toString());
- checkType(mapString, core.String);
-
- let str = "A string";
- let strHash = dart.hashCode(str);
- checkType(strHash, core.int);
-
- let strString = dart.toString(str);
- checkType(strString, core.String);
- assert.equal(str, strString);
-
- let n = 42;
- let intHash = dart.hashCode(n);
- checkType(intHash, core.int);
-
- let intString = dart.toString(n);
- assert.equal(intString, '42');
- });
- });
-
- suite('subtyping', function() {
- 'use strict';
-
- let fnTypeFuzzy = dart.fnTypeFuzzy;
- let fnType = dart.fnType;
- let typedef = dart.typedef;
- let isSubtype = dart.isSubtype;
- let int = core.int;
- let num = core.num;
- let dyn = dart.dynamic;
-
- function always(t1, t2) {
- assert.equal(isSubtype(t1, t2), true,
- dart.toString(t1) +
- " should always be a subtype of " +
- dart.toString(t2));
- }
- function never(t1, t2) {
- assert.equal(isSubtype(t1, t2), false,
- dart.toString(t1) +
- " should never be a subtype of " +
- dart.toString(t2));
- }
- function maybe(t1, t2) {
- assert.equal(isSubtype(t1, t2), null,
- dart.toString(t1) +
- " should maybe be a subtype of " +
- dart.toString(t2));
- }
-
- function always2(t1, t2) {
- always(t1, t2);
- always(fnTypeFuzzy(t1, [t2]), fnTypeFuzzy(t2, [t1]));
- }
- function never2(t1, t2) {
- never(t1, t2);
- maybe(fnTypeFuzzy(t1, [t2]), fnTypeFuzzy(t2, [t1]));
- }
- function maybe2(t1, t2) {
- maybe(t1, t2);
- maybe(fnTypeFuzzy(t1, [t2]), fnTypeFuzzy(t2, [t1]));
- }
-
- function run_test(func1, func2, func2opt, func1extra, func2extra) {
- always2(func2(int, int), func2(int, int));
- always2(func2(int, num), func2(int, int));
- always2(func2(int, int), func2(num, int));
-
- always2(func2opt(int, int), func2opt(int, int));
- always2(func2opt(int, num), func2opt(int, int));
- always2(func2opt(int, int), func2opt(num, int));
-
- always2(func2opt(int, int), func2(int, int));
- always2(func2opt(int, num), func2(int, int));
- always2(func2opt(int, int), func2(num, int));
-
- always2(func2opt(int, int), func1(int));
- always2(func2opt(int, num), func1(int));
- always2(func2opt(int, int), func1(num));
-
- always2(func2extra(int, int), func2(int, int));
- always2(func2extra(int, num), func2(int, int));
- always2(func2extra(int, int), func2(num, int));
-
- maybe2(func2(int, int), func2(int, num));
- maybe2(func2(num, int), func2(int, int));
-
- maybe2(func2opt(num, num), func1(int));
-
- maybe2(func2opt(int, int), func2opt(int, num));
- maybe2(func2opt(num, int), func2opt(int, int));
-
- maybe2(func2opt(int, int), func2(int, num));
- maybe2(func2opt(num, int), func2(int, int));
-
- maybe2(func2extra(int, int), func2(int, num));
- maybe2(func2extra(num, int), func2(int, int));
-
- never2(func1(int), func2(int, num));
- never2(func1(num), func2(int, int));
- never2(func1(num), func2(num, num));
-
- never2(func2(int, int), func1(int));
- never2(func2(num, int), func1(int));
- never2(func2(num, num), func1(num));
-
- never2(func1(int), func2opt(int, num));
- never2(func1(num), func2opt(int, int));
- never2(func1(num), func2opt(num, num));
-
- never2(func2(int, int), func2opt(int, num));
- never2(func2(num, int), func2opt(int, int));
- never2(func2(num, num), func2opt(num, num));
-
- never2(func1extra(int), func2(int, num));
- never2(func1extra(num), func2(int, int));
- never2(func1extra(num), func2(num, num));
-
- never2(func1extra(int), func2opt(int, num));
- never2(func1extra(num), func2opt(int, int));
- never2(func1extra(num), func2opt(num, num));
-
- never2(func1(int), func1extra(int));
- never2(func1(num), func1extra(int));
- never2(func1(num), func1extra(num));
-
- never2(func2(int, int), func1extra(int));
- never2(func2(num, int), func1extra(int));
- never2(func2(num, num), func1extra(num));
-
- never2(func2(int, int), func2extra(int, int));
- never2(func2(num, int), func2extra(int, int));
- never2(func2(num, num), func2extra(num, num));
- };
-
- test('basic function types', () => {
- function func1(S) {
- return fnTypeFuzzy(S, []);
- }
-
- function func2(S, T) {
- return fnTypeFuzzy(S, [T]);
- }
-
- function func2opt(S, T) {
- return fnTypeFuzzy(S, [], [T]);
- }
-
- function func1extra(S) {
- return fnTypeFuzzy(S, [], {extra: int});
- }
-
- function func2extra(S, T) {
- return fnTypeFuzzy(S, [T], {extra: int});
- }
-
- run_test(func1, func2, func2opt, func1extra, func2extra);
- });
-
- test('top and bottom types', () => {
- let FutureOr = async.FutureOr$;
- let tops = [
- dart.dynamic,
- core.Object,
- dart.void,
- FutureOr(dart.dynamic),
- FutureOr(core.Object),
- FutureOr(dart.void),
- FutureOr(FutureOr(core.Object)),
- // ... skip the (infinite) rest of the top types :D
- ];
- let bottoms = [dart.bottom, core.Null];
-
- for (let top of tops) {
- for (let bottom of bottoms) {
- always(bottom, top);
- always(
- fnType(bottom, [top]),
- fnType(top, [bottom]));
- }
- }
-
- for (let equalTypes of [tops, bottoms]) {
- for (let t1 of equalTypes) {
- for (let t2 of equalTypes) {
- always(t1, t2);
- always(t2, t1);
-
- let t11 = fnType(t1, [t1]);
- let t22 = fnType(t2, [t2]);
- always(t11, t22);
- always(t22, t11);
- }
- }
- }
- });
-
- test('basic typedefs', () => {
- function func1(S) {
- return dart.typedef('Func1', () => fnTypeFuzzy(S, []))
- }
-
- function func2(S, T) {
- return dart.typedef('Func2', () => fnTypeFuzzy(S, [T]))
- }
-
- function func2opt(S, T) {
- return dart.typedef('Func2', () => fnTypeFuzzy(S, [], [T]))
- }
-
- function func1extra(S) {
- return dart.typedef('Func1', () => fnTypeFuzzy(S, [], {extra: int}))
- }
-
- function func2extra(S, T) {
- return dart.typedef('Func2', () => fnTypeFuzzy(S, [T], {extra: int}))
- }
-
- run_test(func1, func2, func2opt, func1extra, func2extra);
- });
-
- test('basic generic typedefs', () => {
- let func1 = dart.generic(
- (S) => dart.typedef('Func1', () => fnTypeFuzzy(S, [])));
-
- let func2 = dart.generic(
- (S, T) => dart.typedef('Func2', () => fnTypeFuzzy(S, [T])));
-
- let func2opt = dart.generic(
- (S, T) => dart.typedef('Func2', () => fnTypeFuzzy(S, [], [T])));
-
- let func1extra = dart.generic(
- (S) => dart.typedef('Func1', () => fnTypeFuzzy(S, [], {extra: int})));
-
- let func2extra = dart.generic(
- (S, T) => dart.typedef('Func2',
- () => fnTypeFuzzy(S, [T], {extra: int})));
-
- run_test(func1, func2, func2opt, func1extra, func2extra);
- });
-
- test('fuzzy function types', () => {
- always(fnTypeFuzzy(int, [int]), fnTypeFuzzy(dyn, [dyn]));
- always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dyn, [], [dyn]));
- always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dyn, [dyn]));
- always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dyn, []));
- always(fnTypeFuzzy(int, [int], {extra: int}), fnTypeFuzzy(dyn, [dyn]));
-
- always(fnTypeFuzzy(dyn, [dyn]), fnTypeFuzzy(dyn, [dyn]));
- always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dyn, [], [dyn]));
- always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dyn, [dyn]));
- always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dyn, []));
- always(fnTypeFuzzy(dyn, [dyn], {extra: dyn}), fnTypeFuzzy(dyn, [dyn]));
- });
-
- test('void function types', () => {
- always(fnTypeFuzzy(int, [int]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dart.void, [], [dyn]));
- always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(int, [], [int]), fnTypeFuzzy(dart.void, []));
- always(fnTypeFuzzy(int, [int], {extra: int}), fnTypeFuzzy(dart.void, [dyn]));
-
- always(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dart.void, [], [dyn]));
- always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dart.void, []));
- always(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(dart.void, [dyn]));
-
- always(fnTypeFuzzy(dyn, [dyn]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dart.void, [], [dyn]));
- always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(dyn, [], [dyn]), fnTypeFuzzy(dart.void, []));
- always(fnTypeFuzzy(dyn, [dyn], {extra: dyn}), fnTypeFuzzy(dart.void, [dyn]));
-
- always(fnTypeFuzzy(dart.void, [dyn]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(dart.void, [], [dyn]), fnTypeFuzzy(dart.void, [], [dyn]));
- always(fnTypeFuzzy(dart.void, [], [dyn]), fnTypeFuzzy(dart.void, [dyn]));
- always(fnTypeFuzzy(dart.void, [], [dyn]), fnTypeFuzzy(dart.void, []));
- always(fnTypeFuzzy(dart.void, [dyn], {extra: dyn}), fnTypeFuzzy(dart.void, [dyn]));
-
- always(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(dyn, [dyn]));
- always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dyn, [], [dyn]));
- always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dyn, [dyn]));
- always(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(dyn, []));
- always(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(dyn, [dyn]));
-
- never(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(int, [dyn]));
- never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [], [dyn]));
- never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [dyn]));
- never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, []));
- never(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(int, [dyn]));
-
- never(fnTypeFuzzy(dart.void, [int]), fnTypeFuzzy(int, [int]));
- never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [], [int]));
- never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, [int]));
- never(fnTypeFuzzy(dart.void, [], [int]), fnTypeFuzzy(int, []));
- never(fnTypeFuzzy(dart.void, [int], {extra: int}), fnTypeFuzzy(int, [int]));
- });
-
- test('higher-order typedef', () => {
- let Func$ = dart.generic((S, T) =>
- dart.typedef('Func', () =>
- fnTypeFuzzy(T, [S])));
- let Func2$ = dart.generic((R, S, T) =>
- dart.typedef('Func2', () =>
- fnTypeFuzzy(T, [Func$(R, S)])));
-
- maybe(fnTypeFuzzy(int, [fnTypeFuzzy(int, [num])]),
- fnTypeFuzzy(num, [fnTypeFuzzy(int, [int])]));
- maybe(fnTypeFuzzy(int, [Func$(num, int)]),
- fnTypeFuzzy(num, [Func$(int, int)]));
- maybe(Func2$(num, int, int), Func2$(int, int, num));
- });
-
- test('mixed types', () => {
- let AA$ = dart.generic((T) => {
- class AA extends core.Object {}
- (AA.new = function() {}).prototype = AA.prototype;
- return AA;
- });
-
- always(int, dyn);
- maybe(dyn, int);
-
- never(fnTypeFuzzy(int, [int]), int);
-
- never(int, fnTypeFuzzy(int, [int]));
-
- always(AA$(int), AA$(dyn));
- maybe(AA$(dyn), AA$(int));
- never(AA$(core.Object), AA$(int));
-
- always(AA$(fnTypeFuzzy(int, [int])), AA$(dyn));
- maybe(AA$(dyn), AA$(fnTypeFuzzy(int, [int])));
- never(AA$(core.Object), AA$(fnTypeFuzzy(int, [int])));
-
- always(AA$(fnTypeFuzzy(int, [int])), AA$(fnTypeFuzzy(dyn, [dyn])));
- maybe(AA$(fnTypeFuzzy(dyn, [dyn])), AA$(fnTypeFuzzy(int, [int])));
- maybe(AA$(fnTypeFuzzy(core.Object, [core.Object])),
- AA$(fnTypeFuzzy(int, [int])));
- });
- });
-
- suite('canonicalization', function() {
- 'use strict';
- let fnTypeFuzzy = dart.fnTypeFuzzy;
- let fnType = dart.fnType;
- let typedef = dart.typedef;
- let generic = dart.generic;
-
- let Object = core.Object;
- let String = core.String;
- let int = core.int;
- let dynamic = dart.dynamic;
- let bottom = dart.bottom;
- let Map = core.Map;
- let Map$ = core.Map$;
-
- class A {}
-
- let AA$ = generic((T, U) => {
- class AA extends core.Object {}
- (AA.new = function() {}).prototype = AA.prototype;
- return AA;
- });
- let AA = AA$();
-
- let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic]));
-
- let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U])))
- let FuncG = FuncG$();
-
- test('base types', () => {
- assert.equal(Object, Object);
- assert.equal(String, String);
- assert.equal(dynamic, dynamic);
- });
-
- test('class types', () => {
- assert.equal(A, A);
- });
-
- test('generic class types', () => {
- assert.equal(AA, AA);
- assert.equal(AA, AA$(dynamic, dynamic));
- assert.equal(AA$(dynamic, dynamic), AA$(dynamic, dynamic));
- assert.equal(AA$(AA, Object), AA$(AA, Object));
- assert.equal(Map, Map);
- assert.equal(Map$(dynamic, dynamic), Map);
- assert.equal(Map$(int, Map$(int, int)), Map$(int, Map$(int, int)));
- });
-
- test('typedefs', () => {
- assert.equal(Func2, Func2);
- assert.equal(FuncG, FuncG$(dynamic, dynamic));
- assert.equal(FuncG$(dynamic, dynamic), FuncG$(dynamic, dynamic));
- assert.equal(FuncG$(String, Func2), FuncG$(String, Func2));
- });
-
- test('function types', () => {
- assert.equal(fnTypeFuzzy(dynamic, [dynamic, dynamic]),
- fnTypeFuzzy(dynamic, [dynamic, dynamic]))
-
- assert.notEqual(fnType(dynamic, [dynamic, dynamic]),
- fnTypeFuzzy(dynamic, [dynamic, dynamic]))
-
- assert.equal(fnTypeFuzzy(dynamic, [dynamic, dynamic]),
- fnTypeFuzzy(dynamic, [bottom, bottom]))
-
- assert.equal(fnTypeFuzzy(dynamic, [], [dynamic, dynamic]),
- fnTypeFuzzy(dynamic, [], [dynamic, dynamic]))
-
- assert.notEqual(fnType(dynamic, [], [dynamic, dynamic]),
- fnTypeFuzzy(dynamic, [], [dynamic, dynamic]))
-
- assert.equal(fnTypeFuzzy(dynamic, [], [dynamic, dynamic]),
- fnTypeFuzzy(dynamic, [], [bottom, bottom]))
-
- assert.equal(fnTypeFuzzy(dynamic, [], {extra: dynamic}),
- fnTypeFuzzy(dynamic, [], {extra: dynamic}))
-
- assert.notEqual(fnType(dynamic, [], {extra: dynamic}),
- fnTypeFuzzy(dynamic, [], {extra: dynamic}))
-
- assert.equal(fnTypeFuzzy(dynamic, [], {extra: dynamic}),
- fnTypeFuzzy(dynamic, [], {extra: bottom}))
-
- assert.equal(fnTypeFuzzy(int, [int, int]),
- fnTypeFuzzy(int, [int, int]))
-
- assert.equal(fnTypeFuzzy(int, [], [int, int]),
- fnTypeFuzzy(int, [], [int, int]))
-
- assert.equal(fnTypeFuzzy(int, [int, int], {extra: int}),
- fnTypeFuzzy(int, [int, int], {extra: int}))
-
- assert.equal(fnTypeFuzzy(int, [int, int, int, int, int]),
- fnTypeFuzzy(int, [int, int, int, int, int]))
-
- assert.notEqual(fnTypeFuzzy(int, [int, int, int, int, int]),
- fnTypeFuzzy(int, [int, int, int], [int, int]))
-
- assert.notEqual(fnTypeFuzzy(String, [int, int, int, int, int]),
- fnTypeFuzzy(int, [int, int, int, int, int]))
-
- assert.notEqual(fnTypeFuzzy(String, []),
- fnTypeFuzzy(int, []))
- });
- });
-
- suite('primitives', function() {
- 'use strict';
-
- test('fixed length list', () => {
- let list = core.List.new(10);
- list[0] = 42;
- assert.throws(() => list.add(42));
- });
-
- test('toString on ES Symbol', () => {
- let sym = Symbol('_foobar');
- assert.equal(dart.toString(sym), 'Symbol(_foobar)');
- });
- });
-});
diff --git a/pkg/dev_compiler/test/codegen/async_helper.dart b/pkg/dev_compiler/test/codegen/async_helper.dart
deleted file mode 100644
index 49e33ca..0000000
--- a/pkg/dev_compiler/test/codegen/async_helper.dart
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) 2013, 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.
-
-/// This library is used for testing asynchronous tests.
-/// If a test is asynchronous, it needs to notify the testing driver
-/// about this (otherwise tests may get reported as passing [after main()
-/// finished] even if the asynchronous operations fail).
-/// Tests which can't use the unittest framework should use the helper functions
-/// in this library.
-/// This library provides four methods
-/// - asyncStart(): Needs to be called before an asynchronous operation is
-/// scheduled.
-/// - asyncEnd(): Needs to be called as soon as the asynchronous operation
-/// ended.
-/// - asyncSuccess(_): Variant of asyncEnd useful together with Future.then.
-/// - asyncTest(f()): Helper method that wraps a computation that returns a
-/// Future with matching calls to asyncStart() and
-/// asyncSuccess(_).
-/// After the last asyncStart() called was matched with a corresponding
-/// asyncEnd() or asyncSuccess(_) call, the testing driver will be notified that
-/// the tests is done.
-
-library async_helper;
-
-bool _initialized = false;
-
-typedef void _Action0();
-_Action0 _onAsyncEnd;
-
-int _asyncLevel = 0;
-
-Exception _buildException(String msg) {
- return new Exception('Fatal: $msg. This is most likely a bug in your test.');
-}
-
-/// Implementation method called from language_tests.js.
-/// Registers the callback that will be used to complete the test.
-void asyncTestInitialize(_Action0 callback) {
- _asyncLevel = 0;
- _initialized = false;
- _onAsyncEnd = callback;
-}
-
-/// Implementation method called from language_tests.js.
-/// Returns true if an asyncTest was started.
-bool get asyncTestStarted => _initialized;
-
-/// Call this method before an asynchronous test is created.
-///
-/// If [count] is provided, expect [count] [asyncEnd] calls instead of just one.
-void asyncStart([int count = 1]) {
- if (count <= 0) return;
- if (_initialized && _asyncLevel == 0) {
- throw _buildException('asyncStart() was called even though we are done '
- 'with testing.');
- }
- if (!_initialized) {
- if (_onAsyncEnd == null) {
- throw _buildException(
- 'asyncStart() was called before asyncTestInitialize()');
- }
-
- print('unittest-suite-wait-for-done');
- _initialized = true;
- }
- _asyncLevel += count;
-}
-
-/// Call this after an asynchronous test has ended successfully.
-void asyncEnd() {
- if (_asyncLevel <= 0) {
- if (!_initialized) {
- throw _buildException('asyncEnd() was called before asyncStart().');
- } else {
- throw _buildException('asyncEnd() was called more often than '
- 'asyncStart().');
- }
- }
- _asyncLevel--;
- if (_asyncLevel == 0) {
- var callback = _onAsyncEnd;
- _onAsyncEnd = null;
- callback();
- print('unittest-suite-success');
- }
-}
-
-/**
- * Call this after an asynchronous test has ended successfully. This is a helper
- * for calling [asyncEnd].
- *
- * This method intentionally has a signature that matches [:Future.then:] as a
- * convenience for calling [asyncEnd] when a [:Future:] completes without error,
- * like this:
- *
- * asyncStart();
- * Future result = test();
- * result.then(asyncSuccess);
- */
-void asyncSuccess(_) => asyncEnd();
-
-/**
- * Helper method for performing asynchronous tests involving [:Future:].
- *
- * [f] must return a [:Future:] for the test computation.
- */
-void asyncTest(f()) {
- asyncStart();
- f().then(asyncSuccess);
-}
diff --git a/pkg/dev_compiler/test/codegen_expected/async_helper.js b/pkg/dev_compiler/test/codegen_expected/async_helper.js
deleted file mode 100644
index d3a0723..0000000
--- a/pkg/dev_compiler/test/codegen_expected/async_helper.js
+++ /dev/null
@@ -1,94 +0,0 @@
-define(['dart_sdk'], function(dart_sdk) {
- 'use strict';
- const core = dart_sdk.core;
- const dart = dart_sdk.dart;
- const dartx = dart_sdk.dartx;
- const _root = Object.create(null);
- const async_helper = Object.create(_root);
- let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.fnTypeFuzzy(dart.void, [])))();
- let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.fnTypeFuzzy(dart.dynamic, [])))();
- let StringToException = () => (StringToException = dart.constFn(dart.fnType(core.Exception, [core.String])))();
- let FnTovoid = () => (FnTovoid = dart.constFn(dart.fnType(dart.void, [VoidTovoid()])))();
- let VoidTovoid$ = () => (VoidTovoid$ = dart.constFn(dart.fnType(dart.void, [])))();
- let dynamicTovoid = () => (dynamicTovoid = dart.constFn(dart.fnType(dart.void, [dart.dynamic])))();
- let FnTovoid$ = () => (FnTovoid$ = dart.constFn(dart.fnType(dart.void, [VoidTodynamic()])))();
- dart.defineLazy(async_helper, {
- get _initialized() {
- return false;
- },
- set _initialized(_) {}
- });
- async_helper._Action0 = dart.typedef('_Action0', () => dart.fnTypeFuzzy(dart.void, []));
- dart.defineLazy(async_helper, {
- get _onAsyncEnd() {
- return null;
- },
- set _onAsyncEnd(_) {},
- get _asyncLevel() {
- return 0;
- },
- set _asyncLevel(_) {}
- });
- async_helper._buildException = function(msg) {
- return core.Exception.new(dart.str`Fatal: ${msg}. This is most likely a bug in your test.`);
- };
- dart.fn(async_helper._buildException, StringToException());
- async_helper.asyncTestInitialize = function(callback) {
- async_helper._asyncLevel = 0;
- async_helper._initialized = false;
- async_helper._onAsyncEnd = callback;
- };
- dart.fn(async_helper.asyncTestInitialize, FnTovoid());
- dart.copyProperties(async_helper, {
- get asyncTestStarted() {
- return async_helper._initialized;
- }
- });
- async_helper.asyncStart = function() {
- if (dart.test(async_helper._initialized) && async_helper._asyncLevel === 0) {
- dart.throw(async_helper._buildException('asyncStart() was called even though we are done ' + 'with testing.'));
- }
- if (!dart.test(async_helper._initialized)) {
- if (async_helper._onAsyncEnd == null) {
- dart.throw(async_helper._buildException('asyncStart() was called before asyncTestInitialize()'));
- }
- core.print('unittest-suite-wait-for-done');
- async_helper._initialized = true;
- }
- async_helper._asyncLevel = dart.notNull(async_helper._asyncLevel) + 1;
- };
- dart.fn(async_helper.asyncStart, VoidTovoid$());
- async_helper.asyncEnd = function() {
- if (dart.notNull(async_helper._asyncLevel) <= 0) {
- if (!dart.test(async_helper._initialized)) {
- dart.throw(async_helper._buildException('asyncEnd() was called before asyncStart().'));
- } else {
- dart.throw(async_helper._buildException('asyncEnd() was called more often than ' + 'asyncStart().'));
- }
- }
- async_helper._asyncLevel = dart.notNull(async_helper._asyncLevel) - 1;
- if (async_helper._asyncLevel === 0) {
- let callback = async_helper._onAsyncEnd;
- async_helper._onAsyncEnd = null;
- callback();
- core.print('unittest-suite-success');
- }
- };
- dart.fn(async_helper.asyncEnd, VoidTovoid$());
- async_helper.asyncSuccess = function(_) {
- return async_helper.asyncEnd();
- };
- dart.fn(async_helper.asyncSuccess, dynamicTovoid());
- async_helper.asyncTest = function(f) {
- async_helper.asyncStart();
- dart.dsend(f(), 'then', async_helper.asyncSuccess);
- };
- dart.fn(async_helper.asyncTest, FnTovoid$());
- dart.trackLibraries("async_helper", {
- "async_helper.dart": async_helper
- }, null);
- // Exports:
- return {
- async_helper: async_helper
- };
-});
diff --git a/pkg/dev_compiler/tool/build_pkgs.dart b/pkg/dev_compiler/tool/build_pkgs.dart
index c8b3bf12..91bea3a 100755
--- a/pkg/dev_compiler/tool/build_pkgs.dart
+++ b/pkg/dev_compiler/tool/build_pkgs.dart
@@ -134,7 +134,7 @@
/// Compiles a [module] with a single matching ".dart" library and additional
/// [libs] and [deps] on other modules.
Future compileModule(String module,
- {List<String> libs, List<String> deps}) async {
+ {List<String> libs = const [], List<String> deps = const []}) async {
if (analyzerSummary != null) compileModuleUsingAnalyzer(module, libs, deps);
if (kernelSummary != null) await compileKernelSummary(module, libs, deps);
}
@@ -143,35 +143,20 @@
String module, List<String> libraries, List<String> dependencies) {
var args = [
'--dart-sdk-summary=$analyzerSummary',
- '-o${pkgDirectory}/$module.js'
+ '-o${pkgDirectory}/$module.js',
+ // There is always a library that matches the module.
+ 'package:$module/$module.dart'
];
- // There is always a library that matches the module.
- args.add('package:$module/$module.dart');
-
// Add any additional libraries.
- if (libraries != null) {
- for (var lib in libraries) {
- args.add('package:$module/$lib.dart');
- }
+ for (var lib in libraries) {
+ args.add('package:$module/$lib.dart');
}
// Add summaries for any modules this depends on.
- if (dependencies != null) {
- for (var dep in dependencies) {
- args.add('-s${pkgDirectory}/$dep.sum');
- }
+ for (var dep in dependencies) {
+ args.add('-s${pkgDirectory}/$dep.sum');
}
-
- // TODO(rnystrom): Hack. DDC has its own forked copy of async_helper that
- // has a couple of differences from pkg/async_helper. We should unfork them,
- // but I'm not sure how they'll affect the other non-DDC tests. For now, just
- // use ours.
- if (module == 'async_helper') {
- args.add('--url-mapping=package:async_helper/async_helper.dart,' +
- p.join(scriptDirectory, "../test/codegen/async_helper.dart"));
- }
-
var exitCode = analyzer.compile(args);
if (exitCode != 0) exit(exitCode);
}
@@ -193,36 +178,20 @@
..reportMessages = true
..target = new DevCompilerTarget();
- var inputs = <Uri>[];
+ // There is always a library that matches the module.
+ var inputs = [Uri.parse("package:$module/$module.dart")];
- if (module == "async_helper") {
- // TODO(rnystrom): Hack. DDC has its own forked copy of async_helper that
- // has a couple of differences from pkg/async_helper. We should unfork them,
- // but I'm not sure how they'll affect the other non-DDC tests. For now,
- // just use ours.
- inputs.add(_uriInRepo("pkg/dev_compiler/test/codegen/async_helper.dart"));
- } else {
- // There is always a library that matches the module.
- inputs.add(Uri.parse("package:$module/$module.dart"));
-
- // Add any other libraries too.
- if (libraries != null) {
- for (var lib in libraries) {
- inputs.add(Uri.parse("package:$module/$lib.dart"));
- }
- }
+ // Add any other libraries too.
+ for (var lib in libraries) {
+ inputs.add(Uri.parse("package:$module/$lib.dart"));
}
// Add summaries for any modules this depends on.
- if (dependencies != null) {
- var uris = <Uri>[];
-
- for (var dep in dependencies) {
- uris.add(p.toUri(p.absolute(p.join(pkgDirectory, "$dep.dill"))));
- }
-
- options.inputSummaries = uris;
+ var uris = <Uri>[];
+ for (var dep in dependencies) {
+ uris.add(p.toUri(p.absolute(p.join(pkgDirectory, "$dep.dill"))));
}
+ options.inputSummaries = uris;
// Compile the summary.
var bytes = await summaryFor(inputs, options);
diff --git a/pkg/dev_compiler/tool/run.js b/pkg/dev_compiler/tool/run.js
deleted file mode 100644
index ec9eb24..0000000
--- a/pkg/dev_compiler/tool/run.js
+++ /dev/null
@@ -1,90 +0,0 @@
-// 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.
-
-/// This is a utility to run and debug an individual DDC compiled test.
-/// Tests can be run with either node or devtool (a Chrome-based utility with
-/// DOM APIs and developer tools support).
-///
-/// Install devtool via:
-/// > npm install -g devtool
-///
-/// Run via:
-/// > devtool tool/run.js -- corelib_2/apply2_test
-/// or
-/// > node tool/run.js corelib_2/apply2_test
-///
-/// See TODO below on async / unittest support.
-
-var args = process.argv.slice(2);
-if (args.length != 1) {
- throw new Error("Usage: devtool tool/run.js <test-module-name>");
-}
-var test = args[0];
-
-var requirejs = require('requirejs');
-var ddcdir = __dirname + '/../';
-requirejs.config({
- baseUrl: ddcdir + 'gen/codegen_output',
- paths: {
- dart_sdk: ddcdir + 'lib/js/amd/dart_sdk',
- async_helper: ddcdir + 'gen/codegen_output/pkg/async_helper',
- expect: ddcdir + 'gen/codegen_output/pkg/expect',
- js: ddcdir + 'gen/codegen_output/pkg/js',
- matcher: ddcdir + 'gen/codegen_output/pkg/matcher',
- minitest: ddcdir + 'gen/codegen_output/pkg/minitest',
- path: ddcdir + 'gen/codegen_output/pkg/path',
- stack_trace: ddcdir + 'gen/codegen_output/pkg/stack_trace',
- unittest: ddcdir + 'gen/codegen_output/pkg/unittest',
- }
-});
-
-// TODO(vsm): Factor out test framework code in test/browser/language_tests.js
-// and use here. Async tests and unittests won't work without it.
-var sdk = requirejs('dart_sdk');
-sdk.dart.ignoreWhitelistedErrors(false);
-
-let negative = /negative_test/.test(test);
-function finish(e) {
- if (negative) {
- if (e) {
- e = null;
- } else {
- e = new Error("test marked as 'negative' but did not throw");
- }
- }
- if (e) {
- console.log('Test ' + test + ' failed:\n' + e.toString());
- sdk.dart.stackPrint(e);
- } else {
- console.log('Test ' + test + ' passed.');
- }
-}
-
-sdk.dart.ignoreWhitelistedErrors(false);
-sdk._isolate_helper.startRootIsolate(() => {}, []);
-// Make it easier to debug test failures and required for formatter test that
-// assumes custom formatters are enabled.
-sdk._debugger.registerDevtoolsFormatter();
-
-var async_helper = requirejs('async_helper').async_helper;
-async_helper.asyncTestInitialize(finish);
-
-var module = requirejs(test);
-var lib = test.split('/').slice(-1)[0];
-try {
- if (module[lib]._expectRuntimeError) negative = true;
- var result = module[lib].main();
- // async_helper tests call finish directly - call here for all other
- // tests.
- if (!async_helper.asyncTestStarted) {
- if (!result || !(sdk.async.Future.is(result))) {
- finish();
- } else {
- // Wait iff result is a future
- result.then(sdk.dart.dynamic)(() => finish(), { onError: (e) => finish(e) });
- }
- }
-} catch (e) {
- finish(e);
-}
diff --git a/tools/testing/dart/browser_test.dart b/tools/testing/dart/browser_test.dart
index 4c2d536..4d60b05 100644
--- a/tools/testing/dart/browser_test.dart
+++ b/tools/testing/dart/browser_test.dart
@@ -86,9 +86,6 @@
requirejs(["$testName", "dart_sdk", "async_helper"],
function($testName, sdk, async_helper) {
sdk.dart.ignoreWhitelistedErrors(false);
- // TODO(rnystrom): This uses DDC's forked version of async_helper. Unfork
- // these packages when possible.
- async_helper.async_helper.asyncTestInitialize(function() {});
sdk._isolate_helper.startRootIsolate(function() {}, []);
sdk._debugger.registerDevtoolsFormatter();