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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 */ | 377 */ |
| 378 class StandardTestSuite extends TestSuite { | 378 class StandardTestSuite extends TestSuite { |
| 379 final Path suiteDir; | 379 final Path suiteDir; |
| 380 final List<String> statusFilePaths; | 380 final List<String> statusFilePaths; |
| 381 TestCaseEvent doTest; | 381 TestCaseEvent doTest; |
| 382 TestExpectations testExpectations; | 382 TestExpectations testExpectations; |
| 383 List<TestInformation> cachedTests; | 383 List<TestInformation> cachedTests; |
| 384 final Path dartDir; | 384 final Path dartDir; |
| 385 Predicate<String> isTestFilePredicate; | 385 Predicate<String> isTestFilePredicate; |
| 386 final bool listRecursively; | 386 final bool listRecursively; |
| 387 /** | |
| 388 * The set of servers that have been started to run these tests (Could be | |
| 389 * none). | |
| 390 */ | |
| 391 List serverList; | |
| 387 | 392 |
| 388 StandardTestSuite(Map configuration, | 393 StandardTestSuite(Map configuration, |
| 389 String suiteName, | 394 String suiteName, |
| 390 Path suiteDirectory, | 395 Path suiteDirectory, |
| 391 this.statusFilePaths, | 396 this.statusFilePaths, |
| 397 this.serverList, | |
| 392 {this.isTestFilePredicate, | 398 {this.isTestFilePredicate, |
| 393 bool recursive: false}) | 399 bool recursive: false}) |
| 394 : super(configuration, suiteName), | 400 : super(configuration, suiteName), |
| 395 dartDir = TestUtils.dartDir(), | 401 dartDir = TestUtils.dartDir(), |
| 396 listRecursively = recursive, | 402 listRecursively = recursive, |
| 397 suiteDir = TestUtils.dartDir().join(suiteDirectory); | 403 suiteDir = TestUtils.dartDir().join(suiteDirectory); |
| 398 | 404 |
| 399 /** | 405 /** |
| 400 * Creates a test suite whose file organization matches an expected structure. | 406 * Creates a test suite whose file organization matches an expected structure. |
| 401 * To use this, your suite should look like: | 407 * To use this, your suite should look like: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 415 * * The status file uses the same name. | 421 * * The status file uses the same name. |
| 416 * * Test files are directly in that directory and end in "_test.dart". | 422 * * Test files are directly in that directory and end in "_test.dart". |
| 417 * | 423 * |
| 418 * If you follow that convention, then you can construct one of these like: | 424 * If you follow that convention, then you can construct one of these like: |
| 419 * | 425 * |
| 420 * new StandardTestSuite.forDirectory(configuration, 'path/to/mytestsuite'); | 426 * new StandardTestSuite.forDirectory(configuration, 'path/to/mytestsuite'); |
| 421 * | 427 * |
| 422 * instead of having to create a custom [StandardTestSuite] subclass. In | 428 * instead of having to create a custom [StandardTestSuite] subclass. In |
| 423 * particular, if you add 'path/to/mytestsuite' to [TEST_SUITE_DIRECTORIES] | 429 * particular, if you add 'path/to/mytestsuite' to [TEST_SUITE_DIRECTORIES] |
| 424 * in test.dart, this will all be set up for you. | 430 * in test.dart, this will all be set up for you. |
| 431 * | |
| 432 * The [StandardTestSuite] also optionally takes a list of servers that have | |
| 433 * been started up by the test harness, to be used by browser tests. | |
| 425 */ | 434 */ |
| 426 factory StandardTestSuite.forDirectory( | 435 factory StandardTestSuite.forDirectory( |
| 427 Map configuration, Path directory) { | 436 Map configuration, Path directory, [List serverList=const []]) { |
|
Mads Ager (google)
2013/01/04 09:39:20
Could you add spacing around '=': [List serverList
Emily Fortuna
2013/01/04 23:26:54
Done.
| |
| 428 final name = directory.filename; | 437 final name = directory.filename; |
| 429 | 438 |
| 430 return new StandardTestSuite(configuration, | 439 return new StandardTestSuite(configuration, |
| 431 name, directory, | 440 name, directory, |
| 432 ['$directory/$name.status', '$directory/${name}_dart2js.status'], | 441 ['$directory/$name.status', '$directory/${name}_dart2js.status'], |
| 442 serverList, | |
| 433 isTestFilePredicate: (filename) => filename.endsWith('_test.dart'), | 443 isTestFilePredicate: (filename) => filename.endsWith('_test.dart'), |
| 434 recursive: true); | 444 recursive: true); |
| 435 } | 445 } |
| 436 | 446 |
| 437 Collection<Uri> get dart2JsBootstrapDependencies { | 447 Collection<Uri> get dart2JsBootstrapDependencies { |
| 438 if (!useDart2JsFromSdk) return []; | 448 if (!useDart2JsFromSdk) return []; |
| 439 | 449 |
| 440 var snapshotPath = TestUtils.absolutePath(new Path(buildDir).join( | 450 var snapshotPath = TestUtils.absolutePath(new Path(buildDir).join( |
| 441 new Path('dart-sdk/lib/_internal/compiler/' | 451 new Path('dart-sdk/lib/_internal/compiler/' |
| 442 'implementation/dart2js.dart.snapshot'))).toString(); | 452 'implementation/dart2js.dart.snapshot'))).toString(); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 } | 707 } |
| 698 } | 708 } |
| 699 | 709 |
| 700 List<Command> makeCommands(TestInformation info, var vmOptions, var args) { | 710 List<Command> makeCommands(TestInformation info, var vmOptions, var args) { |
| 701 switch (configuration['compiler']) { | 711 switch (configuration['compiler']) { |
| 702 case 'dart2js': | 712 case 'dart2js': |
| 703 args = new List.from(args); | 713 args = new List.from(args); |
| 704 String tempDir = createOutputDirectory(info.filePath, ''); | 714 String tempDir = createOutputDirectory(info.filePath, ''); |
| 705 args.add('--out=$tempDir/out.js'); | 715 args.add('--out=$tempDir/out.js'); |
| 706 | 716 |
| 707 List<Command> commands = | 717 List<Command> commands = |
| 708 <Command>[new CompilationCommand("$tempDir/out.js", | 718 <Command>[new CompilationCommand("$tempDir/out.js", |
| 709 !useDart2JsFromSdk, | 719 !useDart2JsFromSdk, |
| 710 dart2JsBootstrapDependencies, | 720 dart2JsBootstrapDependencies, |
| 711 compilerPath, | 721 compilerPath, |
| 712 args)]; | 722 args)]; |
| 713 if (info.hasCompileError) { | 723 if (info.hasCompileError) { |
| 714 // Do not attempt to run the compiled result. A compilation | 724 // Do not attempt to run the compiled result. A compilation |
| 715 // error should be reported by the compilation command. | 725 // error should be reported by the compilation command. |
| 716 } else if (configuration['runtime'] == 'd8') { | 726 } else if (configuration['runtime'] == 'd8') { |
| 717 commands.add(new Command(d8FileName, ['$tempDir/out.js'])); | 727 commands.add(new Command(d8FileName, ['$tempDir/out.js'])); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 String htmlFilename = getHtmlName(filename); | 865 String htmlFilename = getHtmlName(filename); |
| 856 while ('$tempDir/../$htmlFilename'.length >= 260) { | 866 while ('$tempDir/../$htmlFilename'.length >= 260) { |
| 857 htmlFilename = htmlFilename.substring(htmlFilename.length~/2); | 867 htmlFilename = htmlFilename.substring(htmlFilename.length~/2); |
| 858 } | 868 } |
| 859 htmlPath = '$tempDir/../$htmlFilename'; | 869 htmlPath = '$tempDir/../$htmlFilename'; |
| 860 } | 870 } |
| 861 final String scriptPath = (compiler == 'none') ? | 871 final String scriptPath = (compiler == 'none') ? |
| 862 dartWrapperFilename : compiledDartWrapperFilename; | 872 dartWrapperFilename : compiledDartWrapperFilename; |
| 863 // Create the HTML file for the test. | 873 // Create the HTML file for the test. |
| 864 RandomAccessFile htmlTest = new File(htmlPath).openSync(FileMode.WRITE); | 874 RandomAccessFile htmlTest = new File(htmlPath).openSync(FileMode.WRITE); |
| 865 String filePrefix = ''; | |
| 866 if (Platform.operatingSystem == 'windows') { | |
| 867 // Firefox on Windows does not like absolute file path names that start | |
| 868 // with 'C:' adding 'file:///' solves the problem. | |
| 869 filePrefix = 'file:///'; | |
| 870 } | |
| 871 String content = null; | 875 String content = null; |
| 872 Path dir = filePath.directoryPath; | 876 Path dir = filePath.directoryPath; |
| 873 String nameNoExt = filePath.filenameWithoutExtension; | 877 String nameNoExt = filePath.filenameWithoutExtension; |
| 874 Path pngPath = dir.append('$nameNoExt.png'); | 878 Path pngPath = dir.append('$nameNoExt.png'); |
| 875 Path txtPath = dir.append('$nameNoExt.txt'); | 879 Path txtPath = dir.append('$nameNoExt.txt'); |
| 876 Path expectedOutput = null; | 880 Path expectedOutput = null; |
| 877 if (new File.fromPath(pngPath).existsSync()) { | 881 if (new File.fromPath(pngPath).existsSync()) { |
| 878 expectedOutput = pngPath; | 882 expectedOutput = pngPath; |
| 879 content = getHtmlLayoutContents(scriptType, '$filePrefix$scriptPath'); | 883 content = getHtmlLayoutContents(scriptType, '$scriptPath'); |
| 880 } else if (new File.fromPath(txtPath).existsSync()) { | 884 } else if (new File.fromPath(txtPath).existsSync()) { |
| 881 expectedOutput = txtPath; | 885 expectedOutput = txtPath; |
| 882 content = getHtmlLayoutContents(scriptType, '$filePrefix$scriptPath'); | 886 content = getHtmlLayoutContents(scriptType, '$scriptPath'); |
| 883 } else { | 887 } else { |
| 884 final htmlLocation = new Path.fromNative(htmlPath); | 888 final htmlLocation = new Path.fromNative(htmlPath); |
| 885 content = getHtmlContents( | 889 content = getHtmlContents( |
| 886 filename, | 890 filename, |
| 887 dartDir.append('pkg/unittest/test_controller.js') | 891 dartDir.append('pkg/unittest/test_controller.js') |
| 888 .relativeTo(htmlLocation), | 892 .relativeTo(htmlLocation), |
| 889 dartDir.append('client/dart.js').relativeTo(htmlLocation), | 893 dartDir.append('client/dart.js').relativeTo(htmlLocation), |
| 890 scriptType, | 894 scriptType, |
| 891 new Path.fromNative(scriptPath).relativeTo(htmlLocation)); | 895 new Path.fromNative(scriptPath).relativeTo(htmlLocation)); |
| 892 } | 896 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 915 } | 919 } |
| 916 | 920 |
| 917 // Variables for browser multi-tests. | 921 // Variables for browser multi-tests. |
| 918 List<String> subtestNames = info.optionsFromFile['subtestNames']; | 922 List<String> subtestNames = info.optionsFromFile['subtestNames']; |
| 919 TestCase multitestParentTest; | 923 TestCase multitestParentTest; |
| 920 int subtestIndex = 0; | 924 int subtestIndex = 0; |
| 921 // Construct the command that executes the browser test | 925 // Construct the command that executes the browser test |
| 922 do { | 926 do { |
| 923 List<Command> commandSet = new List<Command>.from(commands); | 927 List<Command> commandSet = new List<Command>.from(commands); |
| 924 if (subtestIndex != 0) { | 928 if (subtestIndex != 0) { |
| 925 // NOTE: The first time we enter this loop, all the compilation | 929 // NOTE: The first time we enter this loop, all the compilation |
| 926 // commands will be executed. On subsequent loop iterations, we | 930 // commands will be executed. On subsequent loop iterations, we |
| 927 // don't need to do any compilations. Thus we set "commandSet = []". | 931 // don't need to do any compilations. Thus we set "commandSet = []". |
| 928 commandSet = []; | 932 commandSet = []; |
| 929 } | 933 } |
| 930 | 934 |
| 931 List<String> args = <String>[]; | 935 List<String> args = <String>[]; |
| 932 String fullHtmlPath = htmlPath.startsWith('http:') ? htmlPath : | 936 var basePath = TestUtils.dartDir().toString(); |
| 933 (htmlPath.startsWith('/') ? | 937 htmlPath = htmlPath.startsWith(basePath) ? |
| 934 'file://$htmlPath' : | 938 htmlPath.substring(basePath.length) : htmlPath; |
| 935 'file:///$htmlPath'); | 939 String fullHtmlPath = htmlPath; |
| 940 if (!htmlPath.startsWith('http')) { | |
| 941 if (htmlPath.startsWith('/')) htmlPath = '/$htmlPath'; | |
|
Mads Ager (google)
2013/01/04 09:39:20
Shouldn't this be
if (!htmlPath.startsWith('/'))
Emily Fortuna
2013/01/04 23:26:54
Oops, yes. Refactoring fail. Fixed.
| |
| 942 fullHtmlPath = 'http://127.0.0.1:${serverList[0].port}$htmlPath?' | |
| 943 'crossOriginPort=${serverList[1].port}'; | |
| 944 } | |
| 936 if (info.optionsFromFile['isMultiHtmlTest'] | 945 if (info.optionsFromFile['isMultiHtmlTest'] |
| 937 && subtestNames.length > 0) { | 946 && subtestNames.length > 0) { |
| 938 fullHtmlPath = '${fullHtmlPath}#${subtestNames[subtestIndex]}'; | 947 fullHtmlPath = '${fullHtmlPath}#${subtestNames[subtestIndex]}'; |
| 939 } | 948 } |
| 940 | 949 |
| 941 if (TestUtils.usesWebDriver(runtime)) { | 950 if (TestUtils.usesWebDriver(runtime)) { |
| 942 args = [ | 951 args = [ |
| 943 dartDir.append('tools/testing/run_selenium.py').toNativePath(), | 952 dartDir.append('tools/testing/run_selenium.py').toNativePath(), |
| 944 '--browser=$runtime', | 953 '--browser=$runtime', |
| 945 '--timeout=${configuration["timeout"] - 2}', | 954 '--timeout=${configuration["timeout"] - 2}', |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 964 dartFlags.add('--ignore-unrecognized-flags'); | 973 dartFlags.add('--ignore-unrecognized-flags'); |
| 965 if (configuration["checked"]) { | 974 if (configuration["checked"]) { |
| 966 dartFlags.add('--enable_asserts'); | 975 dartFlags.add('--enable_asserts'); |
| 967 dartFlags.add("--enable_type_checks"); | 976 dartFlags.add("--enable_type_checks"); |
| 968 } | 977 } |
| 969 dartFlags.addAll(vmOptions); | 978 dartFlags.addAll(vmOptions); |
| 970 } | 979 } |
| 971 if (compiler == 'none') { | 980 if (compiler == 'none') { |
| 972 var packageRootPath = packageRoot(optionsFromFile['packageRoot']); | 981 var packageRootPath = packageRoot(optionsFromFile['packageRoot']); |
| 973 if (packageRootPath != null) { | 982 if (packageRootPath != null) { |
| 974 var absolutePath = | 983 var absolutePath = |
| 975 TestUtils.absolutePath(new Path(packageRootPath)); | 984 TestUtils.absolutePath(new Path(packageRootPath)); |
| 976 packageRootUri = new Uri.fromComponents( | 985 packageRootUri = new Uri.fromComponents( |
| 977 scheme: 'file', | 986 scheme: 'file', |
| 978 path: absolutePath.toString()); | 987 path: absolutePath.toString()); |
| 979 } | 988 } |
| 980 } | 989 } |
| 981 | 990 |
| 982 if (expectedOutput != null) { | 991 if (expectedOutput != null) { |
| 983 if (expectedOutput.toNativePath().endsWith('.png')) { | 992 if (expectedOutput.toNativePath().endsWith('.png')) { |
| 984 // pixel tests are specified by running DRT "foo.html'-p" | 993 // pixel tests are specified by running DRT "foo.html'-p" |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1793 * $pass tests are expected to pass | 1802 * $pass tests are expected to pass |
| 1794 * $failOk tests are expected to fail that we won't fix | 1803 * $failOk tests are expected to fail that we won't fix |
| 1795 * $fail tests are expected to fail that we should fix | 1804 * $fail tests are expected to fail that we should fix |
| 1796 * $crash tests are expected to crash that we should fix | 1805 * $crash tests are expected to crash that we should fix |
| 1797 * $timeout tests are allowed to timeout | 1806 * $timeout tests are allowed to timeout |
| 1798 * $compileErrorSkip tests are skipped on browsers due to compile-time error | 1807 * $compileErrorSkip tests are skipped on browsers due to compile-time error |
| 1799 """; | 1808 """; |
| 1800 print(report); | 1809 print(report); |
| 1801 } | 1810 } |
| 1802 } | 1811 } |
| OLD | NEW |