Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Classes and methods for enumerating and preparing tests. | 6 * Classes and methods for enumerating and preparing tests. |
| 7 * | 7 * |
| 8 * This library includes: | 8 * This library includes: |
| 9 * | 9 * |
| 10 * - Creating tests by listing all the Dart files in certain directories, | 10 * - Creating tests by listing all the Dart files in certain directories, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 128 } |
| 129 | 129 |
| 130 if (expectations.contains(SKIP)) return; | 130 if (expectations.contains(SKIP)) return; |
| 131 | 131 |
| 132 // The cc test runner takes options after the name of the test | 132 // The cc test runner takes options after the name of the test |
| 133 // to run. | 133 // to run. |
| 134 var args = [testName]; | 134 var args = [testName]; |
| 135 args.addAll(TestUtils.standardOptions(configuration)); | 135 args.addAll(TestUtils.standardOptions(configuration)); |
| 136 | 136 |
| 137 doTest(new TestCase('$suiteName/$testName', | 137 doTest(new TestCase('$suiteName/$testName', |
| 138 runnerPath, | 138 [new Command(runnerPath, args)], |
| 139 args, | |
| 140 configuration, | 139 configuration, |
| 141 completeHandler, | 140 completeHandler, |
| 142 expectations)); | 141 expectations)); |
| 143 } | 142 } |
| 144 } | 143 } |
| 145 | 144 |
| 146 void forEachTest(Function onTest, Map testCache, String globalTempDir(), | 145 void forEachTest(Function onTest, Map testCache, String globalTempDir(), |
| 147 [Function onDone]) { | 146 [Function onDone]) { |
| 148 doTest = onTest; | 147 doTest = onTest; |
| 149 doDone = (ignore) => (onDone != null) ? onDone() : null; | 148 doDone = (ignore) => (onDone != null) ? onDone() : null; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 isNegative = false; | 355 isNegative = false; |
| 357 } | 356 } |
| 358 } | 357 } |
| 359 | 358 |
| 360 var argumentLists = argumentListsFromFile(filename, | 359 var argumentLists = argumentListsFromFile(filename, |
| 361 optionsFromFile, | 360 optionsFromFile, |
| 362 enableFatalTypeErrors); | 361 enableFatalTypeErrors); |
| 363 | 362 |
| 364 for (var args in argumentLists) { | 363 for (var args in argumentLists) { |
| 365 doTest(new TestCase('$suiteName/$testName', | 364 doTest(new TestCase('$suiteName/$testName', |
| 366 shellPath(), | 365 [new Command(shellPath(), args)], |
| 367 args, | |
| 368 configuration, | 366 configuration, |
| 369 completeHandler, | 367 completeHandler, |
| 370 expectations, | 368 expectations, |
| 371 isNegative)); | 369 isNegative)); |
| 372 } | 370 } |
| 373 } | 371 } |
| 374 } | 372 } |
| 375 | 373 |
| 376 Function makeTestCaseCreator(Map optionsFromFile) { | 374 Function makeTestCaseCreator(Map optionsFromFile) { |
| 377 return (String filename, | 375 return (String filename, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 // with 'C:' adding 'file:///' solves the problem. | 505 // with 'C:' adding 'file:///' solves the problem. |
| 508 filePrefix = 'file:///'; | 506 filePrefix = 'file:///'; |
| 509 } | 507 } |
| 510 htmlTest.writeStringSync(GetHtmlContents( | 508 htmlTest.writeStringSync(GetHtmlContents( |
| 511 filename, | 509 filename, |
| 512 '$filePrefix$dartDir/client/testing/unittest/test_controller.js', | 510 '$filePrefix$dartDir/client/testing/unittest/test_controller.js', |
| 513 scriptType, | 511 scriptType, |
| 514 filePrefix + scriptPath)); | 512 filePrefix + scriptPath)); |
| 515 htmlTest.closeSync(); | 513 htmlTest.closeSync(); |
| 516 | 514 |
| 517 List<String> compilerArgs = TestUtils.standardOptions(configuration); | 515 // Construct the command(s) that compile all the inputs needed by the |
| 518 String compilerExecutable = TestUtils.compilerPath(configuration); | 516 // browser test. For dartium, this will be noop commands. |
| 519 switch (component) { | 517 List<Command> commands = [_compileCommand( |
| 520 case 'chromium': | 518 dartWrapperFilename, compiledDartWrapperFilename, |
| 521 compilerArgs.addAll(['--work', tempDir.path]); | 519 component, tempDir.path, vmOptions)]; |
| 522 compilerArgs.addAll(vmOptions); | 520 |
| 523 compilerArgs.add('--ignore-unrecognized-flags'); | 521 // some tests require compiling multiple input scripts. |
| 524 // TODO(zundel): remove assumption of generated code from dartc | 522 List<String> otherScripts = optionsFromFile['otherScripts']; |
| 525 compilerArgs.add('--out'); | 523 for (String name in otherScripts) { |
| 526 compilerArgs.add(compiledDartWrapperFilename); | 524 int end = filename.lastIndexOf('/'); |
| 527 compilerArgs.add(dartWrapperFilename); | 525 Expect.isTrue(end > 0); |
|
Bill Hesse
2012/02/28 16:41:56
Could we print a warning, and just return without
Siggi Cherem (dart-lang)
2012/02/28 17:42:37
Good point. Fixed.
| |
| 528 // TODO(whesse): Add --fatal-type-errors if needed. | 526 String dir = filename.substring(0, end); |
| 529 break; | 527 end = name.lastIndexOf('.dart'); |
| 530 case 'frogium': | 528 Expect.isTrue(end > 0); |
| 531 case 'webdriver': | 529 String compiledName = '${name.substring(0, end)}.js'; |
| 532 String libdir = configuration['froglib']; | 530 commands.add(_compileCommand( |
| 533 if (libdir == '') { | 531 '$dir/$name', '${tempDir.path}/$compiledName', |
| 534 libdir = '$dartDir/frog/lib'; | 532 component, tempDir.path, vmOptions)); |
| 535 } | |
| 536 compilerArgs.addAll(['--libdir=$libdir', | |
| 537 '--compile-only', | |
| 538 '--out=$compiledDartWrapperFilename']); | |
| 539 compilerArgs.addAll(vmOptions); | |
| 540 compilerArgs.add(dartWrapperFilename); | |
| 541 break; | |
| 542 case 'dartium': | |
| 543 // No compilation phase. | |
| 544 compilerExecutable = null; | |
| 545 compilerArgs = null; | |
| 546 break; | |
| 547 default: | |
| 548 Expect.fail('unimplemented component $component'); | |
| 549 } | 533 } |
| 550 | 534 |
| 535 // Construct the command that executes the browser test | |
| 551 List<String> args; | 536 List<String> args; |
| 552 if (component == 'webdriver') { | 537 if (component == 'webdriver') { |
| 553 args = ['$dartDir/tools/testing/run_selenium.py', | 538 args = ['$dartDir/tools/testing/run_selenium.py', |
| 554 '--browser=${configuration["browser"]}', | 539 '--browser=${configuration["browser"]}', |
| 555 '--timeout=${configuration["timeout"] - 2}', | 540 '--timeout=${configuration["timeout"] - 2}', |
| 556 '--out=$htmlPath']; | 541 '--out=$htmlPath']; |
| 557 } else { | 542 } else { |
| 558 args = [ | 543 args = [ |
| 559 '$dartDir/tools/testing/drt-trampoline.py', | 544 '$dartDir/tools/testing/drt-trampoline.py', |
| 560 dumpRenderTreeFilename, | 545 dumpRenderTreeFilename, |
| 561 '--no-timeout' | 546 '--no-timeout' |
| 562 ]; | 547 ]; |
| 563 if (component == 'dartium') { | 548 if (component == 'dartium') { |
| 564 var dartFlags = ['--ignore-unrecognized-flags']; | 549 var dartFlags = ['--ignore-unrecognized-flags']; |
| 565 if (configuration["checked"]) { | 550 if (configuration["checked"]) { |
| 566 dartFlags.add('--enable_asserts'); | 551 dartFlags.add('--enable_asserts'); |
| 567 dartFlags.add("--enable_type_checks"); | 552 dartFlags.add("--enable_type_checks"); |
| 568 } | 553 } |
| 569 dartFlags.addAll(vmOptions); | 554 dartFlags.addAll(vmOptions); |
| 570 args.add('--dart-flags=${Strings.join(dartFlags, " ")}'); | 555 args.add('--dart-flags=${Strings.join(dartFlags, " ")}'); |
| 571 } | 556 } |
| 572 args.add(htmlPath); | 557 args.add(htmlPath); |
| 573 } | 558 } |
| 559 commands.add(new Command('python', args)); | |
| 560 | |
| 574 // Create BrowserTestCase and queue it. | 561 // Create BrowserTestCase and queue it. |
| 575 var testCase = new BrowserTestCase( | 562 var testCase = new BrowserTestCase(testName, commands, configuration, |
| 576 testName, | 563 completeHandler, expectations, optionsFromFile['isNegative']); |
| 577 compilerExecutable, | |
| 578 compilerArgs, | |
| 579 'python', | |
| 580 args, | |
| 581 configuration, | |
| 582 completeHandler, | |
| 583 expectations, | |
| 584 optionsFromFile['isNegative']); | |
| 585 doTest(testCase); | 564 doTest(testCase); |
| 586 } | 565 } |
| 587 } | 566 } |
| 588 | 567 |
| 568 /** Helper to create a compilation command for a single input file. */ | |
| 569 Command _compileCommand(String inputFile, String outputFile, | |
| 570 String component, String dir, var vmOptions) { | |
| 571 String executable = TestUtils.compilerPath(configuration); | |
| 572 List<String> args = TestUtils.standardOptions(configuration); | |
| 573 switch (component) { | |
| 574 case 'chromium': | |
| 575 args.addAll(['--work', dir]); | |
| 576 args.addAll(vmOptions); | |
| 577 args.add('--ignore-unrecognized-flags'); | |
| 578 // TODO(zundel): remove assumption of generated code from dartc | |
| 579 args.add('--out'); | |
| 580 args.add(outputFile); | |
| 581 args.add(inputFile); | |
| 582 // TODO(whesse): Add --fatal-type-errors if needed. | |
| 583 break; | |
| 584 case 'frogium': | |
| 585 case 'webdriver': | |
| 586 String libdir = configuration['froglib']; | |
| 587 if (libdir == '') { | |
| 588 libdir = '$dartDir/frog/lib'; | |
| 589 } | |
| 590 args.addAll(['--libdir=$libdir', | |
| 591 '--compile-only', | |
| 592 '--out=$outputFile']); | |
| 593 args.addAll(vmOptions); | |
| 594 args.add(inputFile); | |
| 595 break; | |
| 596 case 'dartium': | |
| 597 // No compilation phase. | |
| 598 args = null; | |
| 599 break; | |
| 600 default: | |
| 601 Expect.fail('unimplemented component $component'); | |
| 602 } | |
| 603 return new Command(executable, args); | |
| 604 } | |
| 605 | |
| 589 bool get requiresCleanTemporaryDirectory() => | 606 bool get requiresCleanTemporaryDirectory() => |
| 590 configuration['component'] == 'dartc' || | 607 configuration['component'] == 'dartc' || |
| 591 configuration['component'] == 'chromium'; | 608 configuration['component'] == 'chromium'; |
| 592 | 609 |
| 593 /** | 610 /** |
| 594 * Create a directory for the generated test. If a Dart language test | 611 * Create a directory for the generated test. If a Dart language test |
| 595 * needs to be run in a browser, the Dart test needs to be embedded in | 612 * needs to be run in a browser, the Dart test needs to be embedded in |
| 596 * an HTML page, with a testing framework based on scripting and DOM events. | 613 * an HTML page, with a testing framework based on scripting and DOM events. |
| 597 * These scripts and pages are written to a generated_test directory, | 614 * These scripts and pages are written to a generated_test directory, |
| 598 * usually inside the build directory of the checkout. | 615 * usually inside the build directory of the checkout. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 options.addAll(args); | 761 options.addAll(args); |
| 745 result.add(options); | 762 result.add(options); |
| 746 } | 763 } |
| 747 | 764 |
| 748 return result; | 765 return result; |
| 749 } | 766 } |
| 750 | 767 |
| 751 Map optionsFromFile(String filename) { | 768 Map optionsFromFile(String filename) { |
| 752 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)"); | 769 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)"); |
| 753 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)"); | 770 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)"); |
| 771 RegExp otherScriptsRegExp = const RegExp(@"// OtherScripts=(.*)"); | |
| 754 RegExp multiTestRegExp = const RegExp(@"/// [0-9][0-9]:(.*)"); | 772 RegExp multiTestRegExp = const RegExp(@"/// [0-9][0-9]:(.*)"); |
| 755 RegExp leadingHashRegExp = const RegExp(@"^#", multiLine: true); | 773 RegExp leadingHashRegExp = const RegExp(@"^#", multiLine: true); |
| 756 RegExp isolateStubsRegExp = const RegExp(@"// IsolateStubs=(.*)"); | 774 RegExp isolateStubsRegExp = const RegExp(@"// IsolateStubs=(.*)"); |
| 757 RegExp domImportRegExp = | 775 RegExp domImportRegExp = |
| 758 const RegExp(@"^#import.*(dart:(dom|html)|html\.dart).*\)", | 776 const RegExp(@"^#import.*(dart:(dom|html)|html\.dart).*\)", |
| 759 multiLine: true); | 777 multiLine: true); |
| 760 RegExp libraryDefinitionRegExp = | 778 RegExp libraryDefinitionRegExp = |
| 761 const RegExp(@"^#library\(", multiLine: true); | 779 const RegExp(@"^#library\(", multiLine: true); |
| 762 RegExp sourceOrImportRegExp = | 780 RegExp sourceOrImportRegExp = |
| 763 const RegExp(@"^#(source|import)\(", multiLine: true); | 781 const RegExp(@"^#(source|import)\(", multiLine: true); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 788 | 806 |
| 789 matches = dartOptionsRegExp.allMatches(contents); | 807 matches = dartOptionsRegExp.allMatches(contents); |
| 790 for (var match in matches) { | 808 for (var match in matches) { |
| 791 if (dartOptions != null) { | 809 if (dartOptions != null) { |
| 792 throw new Exception( | 810 throw new Exception( |
| 793 'More than one "// DartOptions=" line in test $filename'); | 811 'More than one "// DartOptions=" line in test $filename'); |
| 794 } | 812 } |
| 795 dartOptions = match[1].split(' ').filter((e) => e != ''); | 813 dartOptions = match[1].split(' ').filter((e) => e != ''); |
| 796 } | 814 } |
| 797 | 815 |
| 816 List<String> otherScripts = new List<String>(); | |
| 817 matches = otherScriptsRegExp.allMatches(contents); | |
| 818 for (var match in matches) { | |
| 819 otherScripts.addAll(match[1].split(' ').filter((e) => e != '')); | |
| 820 } | |
| 821 | |
| 798 if (contents.contains("@compile-error") || | 822 if (contents.contains("@compile-error") || |
| 799 contents.contains("@runtime-error")) { | 823 contents.contains("@runtime-error")) { |
| 800 isNegative = true; | 824 isNegative = true; |
| 801 } | 825 } |
| 802 | 826 |
| 803 bool isMultitest = multiTestRegExp.hasMatch(contents); | 827 bool isMultitest = multiTestRegExp.hasMatch(contents); |
| 804 bool containsLeadingHash = leadingHashRegExp.hasMatch(contents); | 828 bool containsLeadingHash = leadingHashRegExp.hasMatch(contents); |
| 805 Match isolateMatch = isolateStubsRegExp.firstMatch(contents); | 829 Match isolateMatch = isolateStubsRegExp.firstMatch(contents); |
| 806 String isolateStubs = isolateMatch != null ? isolateMatch[1] : ''; | 830 String isolateStubs = isolateMatch != null ? isolateMatch[1] : ''; |
| 807 bool containsDomImport = domImportRegExp.hasMatch(contents); | 831 bool containsDomImport = domImportRegExp.hasMatch(contents); |
| 808 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents); | 832 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents); |
| 809 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents); | 833 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents); |
| 810 | 834 |
| 811 | 835 |
| 812 return { "vmOptions": result, | 836 return { "vmOptions": result, |
| 813 "dartOptions": dartOptions, | 837 "dartOptions": dartOptions, |
| 814 "isNegative": isNegative, | 838 "isNegative": isNegative, |
| 839 "otherScripts": otherScripts, | |
| 815 "isMultitest": isMultitest, | 840 "isMultitest": isMultitest, |
| 816 "containsLeadingHash" : containsLeadingHash, | 841 "containsLeadingHash" : containsLeadingHash, |
| 817 "isolateStubs" : isolateStubs, | 842 "isolateStubs" : isolateStubs, |
| 818 "containsDomImport": containsDomImport, | 843 "containsDomImport": containsDomImport, |
| 819 "isLibraryDefinition": isLibraryDefinition, | 844 "isLibraryDefinition": isLibraryDefinition, |
| 820 "containsSourceOrImport": containsSourceOrImport }; | 845 "containsSourceOrImport": containsSourceOrImport }; |
| 821 } | 846 } |
| 822 } | 847 } |
| 823 | 848 |
| 824 | 849 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 956 List<String> args = <String>[ | 981 List<String> args = <String>[ |
| 957 '-ea', | 982 '-ea', |
| 958 '-classpath', classPath, | 983 '-classpath', classPath, |
| 959 '-Dcom.google.dart.runner.d8=$d8', | 984 '-Dcom.google.dart.runner.d8=$d8', |
| 960 '-Dcom.google.dart.corelib.SharedTests.test_py=' + | 985 '-Dcom.google.dart.corelib.SharedTests.test_py=' + |
| 961 dartDir + '/tools/test.py', | 986 dartDir + '/tools/test.py', |
| 962 'org.junit.runner.JUnitCore']; | 987 'org.junit.runner.JUnitCore']; |
| 963 args.addAll(testClasses); | 988 args.addAll(testClasses); |
| 964 | 989 |
| 965 doTest(new TestCase(suiteName, | 990 doTest(new TestCase(suiteName, |
| 966 'java', | 991 [new Command('java', args)], |
| 967 args, | |
| 968 configuration, | 992 configuration, |
| 969 completeHandler, | 993 completeHandler, |
| 970 new Set<String>.from([PASS]))); | 994 new Set<String>.from([PASS]))); |
| 971 doDone(); | 995 doDone(); |
| 972 } | 996 } |
| 973 | 997 |
| 974 void completeHandler(TestCase testCase) { | 998 void completeHandler(TestCase testCase) { |
| 975 } | 999 } |
| 976 | 1000 |
| 977 void computeClassPath() { | 1001 void computeClassPath() { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1142 * $noCrash tests are expected to be flaky but not crash | 1166 * $noCrash tests are expected to be flaky but not crash |
| 1143 * $pass tests are expected to pass | 1167 * $pass tests are expected to pass |
| 1144 * $failOk tests are expected to fail that we won't fix | 1168 * $failOk tests are expected to fail that we won't fix |
| 1145 * $fail tests are expected to fail that we should fix | 1169 * $fail tests are expected to fail that we should fix |
| 1146 * $crash tests are expected to crash that we should fix | 1170 * $crash tests are expected to crash that we should fix |
| 1147 * $timeout tests are allowed to timeout | 1171 * $timeout tests are allowed to timeout |
| 1148 """; | 1172 """; |
| 1149 print(report); | 1173 print(report); |
| 1150 } | 1174 } |
| 1151 } | 1175 } |
| OLD | NEW |