| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * The DartWrapTask generates a Dart wrapper for a test file, that has a | |
| 7 * test Configuration customized for the options specified by the user. | |
| 8 */ | |
| 9 class DartWrapTask extends PipelineTask { | |
| 10 final String _sourceFileTemplate; | |
| 11 final String _tempDartFileTemplate; | |
| 12 | |
| 13 DartWrapTask(this._sourceFileTemplate, this._tempDartFileTemplate); | |
| 14 | |
| 15 execute(Path testfile, List stdout, List stderr, bool logging, | |
| 16 Function exitHandler) { | |
| 17 // Get the source test file and canonicalize the path. | |
| 18 var sourceName = makePathAbsolute( | |
| 19 expandMacros(_sourceFileTemplate, testfile)); | |
| 20 // Get the destination file. | |
| 21 var destFile = expandMacros(_tempDartFileTemplate, testfile); | |
| 22 | |
| 23 if (config.layoutText || config.layoutPixel) { | |
| 24 makeLayoutTestWrappers(sourceName, destFile, runnerDirectory); | |
| 25 } else { | |
| 26 makeNonLayoutTestWrapper(sourceName, destFile, runnerDirectory); | |
| 27 } | |
| 28 exitHandler(0); | |
| 29 } | |
| 30 | |
| 31 void makeLayoutTestWrappers(String sourceName, | |
| 32 String destFile, | |
| 33 String libDirectory) { | |
| 34 | |
| 35 // Get the name of the directory that has the expectation files | |
| 36 // (by stripping .dart suffix from test file path). | |
| 37 // Create it if it does not exist. | |
| 38 var expectedDirectory = sourceName.substring(0, sourceName.length - 5); | |
| 39 if (config.regenerate) { | |
| 40 var d = new Directory(expectedDirectory); | |
| 41 if (!d.existsSync()) { | |
| 42 d.createSync(); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 // Create the child file that runs single tests in DRT. | |
| 47 var childFile = | |
| 48 '${destFile.substring(0, destFile.length - 5)}-child.dart'; | |
| 49 createFile(childFile, layoutTestWrapper(sourceName, libDirectory)); | |
| 50 | |
| 51 // Create the controller file that invokes DRT for each test. | |
| 52 createFile(destFile, | |
| 53 layoutTestControllerWrapper(sourceName, childFile, | |
| 54 expectedDirectory, libDirectory)); | |
| 55 } | |
| 56 | |
| 57 void makeNonLayoutTestWrapper(String sourceName, | |
| 58 String destFile, | |
| 59 String libDirectory) { | |
| 60 var extraImports; | |
| 61 var onDone; | |
| 62 var tprint; | |
| 63 var action; | |
| 64 if (config.runInBrowser) { | |
| 65 extraImports = "#import('dart:html');"; | |
| 66 onDone = "window.postMessage('done', '*')"; | |
| 67 tprint = "query('#console').addText('###\$msg\\n')"; | |
| 68 } else { | |
| 69 extraImports = "#import('dart:io');"; | |
| 70 onDone = "exit(e)"; | |
| 71 tprint = "print('###\$msg')"; | |
| 72 } | |
| 73 if (config.listTests) { | |
| 74 action = 'listTests'; | |
| 75 } else if (config.listGroups) { | |
| 76 action = 'listGroups'; | |
| 77 } else if (config.runIsolated) { | |
| 78 action = 'runIsolateTests'; | |
| 79 } else { | |
| 80 action = 'null'; | |
| 81 } | |
| 82 var wrapper = """ | |
| 83 #library('standard_test'); | |
| 84 $extraImports | |
| 85 #import('${config.unittestPath}', prefix:'unittest'); | |
| 86 #import('$sourceName', prefix: 'test'); | |
| 87 #source('$libDirectory/standard_test_runner.dart'); | |
| 88 | |
| 89 main() { | |
| 90 action = null; | |
| 91 immediate = ${config.immediateOutput}; | |
| 92 includeTime = ${config.includeTime}; | |
| 93 passFormat = '${config.passFormat}'; | |
| 94 failFormat = '${config.failFormat}'; | |
| 95 errorFormat = '${config.errorFormat}'; | |
| 96 listFormat = '${config.listFormat}'; | |
| 97 includeFilters = ${config.includeFilter}; | |
| 98 excludeFilters = ${config.excludeFilter}; | |
| 99 regenerate = ${config.regenerate}; | |
| 100 testfile = '$sourceName'; | |
| 101 summarize = ${config.produceSummary}; | |
| 102 notifyDone = (e) => $onDone; | |
| 103 tprint = (msg) => $tprint; | |
| 104 action = $action; | |
| 105 runTests(test.main); | |
| 106 } | |
| 107 """; | |
| 108 // Save the Dart file. | |
| 109 createFile(destFile, wrapper); | |
| 110 } | |
| 111 | |
| 112 void cleanup(Path testfile, List stdout, List stderr, | |
| 113 bool logging, bool keepFiles) { | |
| 114 deleteFiles([_tempDartFileTemplate], testfile, logging, keepFiles, stdout); | |
| 115 } | |
| 116 | |
| 117 String layoutTestWrapper(String sourceName, String libDirectory) => """ | |
| 118 #library('layout_test'); | |
| 119 #import('dart:math'); | |
| 120 #import('dart:isolate'); | |
| 121 #import('dart:html'); | |
| 122 #import('dart:uri'); | |
| 123 #import('${config.unittestPath}', prefix:'unittest'); | |
| 124 #import('$sourceName', prefix: 'test'); | |
| 125 #source('$libDirectory/layout_test_runner.dart'); | |
| 126 | |
| 127 main() { | |
| 128 includeFilters = ${config.includeFilter}; | |
| 129 excludeFilters = ${config.excludeFilter}; | |
| 130 runTests(test.main); | |
| 131 } | |
| 132 """; | |
| 133 | |
| 134 | |
| 135 String layoutTestControllerWrapper(String sourceName, String childName, | |
| 136 String expectedDirectory, | |
| 137 String libDirectory) { | |
| 138 StringBuffer sbuf = new StringBuffer(); | |
| 139 var htmlFile = childName.replaceFirst('-child.dart', '.html'); | |
| 140 // Add common prefix. | |
| 141 return """ | |
| 142 #library('layout_controller'); | |
| 143 #import('dart:uri'); | |
| 144 #import('dart:io'); | |
| 145 #import('dart:math'); | |
| 146 #source('$libDirectory/layout_test_controller.dart'); | |
| 147 | |
| 148 main() { | |
| 149 includeTime = ${config.includeTime}; | |
| 150 passFormat = '${config.passFormat}'; | |
| 151 failFormat = '${config.failFormat}'; | |
| 152 errorFormat = '${config.errorFormat}'; | |
| 153 listFormat = '${config.listFormat}'; | |
| 154 drt = '${makePathAbsolute(config.drtPath)}'; | |
| 155 regenerate = ${config.regenerate}; | |
| 156 sourceDir = '$expectedDirectory'; | |
| 157 testfile = '$sourceName'; | |
| 158 summarize = ${config.produceSummary}; | |
| 159 baseUrl = 'file://$htmlFile'; | |
| 160 run${config.layoutText?'Text':'Pixel'}LayoutTest(0); | |
| 161 } | |
| 162 """; | |
| 163 } | |
| 164 } | |
| OLD | NEW |