| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 (function() { | 5 (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 let dart_sdk = dart_library.import('dart_sdk'); | 8 let dart_sdk = dart_library.import('dart_sdk'); |
| 9 dart_sdk._isolate_helper.startRootIsolate(function() {}, []); | 9 dart_sdk._isolate_helper.startRootIsolate(function() {}, []); |
| 10 let async_helper = dart_library.import('async_helper').async_helper; | 10 let async_helper = dart_library.import('async_helper').async_helper; |
| 11 let unittest = dart_library.import('unittest'); | 11 let unittest = dart_library.import('unittest'); |
| 12 let html_config = unittest.html_config; | 12 let html_config = unittest.html_config; |
| 13 // Test attributes are a list of strings, or a string for a single | 13 // Test attributes are a list of strings, or a string for a single |
| 14 // attribute. Valid attribues are: | 14 // attribute. Valid attribues are: |
| 15 // | 15 // |
| 16 // 'skip' - don't run the test | 16 // 'skip' - don't run the test |
| 17 // 'fail' - test fails | 17 // 'fail' - test fails |
| 18 // 'timeout' - test times out | 18 // 'timeout' - test times out |
| 19 // 'slow' - use 5s timeout instead of default 2s. | 19 // 'slow' - use 5s timeout instead of default 2s. |
| 20 // 'helper' - not a test, used by other tests. | 20 // 'helper' - not a test, used by other tests. |
| 21 // 'unittest' - run separately as a unittest test. | 21 // 'unittest' - run separately as a unittest test. |
| 22 // | 22 // |
| 23 // Common combinations: | 23 // Common combinations: |
| 24 const fail = 'fail'; | 24 const fail = 'fail'; |
| 25 const skip_fail = ['skip', 'fail']; | 25 const skip_fail = ['skip', 'fail']; |
| 26 const skip_timeout = ['skip', 'timeout']; | 26 const skip_timeout = ['skip', 'timeout']; |
| 27 | 27 |
| 28 // The number of expected unittest errors should be zero but unfortunately | 28 // The number of expected unittest errors should be zero but unfortunately |
| 29 // there are a lot of broken html unittests. | 29 // there are a lot of broken html unittests. |
| 30 let num_expected_unittest_errors = 5; | 30 let num_expected_unittest_fails = 3; |
| 31 let num_expected_unittest_errors = 2; |
| 31 | 32 |
| 32 // TODO(jmesserly): separate StrongModeError from other errors. | 33 // TODO(jmesserly): separate StrongModeError from other errors. |
| 33 let all_status = { | 34 let all_status = { |
| 34 'language': { | 35 'language': { |
| 35 'arithmetic2_test': fail, | 36 'arithmetic2_test': fail, |
| 36 'assert_with_type_test_or_cast_test': skip_fail, | 37 'assert_with_type_test_or_cast_test': skip_fail, |
| 37 'assertion_test': skip_fail, | 38 'assertion_test': skip_fail, |
| 38 'async_await_test_none_multi': 'unittest', | 39 'async_await_test_none_multi': 'unittest', |
| 39 'async_star_await_pauses_test': skip_fail, | 40 'async_star_await_pauses_test': skip_fail, |
| 40 | 41 |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // you increase the time by a large amount, but it's pretty gratuitous. | 467 // you increase the time by a large amount, but it's pretty gratuitous. |
| 467 // I'm not sure why they are so slow. One guess is that they are spewing | 468 // I'm not sure why they are so slow. One guess is that they are spewing |
| 468 // a ton of warnings, that slow down the test. | 469 // a ton of warnings, that slow down the test. |
| 469 'chunked_conversion_utf84_test': skip_timeout, | 470 'chunked_conversion_utf84_test': skip_timeout, |
| 470 'chunked_conversion_utf88_test': skip_timeout, | 471 'chunked_conversion_utf88_test': skip_timeout, |
| 471 'chunked_conversion_utf8_test': skip_timeout, | 472 'chunked_conversion_utf8_test': skip_timeout, |
| 472 | 473 |
| 473 // TODO(rnystrom): Strong mode cast failures. | 474 // TODO(rnystrom): Strong mode cast failures. |
| 474 'codec1_test': skip_fail, | 475 'codec1_test': skip_fail, |
| 475 'encoding_test': skip_fail, | 476 'encoding_test': skip_fail, |
| 477 'html_escape_test': fail, |
| 476 | 478 |
| 477 // TODO(rnystrom): If this test is enabled, karma gets confused and | 479 // TODO(rnystrom): If this test is enabled, karma gets confused and |
| 478 // disconnects randomly. | 480 // disconnects randomly. |
| 479 'json_lib_test': skip_fail, | 481 'json_lib_test': skip_fail, |
| 480 | 482 |
| 481 'json_utf8_chunk_test': skip_timeout, | 483 'json_utf8_chunk_test': skip_timeout, |
| 482 | 484 |
| 483 // TODO(rnystrom): Strong mode cast failure. | 485 // TODO(rnystrom): Strong mode cast failure. |
| 484 'line_splitter_test': skip_fail, | 486 'line_splitter_test': skip_fail, |
| 485 | 487 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 // TODO(vsm): List.toString is different in DDC | 667 // TODO(vsm): List.toString is different in DDC |
| 666 // https://github.com/dart-lang/dev_compiler/issues/445 | 668 // https://github.com/dart-lang/dev_compiler/issues/445 |
| 667 'setRange_1_test': skip_fail, | 669 'setRange_1_test': skip_fail, |
| 668 'setRange_2_test': skip_fail, | 670 'setRange_2_test': skip_fail, |
| 669 'setRange_3_test': skip_fail, | 671 'setRange_3_test': skip_fail, |
| 670 'setRange_4_test': skip_fail, | 672 'setRange_4_test': skip_fail, |
| 671 'setRange_5_test': skip_fail, | 673 'setRange_5_test': skip_fail, |
| 672 }, | 674 }, |
| 673 }; | 675 }; |
| 674 | 676 |
| 677 function countMatches(text, regex) { |
| 678 let matches = text.match(regex); |
| 679 return matches ? matches.length : 0; |
| 680 } |
| 681 |
| 675 let unittest_tests = []; | 682 let unittest_tests = []; |
| 676 | 683 |
| 677 let languageTestPattern = new RegExp('(.*)/([^/]*_test[^/]*)'); | 684 let languageTestPattern = new RegExp('(.*)/([^/]*_test[^/]*)'); |
| 678 html_config.useHtmlConfiguration(); | 685 html_config.useHtmlConfiguration(); |
| 679 // We need to let Dart unittest control when tests are run not mocha. | 686 // We need to let Dart unittest control when tests are run not mocha. |
| 680 // mocha.allowUncaught(true); | 687 // mocha.allowUncaught(true); |
| 681 let dartUnittestsLeft = 0; | 688 let dartUnittestsLeft = 0; |
| 682 for (let testFile of dart_library.libraries()) { | 689 for (let testFile of dart_library.libraries()) { |
| 683 let match = languageTestPattern.exec(testFile); | 690 let match = languageTestPattern.exec(testFile); |
| 684 if (match != null) { | 691 if (match != null) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 }); | 767 }); |
| 761 } | 768 } |
| 762 } | 769 } |
| 763 | 770 |
| 764 let mochaOnError; | 771 let mochaOnError; |
| 765 // We run these tests in a mocha test wrapper to avoid the confusing failure | 772 // We run these tests in a mocha test wrapper to avoid the confusing failure |
| 766 // case of dart unittests being interleaved with mocha tests. | 773 // case of dart unittests being interleaved with mocha tests. |
| 767 // In practice we are really just suppressing all mocha test behavior while | 774 // In practice we are really just suppressing all mocha test behavior while |
| 768 // Dart unittests run and then re-enabling it when the dart tests complete. | 775 // Dart unittests run and then re-enabling it when the dart tests complete. |
| 769 test('run all dart unittests', function(done) { // 'function' to allow `this.t
imeout` | 776 test('run all dart unittests', function(done) { // 'function' to allow `this.t
imeout` |
| 777 this.timeout(100000000); |
| 770 this.enableTimeouts(false); | 778 this.enableTimeouts(false); |
| 771 // Suppress mocha on-error handling because it will mess up unittests. | 779 // Suppress mocha on-error handling because it will mess up unittests. |
| 772 mochaOnError = window.onerror; | 780 mochaOnError = window.onerror; |
| 773 window.onerror = function(err, url, line) { | 781 window.onerror = function(err, url, line) { |
| 774 console.error(err, url, line); | 782 console.error(err, url, line); |
| 775 }; | 783 }; |
| 776 window.addEventListener('message', (event) => { | 784 window.addEventListener('message', (event) => { |
| 777 if (event.data == 'unittest-suite-done') { | 785 if (event.data == 'unittest-suite-done') { |
| 778 window.console.log("Done running unittests"); | 786 window.console.log("Done running unittests"); |
| 779 let output = document.body.textContent; | 787 let output = document.body.textContent; |
| 780 // Restore the Mocha onerror handler in case future tests need to run. | 788 // Restore the Mocha onerror handler in case future tests need to run. |
| 781 window.onerror = mochaOnError; | 789 window.onerror = mochaOnError; |
| 782 this.enableTimeouts(true); | 790 this.enableTimeouts(true); |
| 783 | 791 |
| 784 var matches = output.match(/ERROR/g); | 792 let numErrors = countMatches(output, /\d\s+ERROR/g); |
| 785 let numErrors = matches ? matches.length : 0; | 793 let numFails = countMatches(output, /\d\s+FAIL/g); |
| 786 if (numErrors != num_expected_unittest_errors) { | 794 if (numErrors != num_expected_unittest_errors || |
| 787 output = "Expected " + num_expected_unittest_errors + | 795 numFails != num_expected_unittest_fails) { |
| 788 " failing unittests, got " + numErrors + ".\n" + output; | 796 output = "Expected " + num_expected_unittest_fails + |
| 797 " fail and " + num_expected_unittest_errors + |
| 798 " error unittests, got " + numFails + " fail and " + |
| 799 numErrors + "error tests.\n" + output; |
| 789 console.error(output); | 800 console.error(output); |
| 790 done(new Error(output)); | 801 done(new Error(output)); |
| 791 } else { | 802 } else { |
| 792 console.log(output); | 803 console.log(output); |
| 793 done(); | 804 done(); |
| 794 } | 805 } |
| 795 } | 806 } |
| 796 }); | 807 }); |
| 797 | 808 |
| 798 for (let action of unittest_tests) { | 809 for (let action of unittest_tests) { |
| 799 try { | 810 try { |
| 800 action(); | 811 action(); |
| 801 } catch (e) { | 812 } catch (e) { |
| 802 console.error("Caught error tying to setup test:", e); | 813 console.error("Caught error tying to setup test:", e); |
| 803 } | 814 } |
| 804 } | 815 } |
| 805 }); | 816 }); |
| 806 })(); | 817 })(); |
| OLD | NEW |