| 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 /* | 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) |
| 11 * - the dart2js snapshot | 11 * - the dart2js snapshot |
| 12 * Furtheremore it ensure that a compilations is not skipped if any of the | 12 * Furtheremore it ensure that a compilations is not skipped if any of the |
| 13 * necessary files could not be found (dart2js snapshots, previous dart2js | 13 * necessary files could not be found (dart2js snapshots, previous dart2js |
| 14 * output (+deps file), dart application) | 14 * output (+deps file), dart application) |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 import 'package:expect/expect.dart'; | 17 import 'package:expect/expect.dart'; |
| 18 import 'package:path/path.dart'; | 18 import 'package:path/path.dart'; |
| 19 import 'dart:async'; | 19 import 'dart:async'; |
| 20 import 'dart:convert'; |
| 20 import 'dart:io'; | 21 import 'dart:io'; |
| 21 import '../../../tools/testing/dart/test_suite.dart' as suite; | 22 import '../../../tools/testing/dart/test_suite.dart' as suite; |
| 22 import '../../../tools/testing/dart/test_runner.dart' as runner; | 23 import '../../../tools/testing/dart/test_runner.dart' as runner; |
| 23 import '../../../tools/testing/dart/test_options.dart' as options; | 24 import '../../../tools/testing/dart/test_options.dart' as options; |
| 24 import '../../../tools/testing/dart/status_file_parser.dart' as status; | 25 import '../../../tools/testing/dart/status_file_parser.dart' as status; |
| 25 import '../../../tools/testing/dart/utils.dart'; | 26 import '../../../tools/testing/dart/utils.dart'; |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * 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 |
| 29 * as well as touching a file. | 30 * as well as touching a file. |
| 30 */ | 31 */ |
| 31 class FileUtils { | 32 class FileUtils { |
| 32 Directory tempDir; | 33 Directory tempDir; |
| 33 File testJs; | 34 File testJs; |
| 34 File testJsDeps; | 35 File testJsDeps; |
| 35 File testDart; | 36 File testDart; |
| 36 File testSnapshot; | 37 File testSnapshot; |
| 38 File testCachedOutput; |
| 37 | 39 |
| 38 FileUtils({bool createJs, | 40 FileUtils({bool createJs, |
| 39 bool createJsDeps, | 41 bool createJsDeps, |
| 40 bool createDart, | 42 bool createDart, |
| 41 bool createSnapshot}) { | 43 bool createSnapshot, |
| 44 bool createCachedOutput}) { |
| 42 tempDir = Directory.systemTemp | 45 tempDir = Directory.systemTemp |
| 43 .createTempSync('dart_skipping_dart2js_compilations'); | 46 .createTempSync('dart_skipping_dart2js_compilations'); |
| 44 if (createJs) { | 47 if (createJs) { |
| 45 testJs = _createFile(testJsFilePath); | 48 testJs = _createFile(testJsFilePath); |
| 46 _writeToFile(testJs, "test.js content"); | 49 _writeToFile(testJs, "test.js content"); |
| 47 } | 50 } |
| 48 if (createSnapshot) { | 51 if (createSnapshot) { |
| 49 testSnapshot = _createFile(testSnapshotFilePath); | 52 testSnapshot = _createFile(testSnapshotFilePath); |
| 50 _writeToFile(testSnapshot, "dart2js snapshot"); | 53 _writeToFile(testSnapshot, "dart2js snapshot"); |
| 51 } | 54 } |
| 52 if (createDart) { | 55 if (createDart) { |
| 53 testDart = _createFile(testDartFilePath); | 56 testDart = _createFile(testDartFilePath); |
| 54 _writeToFile(testDart, "dart code"); | 57 _writeToFile(testDart, "dart code"); |
| 55 } | 58 } |
| 56 if (createJsDeps) { | 59 if (createJsDeps) { |
| 57 testJsDeps = _createFile(testJsDepsFilePath); | 60 testJsDeps = _createFile(testJsDepsFilePath); |
| 58 var path = suite.TestUtils.absolutePath(new Path(tempDir.path)) | 61 var path = suite.TestUtils.absolutePath(new Path(tempDir.path)) |
| 59 .append("test.dart"); | 62 .append("test.dart"); |
| 60 _writeToFile(testJsDeps, "file://$path"); | 63 _writeToFile(testJsDeps, "file://$path"); |
| 61 } | 64 } |
| 65 if (createCachedOutput) { |
| 66 testCachedOutput = _createFile(testCachedOutputPath); |
| 67 var content = JSON.encode({ |
| 68 'stdout': '', |
| 69 'stderr': '', |
| 70 'exitCode': 0, |
| 71 'timedOut': false |
| 72 }); |
| 73 _writeToFile(testCachedOutput, content); |
| 74 } |
| 75 |
| 62 } | 76 } |
| 63 | 77 |
| 64 void cleanup() { | 78 void cleanup() { |
| 65 if (testJs != null) testJs.deleteSync(); | 79 if (testJs != null) testJs.deleteSync(); |
| 66 if (testJsDeps != null) testJsDeps.deleteSync(); | 80 if (testJsDeps != null) testJsDeps.deleteSync(); |
| 67 if (testDart != null) testDart.deleteSync(); | 81 if (testDart != null) testDart.deleteSync(); |
| 68 if (testSnapshot != null) testSnapshot.deleteSync(); | 82 if (testSnapshot != null) testSnapshot.deleteSync(); |
| 83 if (testCachedOutput != null) testCachedOutput.deleteSync(); |
| 69 | 84 |
| 70 // if the script did run, it created this file, so we need to delete it | 85 // If the script did run, it created this file, so we need to delete it |
| 86 // We also need to delete the cached output which will always be there if |
| 87 // we ran. |
| 71 File file = new File(scriptOutputPath.toNativePath()); | 88 File file = new File(scriptOutputPath.toNativePath()); |
| 72 if (file.existsSync()) { | 89 if (file.existsSync()) { |
| 73 file.deleteSync(); | 90 file.deleteSync(); |
| 74 } | 91 } |
| 92 File cacheFile = new File(testCachedOutputPath.toNativePath()); |
| 93 if (cacheFile.existsSync()) { |
| 94 cacheFile.deleteSync(); |
| 95 } |
| 75 | 96 |
| 76 tempDir.deleteSync(); | 97 tempDir.deleteSync(); |
| 77 } | 98 } |
| 78 | 99 |
| 79 Path get scriptOutputPath { | 100 Path get scriptOutputPath { |
| 80 return suite.TestUtils.absolutePath(new Path(tempDir.path) | 101 return suite.TestUtils.absolutePath(new Path(tempDir.path) |
| 81 .append('created_if_command_did_run.txt')); | 102 .append('created_if_command_did_run.txt')); |
| 82 } | 103 } |
| 83 | 104 |
| 84 Path get testDartFilePath { | 105 Path get testDartFilePath { |
| 85 return suite.TestUtils.absolutePath(new Path(tempDir.path) | 106 return suite.TestUtils.absolutePath(new Path(tempDir.path) |
| 86 .append('test.dart')); | 107 .append('test.dart')); |
| 87 } | 108 } |
| 88 | 109 |
| 89 Path get testJsFilePath { | 110 Path get testJsFilePath { |
| 90 return suite.TestUtils.absolutePath(new Path(tempDir.path) | 111 return suite.TestUtils.absolutePath(new Path(tempDir.path) |
| 91 .append('test.js')); | 112 .append('test.js')); |
| 92 } | 113 } |
| 93 | 114 |
| 94 Path get testJsDepsFilePath { | 115 Path get testJsDepsFilePath { |
| 95 return suite.TestUtils.absolutePath(new Path(tempDir.path) | 116 return suite.TestUtils.absolutePath(new Path(tempDir.path) |
| 96 .append('test.js.deps')); | 117 .append('test.js.deps')); |
| 97 } | 118 } |
| 98 | 119 |
| 120 Path get testCachedOutputPath { |
| 121 return suite.TestUtils.absolutePath(new Path(tempDir.path) |
| 122 .append('test.js.cached_output')); |
| 123 } |
| 124 |
| 99 Path get testSnapshotFilePath { | 125 Path get testSnapshotFilePath { |
| 100 return suite.TestUtils.absolutePath(new Path(tempDir.path) | 126 return suite.TestUtils.absolutePath(new Path(tempDir.path) |
| 101 .append('test_dart2js.snapshot')); | 127 .append('test_dart2js.snapshot')); |
| 102 } | 128 } |
| 103 | 129 |
| 104 void touchFile(File file) { | 130 void touchFile(File file) { |
| 105 _writeToFile(file, _readFile(file)); | 131 _writeToFile(file, _readFile(file)); |
| 106 } | 132 } |
| 107 | 133 |
| 108 void _writeToFile(File file, String content) { | 134 void _writeToFile(File file, String content) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 127 | 153 |
| 128 class CommandCompletedHandler { | 154 class CommandCompletedHandler { |
| 129 FileUtils fileUtils; | 155 FileUtils fileUtils; |
| 130 DateTime _expectedTimestamp; | 156 DateTime _expectedTimestamp; |
| 131 bool _shouldHaveRun; | 157 bool _shouldHaveRun; |
| 132 | 158 |
| 133 CommandCompletedHandler(FileUtils this.fileUtils, bool this._shouldHaveRun); | 159 CommandCompletedHandler(FileUtils this.fileUtils, bool this._shouldHaveRun); |
| 134 | 160 |
| 135 void processCompletedTest(runner.CommandOutput output) { | 161 void processCompletedTest(runner.CommandOutput output) { |
| 136 Expect.isTrue(output.exitCode == 0); | 162 Expect.isTrue(output.exitCode == 0); |
| 163 if (output.stderr.length > 0) |
| 164 print(output.stderr); |
| 137 Expect.isTrue(output.stderr.length == 0); | 165 Expect.isTrue(output.stderr.length == 0); |
| 138 if (_shouldHaveRun) { | 166 if (_shouldHaveRun) { |
| 139 Expect.isTrue(output.stdout.length == 0); | 167 Expect.isTrue(output.stdout.length == 0); |
| 140 Expect.isTrue(new File(fileUtils.scriptOutputPath.toNativePath()) | 168 Expect.isTrue(new File(fileUtils.scriptOutputPath.toNativePath()) |
| 141 .existsSync()); | 169 .existsSync()); |
| 142 } else { | 170 } else { |
| 143 Expect.isFalse(new File(fileUtils.scriptOutputPath.toNativePath()) | 171 Expect.isFalse(new File(fileUtils.scriptOutputPath.toNativePath()) |
| 144 .existsSync()); | 172 .existsSync()); |
| 173 Expect.isTrue(new File(fileUtils.testCachedOutputPath.toNativePath()) |
| 174 .existsSync()); |
| 145 } | 175 } |
| 146 } | 176 } |
| 147 } | 177 } |
| 148 | 178 |
| 149 runner.Command makeCompilationCommand(String testName, FileUtils fileUtils) { | 179 runner.Command makeCompilationCommand(String testName, FileUtils fileUtils) { |
| 150 var config = new options.TestOptionsParser().parse(['--timeout', '2'])[0]; | 180 var config = new options.TestOptionsParser().parse(['--timeout', '2'])[0]; |
| 151 var createFileScript = Platform.script | 181 var createFileScript = Platform.script |
| 152 .resolve('skipping_dart2js_compilations_helper.dart').toFilePath(); | 182 .resolve('skipping_dart2js_compilations_helper.dart').toFilePath(); |
| 153 var executable = Platform.executable; | 183 var executable = Platform.executable; |
| 154 var arguments = [createFileScript, fileUtils.scriptOutputPath.toNativePath()]; | 184 var arguments = [createFileScript, fileUtils.scriptOutputPath.toNativePath()]; |
| 155 var bootstrapDeps = [ | 185 var bootstrapDeps = [ |
| 156 Uri.parse("file://${fileUtils.testSnapshotFilePath}")]; | 186 Uri.parse("file://${fileUtils.testSnapshotFilePath}")]; |
| 157 return runner.CommandBuilder.instance.getCompilationCommand( | 187 return runner.CommandBuilder.instance.getCompilationCommand( |
| 158 'dart2js', | 188 'dart2js', |
| 159 fileUtils.testJsFilePath.toNativePath(), | 189 fileUtils.testJsFilePath.toNativePath(), |
| 160 false, | 190 false, |
| 161 bootstrapDeps, | 191 bootstrapDeps, |
| 162 executable, | 192 executable, |
| 163 arguments, {}); | 193 arguments, {}); |
| 164 } | 194 } |
| 165 | 195 |
| 166 void main() { | 196 void main() { |
| 167 var fs_noTestJs = new FileUtils(createJs: false, | 197 var fs_noTestJs = new FileUtils(createJs: false, |
| 168 createJsDeps: true, | 198 createJsDeps: true, |
| 169 createDart: true, | 199 createDart: true, |
| 170 createSnapshot: true); | 200 createSnapshot: true, |
| 201 createCachedOutput: false); |
| 171 var fs_noTestJsDeps = new FileUtils(createJs: true, | 202 var fs_noTestJsDeps = new FileUtils(createJs: true, |
| 172 createJsDeps: false, | 203 createJsDeps: false, |
| 173 createDart: true, | 204 createDart: true, |
| 174 createSnapshot: true); | 205 createSnapshot: true, |
| 206 createCachedOutput: true); |
| 175 var fs_noTestDart = new FileUtils(createJs: true, | 207 var fs_noTestDart = new FileUtils(createJs: true, |
| 176 createJsDeps: true, | 208 createJsDeps: true, |
| 177 createDart: false, | 209 createDart: false, |
| 178 createSnapshot: true); | 210 createSnapshot: true, |
| 211 createCachedOutput: true); |
| 179 var fs_noTestSnapshot = new FileUtils(createJs: true, | 212 var fs_noTestSnapshot = new FileUtils(createJs: true, |
| 180 createJsDeps: true, | 213 createJsDeps: true, |
| 181 createDart: true, | 214 createDart: true, |
| 182 createSnapshot: false); | 215 createSnapshot: false, |
| 216 createCachedOutput: true); |
| 183 var fs_notUpToDate_snapshot = new FileUtils(createJs: true, | 217 var fs_notUpToDate_snapshot = new FileUtils(createJs: true, |
| 184 createJsDeps: true, | 218 createJsDeps: true, |
| 185 createDart: true, | 219 createDart: true, |
| 186 createSnapshot: true); | 220 createSnapshot: true, |
| 221 createCachedOutput: true); |
| 187 var fs_notUpToDate_dart = new FileUtils(createJs: true, | 222 var fs_notUpToDate_dart = new FileUtils(createJs: true, |
| 188 createJsDeps: true, | 223 createJsDeps: true, |
| 189 createDart: true, | 224 createDart: true, |
| 190 createSnapshot: true); | 225 createSnapshot: true, |
| 226 createCachedOutput: true); |
| 191 var fs_upToDate = new FileUtils(createJs: true, | 227 var fs_upToDate = new FileUtils(createJs: true, |
| 192 createJsDeps: true, | 228 createJsDeps: true, |
| 193 createDart: true, | 229 createDart: true, |
| 194 createSnapshot: true); | 230 createSnapshot: true, |
| 231 createCachedOutput: true); |
| 195 void cleanup() { | 232 void cleanup() { |
| 196 fs_noTestJs.cleanup(); | 233 fs_noTestJs.cleanup(); |
| 197 fs_noTestJsDeps.cleanup(); | 234 fs_noTestJsDeps.cleanup(); |
| 198 fs_noTestDart.cleanup(); | 235 fs_noTestDart.cleanup(); |
| 199 fs_noTestSnapshot.cleanup(); | 236 fs_noTestSnapshot.cleanup(); |
| 200 fs_notUpToDate_snapshot.cleanup(); | 237 fs_notUpToDate_snapshot.cleanup(); |
| 201 fs_notUpToDate_dart.cleanup(); | 238 fs_notUpToDate_dart.cleanup(); |
| 202 fs_upToDate.cleanup(); | 239 fs_upToDate.cleanup(); |
| 203 } | 240 } |
| 204 | 241 |
| 205 void touchFilesAndRunTests() { | 242 void touchFilesAndRunTests() { |
| 206 fs_notUpToDate_snapshot.touchFile(fs_notUpToDate_snapshot.testSnapshot); | 243 fs_notUpToDate_snapshot.touchFile(fs_notUpToDate_snapshot.testSnapshot); |
| 207 fs_notUpToDate_dart.touchFile(fs_notUpToDate_dart.testDart); | 244 fs_notUpToDate_dart.touchFile(fs_notUpToDate_dart.testDart); |
| 208 fs_upToDate.touchFile(fs_upToDate.testJs); | 245 fs_upToDate.touchFile(fs_upToDate.testJs); |
| 209 | 246 |
| 210 Future runTest(String name, FileUtils fileUtils, bool shouldRun) { | 247 Future runTest(String name, FileUtils fileUtils, bool shouldRun) { |
| 211 var completedHandler = new CommandCompletedHandler(fileUtils, shouldRun); | 248 var completedHandler = new CommandCompletedHandler(fileUtils, shouldRun); |
| 212 var command = makeCompilationCommand(name, fileUtils); | 249 var command = makeCompilationCommand(name, fileUtils); |
| 213 var process = new runner.RunningProcess(command, 60); | 250 var process = new runner.RunningProcess(command, 60); |
| 214 return process.run().then((runner.CommandOutput output) { | 251 return process.run().then((runner.CommandOutput output) { |
| 252 print(name); |
| 215 completedHandler.processCompletedTest(output); | 253 completedHandler.processCompletedTest(output); |
| 216 }); | 254 }); |
| 217 } | 255 } |
| 218 // We run the tests in sequence, so that if one of them failes we clean up | 256 // We run the tests in sequence, so that if one of them failes we clean up |
| 219 // everything and throw. | 257 // everything and throw. |
| 220 runTest("fs_noTestJs", fs_noTestJs, true).then((_) { | 258 runTest("fs_noTestJs", fs_noTestJs, true).then((_) { |
| 221 return runTest("fs_noTestJsDeps", fs_noTestJsDeps, true); | 259 return runTest("fs_noTestJsDeps", fs_noTestJsDeps, true); |
| 222 }).then((_) { | 260 }).then((_) { |
| 223 return runTest("fs_noTestDart", fs_noTestDart, true); | 261 return runTest("fs_noTestDart", fs_noTestDart, true); |
| 224 }).then((_) { | 262 }).then((_) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 236 cleanup(); | 274 cleanup(); |
| 237 throw error; | 275 throw error; |
| 238 }).then((_) { | 276 }).then((_) { |
| 239 cleanup(); | 277 cleanup(); |
| 240 }); | 278 }); |
| 241 } | 279 } |
| 242 // We need to wait some time to make sure that the files we 'touch' get a | 280 // We need to wait some time to make sure that the files we 'touch' get a |
| 243 // bigger timestamp than the old ones | 281 // bigger timestamp than the old ones |
| 244 new Timer(new Duration(seconds: 1), touchFilesAndRunTests); | 282 new Timer(new Duration(seconds: 1), touchFilesAndRunTests); |
| 245 } | 283 } |
| OLD | NEW |