| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // OtherResources=skipping_dart2js_compilations_helper.dart | 5 // OtherResources=skipping_dart2js_compilations_helper.dart |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * This test makes sure that the "skipping Dart2Js compilations if the output is | 8 * This test makes sure that the "skipping Dart2Js compilations if the output is |
| 9 * already up to date" feature does work as it should. | 9 * already up to date" feature does work as it should. |
| 10 * Therefore this test ensures that compilations are only skipped if the last | 10 * Therefore this test ensures that compilations are only skipped if the last |
| 11 * modified date of the output of a dart2js compilation is newer than | 11 * modified date of the output of a dart2js compilation is newer than |
| 12 * - the dart application to compile (including it's dependencies) | 12 * - the dart application to compile (including it's dependencies) |
| 13 * - the dart2js snapshot | 13 * - the dart2js snapshot |
| 14 * Furtheremore it ensure that a compilations is not skipped if any of the | 14 * Furtheremore it ensure that a compilations is not skipped if any of the |
| 15 * necessary files could not be found (dart2js snapshots, previous dart2js | 15 * necessary files could not be found (dart2js snapshots, previous dart2js |
| 16 * output (+deps file), dart application) | 16 * output (+deps file), dart application) |
| 17 */ | 17 */ |
| 18 | 18 |
| 19 import 'package:expect/expect.dart'; | 19 import 'package:expect/expect.dart'; |
| 20 import 'package:path/path.dart'; | |
| 21 import 'dart:async'; | 20 import 'dart:async'; |
| 22 import 'dart:io'; | 21 import 'dart:io'; |
| 23 import '../../../tools/testing/dart/command.dart'; | 22 import '../../../tools/testing/dart/command.dart'; |
| 24 import '../../../tools/testing/dart/options.dart' as options; | 23 import '../../../tools/testing/dart/command_output.dart'; |
| 25 import '../../../tools/testing/dart/path.dart'; | 24 import '../../../tools/testing/dart/path.dart'; |
| 26 import '../../../tools/testing/dart/test_runner.dart' as runner; | 25 import '../../../tools/testing/dart/test_runner.dart' as runner; |
| 27 import '../../../tools/testing/dart/utils.dart'; | 26 import '../../../tools/testing/dart/utils.dart'; |
| 28 | 27 |
| 29 /** | 28 /** |
| 30 * This class is reponsible for setting up the files necessary for this test | 29 * This class is reponsible for setting up the files necessary for this test |
| 31 * as well as touching a file. | 30 * as well as touching a file. |
| 32 */ | 31 */ |
| 33 class FileUtils { | 32 class FileUtils { |
| 34 Directory tempDir; | 33 Directory tempDir; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 120 |
| 122 File _createFile(Path path) { | 121 File _createFile(Path path) { |
| 123 var file = new File(path.toNativePath()); | 122 var file = new File(path.toNativePath()); |
| 124 file.createSync(); | 123 file.createSync(); |
| 125 return file; | 124 return file; |
| 126 } | 125 } |
| 127 } | 126 } |
| 128 | 127 |
| 129 class CommandCompletedHandler { | 128 class CommandCompletedHandler { |
| 130 FileUtils fileUtils; | 129 FileUtils fileUtils; |
| 131 DateTime _expectedTimestamp; | |
| 132 bool _shouldHaveRun; | 130 bool _shouldHaveRun; |
| 133 | 131 |
| 134 CommandCompletedHandler(FileUtils this.fileUtils, bool this._shouldHaveRun); | 132 CommandCompletedHandler(FileUtils this.fileUtils, bool this._shouldHaveRun); |
| 135 | 133 |
| 136 void processCompletedTest(runner.CommandOutput output) { | 134 void processCompletedTest(CommandOutput output) { |
| 137 Expect.isTrue(output.exitCode == 0); | 135 Expect.isTrue(output.exitCode == 0); |
| 138 Expect.isTrue(output.stderr.length == 0); | 136 Expect.isTrue(output.stderr.length == 0); |
| 139 if (_shouldHaveRun) { | 137 if (_shouldHaveRun) { |
| 140 Expect.isTrue(output.stdout.length == 0); | 138 Expect.isTrue(output.stdout.length == 0); |
| 141 Expect.isTrue( | 139 Expect.isTrue( |
| 142 new File(fileUtils.scriptOutputPath.toNativePath()).existsSync()); | 140 new File(fileUtils.scriptOutputPath.toNativePath()).existsSync()); |
| 143 } else { | 141 } else { |
| 144 Expect.isFalse( | 142 Expect.isFalse( |
| 145 new File(fileUtils.scriptOutputPath.toNativePath()).existsSync()); | 143 new File(fileUtils.scriptOutputPath.toNativePath()).existsSync()); |
| 146 } | 144 } |
| 147 } | 145 } |
| 148 } | 146 } |
| 149 | 147 |
| 150 Command makeCompilationCommand(String testName, FileUtils fileUtils) { | 148 Command makeCompilationCommand(String testName, FileUtils fileUtils) { |
| 151 var config = new options.OptionsParser().parse(['--timeout', '2'])[0]; | |
| 152 var createFileScript = Platform.script | 149 var createFileScript = Platform.script |
| 153 .resolve('skipping_dart2js_compilations_helper.dart') | 150 .resolve('skipping_dart2js_compilations_helper.dart') |
| 154 .toFilePath(); | 151 .toFilePath(); |
| 155 var executable = Platform.executable; | 152 var executable = Platform.executable; |
| 156 var arguments = [createFileScript, fileUtils.scriptOutputPath.toNativePath()]; | 153 var arguments = [createFileScript, fileUtils.scriptOutputPath.toNativePath()]; |
| 157 var bootstrapDeps = [Uri.parse("file://${fileUtils.testSnapshotFilePath}")]; | 154 var bootstrapDeps = [Uri.parse("file://${fileUtils.testSnapshotFilePath}")]; |
| 158 return Command.compilation('dart2js', fileUtils.testJsFilePath.toNativePath(), | 155 return Command.compilation('dart2js', fileUtils.testJsFilePath.toNativePath(), |
| 159 false, bootstrapDeps, executable, arguments, {}); | 156 false, bootstrapDeps, executable, arguments, {}); |
| 160 } | 157 } |
| 161 | 158 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 207 |
| 211 void touchFilesAndRunTests() { | 208 void touchFilesAndRunTests() { |
| 212 fs_notUpToDate_snapshot.touchFile(fs_notUpToDate_snapshot.testSnapshot); | 209 fs_notUpToDate_snapshot.touchFile(fs_notUpToDate_snapshot.testSnapshot); |
| 213 fs_notUpToDate_dart.touchFile(fs_notUpToDate_dart.testDart); | 210 fs_notUpToDate_dart.touchFile(fs_notUpToDate_dart.testDart); |
| 214 fs_upToDate.touchFile(fs_upToDate.testJs); | 211 fs_upToDate.touchFile(fs_upToDate.testJs); |
| 215 | 212 |
| 216 Future runTest(String name, FileUtils fileUtils, bool shouldRun) { | 213 Future runTest(String name, FileUtils fileUtils, bool shouldRun) { |
| 217 var completedHandler = new CommandCompletedHandler(fileUtils, shouldRun); | 214 var completedHandler = new CommandCompletedHandler(fileUtils, shouldRun); |
| 218 var command = makeCompilationCommand(name, fileUtils); | 215 var command = makeCompilationCommand(name, fileUtils); |
| 219 var process = new runner.RunningProcess(command, 60); | 216 var process = new runner.RunningProcess(command, 60); |
| 220 return process.run().then((runner.CommandOutput output) { | 217 return process.run().then((CommandOutput output) { |
| 221 completedHandler.processCompletedTest(output); | 218 completedHandler.processCompletedTest(output); |
| 222 }); | 219 }); |
| 223 } | 220 } |
| 224 | 221 |
| 225 // We run the tests in sequence, so that if one of them failes we clean up | 222 // We run the tests in sequence, so that if one of them failes we clean up |
| 226 // everything and throw. | 223 // everything and throw. |
| 227 runTest("fs_noTestJs", fs_noTestJs, true).then((_) { | 224 runTest("fs_noTestJs", fs_noTestJs, true).then((_) { |
| 228 return runTest("fs_noTestJsDeps", fs_noTestJsDeps, true); | 225 return runTest("fs_noTestJsDeps", fs_noTestJsDeps, true); |
| 229 }).then((_) { | 226 }).then((_) { |
| 230 return runTest("fs_noTestDart", fs_noTestDart, true); | 227 return runTest("fs_noTestDart", fs_noTestDart, true); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 244 throw error; | 241 throw error; |
| 245 }).then((_) { | 242 }).then((_) { |
| 246 cleanup(); | 243 cleanup(); |
| 247 }); | 244 }); |
| 248 } | 245 } |
| 249 | 246 |
| 250 // We need to wait some time to make sure that the files we 'touch' get a | 247 // We need to wait some time to make sure that the files we 'touch' get a |
| 251 // bigger timestamp than the old ones | 248 // bigger timestamp than the old ones |
| 252 new Timer(new Duration(seconds: 1), touchFilesAndRunTests); | 249 new Timer(new Duration(seconds: 1), touchFilesAndRunTests); |
| 253 } | 250 } |
| OLD | NEW |