Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: tools/testing/dart/test_suite.dart

Issue 9475038: test.dart: add support for compiling multiple scripts for a single test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/testing/dart/test_runner.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 if (expectations.contains(SKIP)) return; 128 if (expectations.contains(SKIP)) return;
129 129
130 // The cc test runner takes options after the name of the test 130 // The cc test runner takes options after the name of the test
131 // to run. 131 // to run.
132 var args = [testName]; 132 var args = [testName];
133 args.addAll(TestUtils.standardOptions(configuration)); 133 args.addAll(TestUtils.standardOptions(configuration));
134 134
135 doTest(new TestCase('$suiteName/$testName', 135 doTest(new TestCase('$suiteName/$testName',
136 runnerPath, 136 [new Command(runnerPath, args)],
137 args,
138 configuration, 137 configuration,
139 completeHandler, 138 completeHandler,
140 expectations)); 139 expectations));
141 } 140 }
142 } 141 }
143 142
144 void forEachTest(Function onTest, Map testCache, String globalTempDir(), 143 void forEachTest(Function onTest, Map testCache, String globalTempDir(),
145 [Function onDone]) { 144 [Function onDone]) {
146 doTest = onTest; 145 doTest = onTest;
147 doDone = (ignore) => (onDone != null) ? onDone() : null; 146 doDone = (ignore) => (onDone != null) ? onDone() : null;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 isNegative = false; 353 isNegative = false;
355 } 354 }
356 } 355 }
357 356
358 var argumentLists = argumentListsFromFile(filename, 357 var argumentLists = argumentListsFromFile(filename,
359 optionsFromFile, 358 optionsFromFile,
360 enableFatalTypeErrors); 359 enableFatalTypeErrors);
361 360
362 for (var args in argumentLists) { 361 for (var args in argumentLists) {
363 doTest(new TestCase('$suiteName/$testName', 362 doTest(new TestCase('$suiteName/$testName',
364 shellPath(), 363 [new Command(shellPath(), args)],
365 args,
366 configuration, 364 configuration,
367 completeHandler, 365 completeHandler,
368 expectations, 366 expectations,
369 isNegative)); 367 isNegative));
370 } 368 }
371 } 369 }
372 } 370 }
373 371
374 Function makeTestCaseCreator(Map optionsFromFile) { 372 Function makeTestCaseCreator(Map optionsFromFile) {
375 return (String filename, 373 return (String filename,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // with 'C:' adding 'file:///' solves the problem. 503 // with 'C:' adding 'file:///' solves the problem.
506 filePrefix = 'file:///'; 504 filePrefix = 'file:///';
507 } 505 }
508 htmlTest.writeStringSync(GetHtmlContents( 506 htmlTest.writeStringSync(GetHtmlContents(
509 filename, 507 filename,
510 '$filePrefix$dartDir/client/testing/unittest/test_controller.js', 508 '$filePrefix$dartDir/client/testing/unittest/test_controller.js',
511 scriptType, 509 scriptType,
512 filePrefix + scriptPath)); 510 filePrefix + scriptPath));
513 htmlTest.closeSync(); 511 htmlTest.closeSync();
514 512
515 List<String> compilerArgs = TestUtils.standardOptions(configuration); 513 // Construct the command(s) that compile all the inputs needed by the
516 String compilerExecutable = TestUtils.compilerPath(configuration); 514 // browser test. For dartium, this will be noop commands.
517 switch (component) { 515 List<Command> commands = [_compileCommand(
518 case 'chromium': 516 dartWrapperFilename, compiledDartWrapperFilename,
519 compilerArgs.addAll(['--work', tempDir.path]); 517 component, tempDir.path, vmOptions)];
520 compilerArgs.addAll(vmOptions); 518
521 compilerArgs.add('--ignore-unrecognized-flags'); 519 // some tests require compiling multiple input scripts.
522 // TODO(zundel): remove assumption of generated code from dartc 520 List<String> otherScripts = optionsFromFile['otherScripts'];
523 compilerArgs.add('--out'); 521 for (String name in otherScripts) {
524 compilerArgs.add(compiledDartWrapperFilename); 522 int end = filename.lastIndexOf('/');
525 compilerArgs.add(dartWrapperFilename); 523 if (end == -1) {
526 // TODO(whesse): Add --fatal-type-errors if needed. 524 print('Warning: error processing "OtherScripts" of $filename.');
527 break; 525 print('Skipping test ($testName).');
528 case 'frogium': 526 return;
529 case 'webdriver': 527 }
530 String libdir = configuration['froglib']; 528 String dir = filename.substring(0, end);
531 if (libdir == '') { 529 end = name.lastIndexOf('.dart');
532 libdir = '$dartDir/frog/lib'; 530 if (end == -1) {
533 } 531 print('Warning: error processing "OtherScripts" in $filename.');
534 compilerArgs.addAll(['--libdir=$libdir', 532 print('Skipping test ($testName).');
535 '--compile-only', 533 return;
536 '--out=$compiledDartWrapperFilename']); 534 }
537 compilerArgs.addAll(vmOptions); 535 String compiledName = '${name.substring(0, end)}.js';
538 compilerArgs.add(dartWrapperFilename); 536 commands.add(_compileCommand(
539 break; 537 '$dir/$name', '${tempDir.path}/$compiledName',
540 case 'dartium': 538 component, tempDir.path, vmOptions));
541 // No compilation phase.
542 compilerExecutable = null;
543 compilerArgs = null;
544 break;
545 default:
546 Expect.fail('unimplemented component $component');
547 } 539 }
548 540
541 // Construct the command that executes the browser test
549 List<String> args; 542 List<String> args;
550 if (component == 'webdriver') { 543 if (component == 'webdriver') {
551 args = ['$dartDir/tools/testing/run_selenium.py', 544 args = ['$dartDir/tools/testing/run_selenium.py',
552 '--browser=${configuration["browser"]}', 545 '--browser=${configuration["browser"]}',
553 '--timeout=${configuration["timeout"] - 2}', 546 '--timeout=${configuration["timeout"] - 2}',
554 '--out=$htmlPath']; 547 '--out=$htmlPath'];
555 } else { 548 } else {
556 args = [ 549 args = [
557 '$dartDir/tools/testing/drt-trampoline.py', 550 '$dartDir/tools/testing/drt-trampoline.py',
558 dumpRenderTreeFilename, 551 dumpRenderTreeFilename,
559 '--no-timeout' 552 '--no-timeout'
560 ]; 553 ];
561 if (component == 'dartium') { 554 if (component == 'dartium') {
562 var dartFlags = ['--ignore-unrecognized-flags']; 555 var dartFlags = ['--ignore-unrecognized-flags'];
563 if (configuration["checked"]) { 556 if (configuration["checked"]) {
564 dartFlags.add('--enable_asserts'); 557 dartFlags.add('--enable_asserts');
565 dartFlags.add("--enable_type_checks"); 558 dartFlags.add("--enable_type_checks");
566 } 559 }
567 dartFlags.addAll(vmOptions); 560 dartFlags.addAll(vmOptions);
568 args.add('--dart-flags=${Strings.join(dartFlags, " ")}'); 561 args.add('--dart-flags=${Strings.join(dartFlags, " ")}');
569 } 562 }
570 args.add(htmlPath); 563 args.add(htmlPath);
571 } 564 }
565 commands.add(new Command('python', args));
566
572 // Create BrowserTestCase and queue it. 567 // Create BrowserTestCase and queue it.
573 var testCase = new BrowserTestCase( 568 var testCase = new BrowserTestCase(testName, commands, configuration,
574 testName, 569 completeHandler, expectations, optionsFromFile['isNegative']);
575 compilerExecutable,
576 compilerArgs,
577 'python',
578 args,
579 configuration,
580 completeHandler,
581 expectations,
582 optionsFromFile['isNegative']);
583 doTest(testCase); 570 doTest(testCase);
584 } 571 }
585 } 572 }
586 573
574 /** Helper to create a compilation command for a single input file. */
575 Command _compileCommand(String inputFile, String outputFile,
576 String component, String dir, var vmOptions) {
577 String executable = TestUtils.compilerPath(configuration);
578 List<String> args = TestUtils.standardOptions(configuration);
579 switch (component) {
580 case 'chromium':
581 args.addAll(['--work', dir]);
582 args.addAll(vmOptions);
583 args.add('--ignore-unrecognized-flags');
584 // TODO(zundel): remove assumption of generated code from dartc
585 args.add('--out');
586 args.add(outputFile);
587 args.add(inputFile);
588 // TODO(whesse): Add --fatal-type-errors if needed.
589 break;
590 case 'frogium':
591 case 'webdriver':
592 String libdir = configuration['froglib'];
593 if (libdir == '') {
594 libdir = '$dartDir/frog/lib';
595 }
596 args.addAll(['--libdir=$libdir',
597 '--compile-only',
598 '--out=$outputFile']);
599 args.addAll(vmOptions);
600 args.add(inputFile);
601 break;
602 case 'dartium':
603 // No compilation phase.
604 args = null;
605 break;
606 default:
607 Expect.fail('unimplemented component $component');
608 }
609 return new Command(executable, args);
610 }
611
587 bool get requiresCleanTemporaryDirectory() => 612 bool get requiresCleanTemporaryDirectory() =>
588 configuration['component'] == 'dartc' || 613 configuration['component'] == 'dartc' ||
589 configuration['component'] == 'chromium'; 614 configuration['component'] == 'chromium';
590 615
591 /** 616 /**
592 * Create a directory for the generated test. If a Dart language test 617 * Create a directory for the generated test. If a Dart language test
593 * needs to be run in a browser, the Dart test needs to be embedded in 618 * needs to be run in a browser, the Dart test needs to be embedded in
594 * an HTML page, with a testing framework based on scripting and DOM events. 619 * an HTML page, with a testing framework based on scripting and DOM events.
595 * These scripts and pages are written to a generated_test directory, 620 * These scripts and pages are written to a generated_test directory,
596 * usually inside the build directory of the checkout. 621 * usually inside the build directory of the checkout.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 options.addAll(args); 767 options.addAll(args);
743 result.add(options); 768 result.add(options);
744 } 769 }
745 770
746 return result; 771 return result;
747 } 772 }
748 773
749 Map readOptionsFromFile(String filename) { 774 Map readOptionsFromFile(String filename) {
750 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)"); 775 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)");
751 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)"); 776 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)");
777 RegExp otherScriptsRegExp = const RegExp(@"// OtherScripts=(.*)");
752 RegExp multiTestRegExp = const RegExp(@"/// [0-9][0-9]:(.*)"); 778 RegExp multiTestRegExp = const RegExp(@"/// [0-9][0-9]:(.*)");
753 RegExp leadingHashRegExp = const RegExp(@"^#", multiLine: true); 779 RegExp leadingHashRegExp = const RegExp(@"^#", multiLine: true);
754 RegExp isolateStubsRegExp = const RegExp(@"// IsolateStubs=(.*)"); 780 RegExp isolateStubsRegExp = const RegExp(@"// IsolateStubs=(.*)");
755 RegExp domImportRegExp = 781 RegExp domImportRegExp =
756 const RegExp(@"^#import.*(dart:(dom|html)|html\.dart).*\)", 782 const RegExp(@"^#import.*(dart:(dom|html)|html\.dart).*\)",
757 multiLine: true); 783 multiLine: true);
758 RegExp libraryDefinitionRegExp = 784 RegExp libraryDefinitionRegExp =
759 const RegExp(@"^#library\(", multiLine: true); 785 const RegExp(@"^#library\(", multiLine: true);
760 RegExp sourceOrImportRegExp = 786 RegExp sourceOrImportRegExp =
761 const RegExp(@"^#(source|import)\(", multiLine: true); 787 const RegExp(@"^#(source|import)\(", multiLine: true);
(...skipping 24 matching lines...) Expand all
786 812
787 matches = dartOptionsRegExp.allMatches(contents); 813 matches = dartOptionsRegExp.allMatches(contents);
788 for (var match in matches) { 814 for (var match in matches) {
789 if (dartOptions != null) { 815 if (dartOptions != null) {
790 throw new Exception( 816 throw new Exception(
791 'More than one "// DartOptions=" line in test $filename'); 817 'More than one "// DartOptions=" line in test $filename');
792 } 818 }
793 dartOptions = match[1].split(' ').filter((e) => e != ''); 819 dartOptions = match[1].split(' ').filter((e) => e != '');
794 } 820 }
795 821
822 List<String> otherScripts = new List<String>();
823 matches = otherScriptsRegExp.allMatches(contents);
824 for (var match in matches) {
825 otherScripts.addAll(match[1].split(' ').filter((e) => e != ''));
826 }
827
796 if (contents.contains("@compile-error") || 828 if (contents.contains("@compile-error") ||
797 contents.contains("@runtime-error")) { 829 contents.contains("@runtime-error")) {
798 isNegative = true; 830 isNegative = true;
799 } 831 }
800 832
801 bool isMultitest = multiTestRegExp.hasMatch(contents); 833 bool isMultitest = multiTestRegExp.hasMatch(contents);
802 bool containsLeadingHash = leadingHashRegExp.hasMatch(contents); 834 bool containsLeadingHash = leadingHashRegExp.hasMatch(contents);
803 Match isolateMatch = isolateStubsRegExp.firstMatch(contents); 835 Match isolateMatch = isolateStubsRegExp.firstMatch(contents);
804 String isolateStubs = isolateMatch != null ? isolateMatch[1] : ''; 836 String isolateStubs = isolateMatch != null ? isolateMatch[1] : '';
805 bool containsDomImport = domImportRegExp.hasMatch(contents); 837 bool containsDomImport = domImportRegExp.hasMatch(contents);
806 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents); 838 bool isLibraryDefinition = libraryDefinitionRegExp.hasMatch(contents);
807 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents); 839 bool containsSourceOrImport = sourceOrImportRegExp.hasMatch(contents);
808 840
809 841
810 return { "vmOptions": result, 842 return { "vmOptions": result,
811 "dartOptions": dartOptions, 843 "dartOptions": dartOptions,
812 "isNegative": isNegative, 844 "isNegative": isNegative,
845 "otherScripts": otherScripts,
813 "isMultitest": isMultitest, 846 "isMultitest": isMultitest,
814 "containsLeadingHash" : containsLeadingHash, 847 "containsLeadingHash" : containsLeadingHash,
815 "isolateStubs" : isolateStubs, 848 "isolateStubs" : isolateStubs,
816 "containsDomImport": containsDomImport, 849 "containsDomImport": containsDomImport,
817 "isLibraryDefinition": isLibraryDefinition, 850 "isLibraryDefinition": isLibraryDefinition,
818 "containsSourceOrImport": containsSourceOrImport }; 851 "containsSourceOrImport": containsSourceOrImport };
819 } 852 }
820 } 853 }
821 854
822 855
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 List<String> args = <String>[ 987 List<String> args = <String>[
955 '-ea', 988 '-ea',
956 '-classpath', classPath, 989 '-classpath', classPath,
957 '-Dcom.google.dart.runner.d8=$d8', 990 '-Dcom.google.dart.runner.d8=$d8',
958 '-Dcom.google.dart.corelib.SharedTests.test_py=' + 991 '-Dcom.google.dart.corelib.SharedTests.test_py=' +
959 dartDir + '/tools/test.py', 992 dartDir + '/tools/test.py',
960 'org.junit.runner.JUnitCore']; 993 'org.junit.runner.JUnitCore'];
961 args.addAll(testClasses); 994 args.addAll(testClasses);
962 995
963 doTest(new TestCase(suiteName, 996 doTest(new TestCase(suiteName,
964 'java', 997 [new Command('java', args)],
965 args,
966 configuration, 998 configuration,
967 completeHandler, 999 completeHandler,
968 new Set<String>.from([PASS]))); 1000 new Set<String>.from([PASS])));
969 doDone(); 1001 doDone();
970 } 1002 }
971 1003
972 void completeHandler(TestCase testCase) { 1004 void completeHandler(TestCase testCase) {
973 } 1005 }
974 1006
975 void computeClassPath() { 1007 void computeClassPath() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 * $noCrash tests are expected to be flaky but not crash 1172 * $noCrash tests are expected to be flaky but not crash
1141 * $pass tests are expected to pass 1173 * $pass tests are expected to pass
1142 * $failOk tests are expected to fail that we won't fix 1174 * $failOk tests are expected to fail that we won't fix
1143 * $fail tests are expected to fail that we should fix 1175 * $fail tests are expected to fail that we should fix
1144 * $crash tests are expected to crash that we should fix 1176 * $crash tests are expected to crash that we should fix
1145 * $timeout tests are allowed to timeout 1177 * $timeout tests are allowed to timeout
1146 """; 1178 """;
1147 print(report); 1179 print(report);
1148 } 1180 }
1149 } 1181 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_runner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698