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