| 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 * This test makes sure that the "skipping Dart2Js compilations if the output is | 6 * This test makes sure that the "skipping Dart2Js compilations if the output is |
| 7 * already up to date" feature does work as it should. | 7 * already up to date" feature does work as it should. |
| 8 * Therefore this test ensures that compilations are only skipped if the last | 8 * Therefore this test ensures that compilations are only skipped if the last |
| 9 * modified date of the output of a dart2js compilation is newer than | 9 * modified date of the output of a dart2js compilation is newer than |
| 10 * - the the dart application to compile (including it's dependencies) | 10 * - the the dart application to compile (including it's dependencies) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 Expect.isFalse(output.unexpectedOutput); | 134 Expect.isFalse(output.unexpectedOutput); |
| 135 Expect.isTrue(output.stderr.length == 0); | 135 Expect.isTrue(output.stderr.length == 0); |
| 136 if (_shouldHaveRun) { | 136 if (_shouldHaveRun) { |
| 137 Expect.isTrue(output.stdout.length == 0); | 137 Expect.isTrue(output.stdout.length == 0); |
| 138 Expect.isTrue(new File(fileUtils.scriptOutputPath.toNativePath()) | 138 Expect.isTrue(new File(fileUtils.scriptOutputPath.toNativePath()) |
| 139 .existsSync()); | 139 .existsSync()); |
| 140 } else { | 140 } else { |
| 141 Expect.isFalse(new File(fileUtils.scriptOutputPath.toNativePath()) | 141 Expect.isFalse(new File(fileUtils.scriptOutputPath.toNativePath()) |
| 142 .existsSync()); | 142 .existsSync()); |
| 143 } | 143 } |
| 144 fileUtils.cleanup(); | |
| 145 } | 144 } |
| 146 } | 145 } |
| 147 | 146 |
| 148 runner.TestCase makeTestCase(String testName, | 147 runner.TestCase makeTestCase(String testName, FileUtils fileUtils) { |
| 149 TestCompletedHandler completedHandler) { | |
| 150 var fileUtils = completedHandler.fileUtils; | |
| 151 var config = new options.TestOptionsParser().parse(['--timeout', '2'])[0]; | 148 var config = new options.TestOptionsParser().parse(['--timeout', '2'])[0]; |
| 152 var scriptDirPath = new Path(new Options().script).directoryPath; | 149 var scriptDirPath = new Path(new Options().script).directoryPath; |
| 153 var createFileScript = scriptDirPath. | 150 var createFileScript = scriptDirPath. |
| 154 append('skipping_dart2js_compilations_helper.dart').toNativePath(); | 151 append('skipping_dart2js_compilations_helper.dart').toNativePath(); |
| 155 var executable = new Options().executable; | 152 var executable = new Options().executable; |
| 156 var arguments = [createFileScript, fileUtils.scriptOutputPath.toNativePath()]; | 153 var arguments = [createFileScript, fileUtils.scriptOutputPath.toNativePath()]; |
| 157 var bootstrapDeps = [ | 154 var bootstrapDeps = [ |
| 158 new Uri("file://${fileUtils.testSnapshotFilePath}")]; | 155 new Uri("file://${fileUtils.testSnapshotFilePath}")]; |
| 159 var commands = [new runner.CompilationCommand( | 156 var commands = [new runner.CompilationCommand( |
| 160 fileUtils.testJsFilePath.toNativePath(), | 157 fileUtils.testJsFilePath.toNativePath(), |
| 161 false, | 158 false, |
| 162 bootstrapDeps, | 159 bootstrapDeps, |
| 163 executable, | 160 executable, |
| 164 arguments)]; | 161 arguments)]; |
| 165 return new runner.TestCase( | 162 return new runner.TestCase( |
| 166 testName, | 163 testName, |
| 167 commands, | 164 commands, |
| 168 config, | 165 config, |
| 169 completedHandler.processCompletedTest, | 166 (_) {}, |
| 170 new Set<String>.from([status.PASS])); | 167 new Set<String>.from([status.PASS])); |
| 171 } | 168 } |
| 172 | 169 |
| 173 void main() { | 170 void main() { |
| 174 var fs_noTestJs = new FileUtils(createJs: false, | 171 var fs_noTestJs = new FileUtils(createJs: false, |
| 175 createJsDeps: true, | 172 createJsDeps: true, |
| 176 createDart: true, | 173 createDart: true, |
| 177 createSnapshot: true); | 174 createSnapshot: true); |
| 178 var fs_noTestJsDeps = new FileUtils(createJs: true, | 175 var fs_noTestJsDeps = new FileUtils(createJs: true, |
| 179 createJsDeps: false, | 176 createJsDeps: false, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 192 createDart: true, | 189 createDart: true, |
| 193 createSnapshot: true); | 190 createSnapshot: true); |
| 194 var fs_notUpToDate_dart = new FileUtils(createJs: true, | 191 var fs_notUpToDate_dart = new FileUtils(createJs: true, |
| 195 createJsDeps: true, | 192 createJsDeps: true, |
| 196 createDart: true, | 193 createDart: true, |
| 197 createSnapshot: true); | 194 createSnapshot: true); |
| 198 var fs_upToDate = new FileUtils(createJs: true, | 195 var fs_upToDate = new FileUtils(createJs: true, |
| 199 createJsDeps: true, | 196 createJsDeps: true, |
| 200 createDart: true, | 197 createDart: true, |
| 201 createSnapshot: true); | 198 createSnapshot: true); |
| 199 void cleanup() { |
| 200 fs_noTestJs.cleanup(); |
| 201 fs_noTestJsDeps.cleanup(); |
| 202 fs_noTestDart.cleanup(); |
| 203 fs_noTestSnapshot.cleanup(); |
| 204 fs_notUpToDate_snapshot.cleanup(); |
| 205 fs_notUpToDate_dart.cleanup(); |
| 206 fs_upToDate.cleanup(); |
| 207 } |
| 202 | 208 |
| 203 void touchFilesAndRunTests() { | 209 void touchFilesAndRunTests() { |
| 204 fs_notUpToDate_snapshot.touchFile(fs_notUpToDate_snapshot.testSnapshot); | 210 fs_notUpToDate_snapshot.touchFile(fs_notUpToDate_snapshot.testSnapshot); |
| 205 fs_notUpToDate_dart.touchFile(fs_notUpToDate_dart.testDart); | 211 fs_notUpToDate_dart.touchFile(fs_notUpToDate_dart.testDart); |
| 206 fs_upToDate.touchFile(fs_upToDate.testJs); | 212 fs_upToDate.touchFile(fs_upToDate.testJs); |
| 207 | 213 |
| 208 void runTest(String name, FileUtils fileUtils, bool shouldRun) { | 214 Future runTest(String name, FileUtils fileUtils, bool shouldRun) { |
| 209 var testCase = makeTestCase( | 215 var completedHandler = new TestCompletedHandler(fileUtils, shouldRun); |
| 210 name, new TestCompletedHandler(fileUtils, shouldRun)); | 216 var testCase = makeTestCase(name, fileUtils); |
| 211 new runner.RunningProcess(testCase, testCase.commands[0]).start(); | 217 var process = new runner.RunningProcess(testCase, testCase.commands[0]); |
| 218 return process.start().then((_) { |
| 219 completedHandler.processCompletedTest(testCase); |
| 220 }); |
| 212 } | 221 } |
| 213 runTest("fs_noTestJs", fs_noTestJs, true); | 222 // We run the tests in sequence, so that if one of them failes we clean up |
| 214 runTest("fs_noTestJsDeps", fs_noTestJsDeps, true); | 223 // everything and throw. |
| 215 runTest("fs_noTestDart", fs_noTestDart, true); | 224 runTest("fs_noTestJs", fs_noTestJs, true).then((_) { |
| 216 runTest("fs_noTestSnapshot", fs_noTestSnapshot, true); | 225 return runTest("fs_noTestJsDeps", fs_noTestJsDeps, true); |
| 217 runTest("fs_notUpToDate_snapshot", fs_notUpToDate_snapshot, true); | 226 }).then((_) { |
| 218 runTest("fs_notUpToDate_dart", fs_notUpToDate_dart, true); | 227 return runTest("fs_noTestDart", fs_noTestDart, true); |
| 219 // This is the only test where all dependencies are present and the test.js | 228 }).then((_) { |
| 220 // file is newer than all the others. So we pass 'false' for shouldRun. | 229 return runTest("fs_noTestSnapshot", fs_noTestSnapshot, true); |
| 221 runTest("fs_upToDate", fs_upToDate, false); | 230 }).then((_) { |
| 231 return runTest("fs_notUpToDate_snapshot", fs_notUpToDate_snapshot, true); |
| 232 }).then((_) { |
| 233 return runTest("fs_notUpToDate_dart", fs_notUpToDate_dart, true); |
| 234 }).then((_) { |
| 235 // This is the only test where all dependencies are present and the |
| 236 // test.js file is newer than all the others. So we pass 'false' for |
| 237 // shouldRun. |
| 238 return runTest("fs_upToDate", fs_upToDate, false); |
| 239 }).catchError((error) { |
| 240 cleanup(); |
| 241 throw error; |
| 242 }).then((_) { |
| 243 cleanup(); |
| 244 }); |
| 222 } | 245 } |
| 223 // We need to wait some time to make sure that the files we 'touch' get a | 246 // We need to wait some time to make sure that the files we 'touch' get a |
| 224 // bigger timestamp than the old ones | 247 // bigger timestamp than the old ones |
| 225 new Timer(new Duration(seconds: 1), touchFilesAndRunTests); | 248 new Timer(new Duration(seconds: 1), touchFilesAndRunTests); |
| 226 } | 249 } |
| OLD | NEW |