Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/standalone/io/test_skipping_dart2js_compilations.dart

Issue 11369216: Added support for skipping redundant dart2js compilations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #import("dart:io");
6 #import("dart:isolate");
7 #import("dart:uri");
8 #import("../../../tools/testing/dart/test_suite.dart");
9 #import("../../../tools/testing/dart/test_runner.dart");
10 #import("../../../tools/testing/dart/test_options.dart");
11 #import("../../../tools/testing/dart/status_file_parser.dart");
12
13 class FsUtils {
14 Directory tempDir;
15 File testJs;
16 File testJsDeps;
17 File testDart;
18 File testSnapshot;
19
20 FsUtils(bool createJs, bool createJsDeps, bool createDart,
21 bool createSnapshot) {
22 tempDir = new Directory('').createTempSync();
23 if (createJs) {
24 testJs = _createFile(testJsFilePath);
25 _writeToFile(testJs, "test.js content");
26 }
27 if (createSnapshot) {
28 testSnapshot = _createFile(testSnapshotFilePath);
29 _writeToFile(testSnapshot, "dart2js snapshot");
30 }
31 if (createDart) {
32 testDart = _createFile(testDartFilePath);
33 _writeToFile(testDart, "dart code");
34 }
35 if (createJsDeps) {
36 testJsDeps = _createFile(testJsDepsFilePath);
37 var path = TestUtils.absolutePath(new Path.fromNative(tempDir.path))
38 .append("test.dart");
39 _writeToFile(testJsDeps, "file://$path");
40 }
41 }
42
43 void cleanup() {
44 if (testJs != null) testJs.deleteSync();
45 if (testJsDeps != null) testJsDeps.deleteSync();
46 if (testDart != null) testDart.deleteSync();
47 if (testSnapshot != null) testSnapshot.deleteSync();
48
49 // if the script did run, it created this file, so we need to delete it
50 File file = new File.fromPath(scriptOutputPath);
51 if (file.existsSync()) {
52 file.deleteSync();
53 }
54
55 tempDir.deleteSync();
56 }
57
58 Path get scriptOutputPath {
59 return TestUtils.absolutePath(new Path.fromNative(tempDir.path)
60 .append('created_if_command_did_run.txt'));
61 }
62
63 Path get testDartFilePath {
64 return TestUtils.absolutePath(new Path.fromNative(tempDir.path)
65 .append('test.dart'));
66 }
67
68 Path get testJsFilePath {
69 return TestUtils.absolutePath(new Path.fromNative(tempDir.path)
70 .append('test.js'));
71 }
72
73 Path get testJsDepsFilePath {
74 return TestUtils.absolutePath(new Path.fromNative(tempDir.path)
75 .append('test.js.deps'));
76 }
77
78 Path get testSnapshotFilePath {
79 return TestUtils.absolutePath(new Path.fromNative(tempDir.path)
80 .append('test_dart2js.snapshot'));
81 }
82
83 void touchFile(File file) {
84 _writeToFile(file, _readFile(file));
85 }
86
87 void _writeToFile(File file, String content) {
88 if (content != null) {
89 var fd = new File(file.fullPathSync()).openSync(FileMode.WRITE);
90 fd.writeStringSync(content);
91 fd.closeSync();
92 }
93 }
94
95 String _readFile(File file) {
96 return file.readAsTextSync();
97 }
98
99 File _createFile(Path path) {
100 var file = new File.fromPath(path);
101 file.createSync();
102 return file;
103 }
104 }
105
106 class TestCompletedHandler {
107 FsUtils fsUtils;
108 Date _expectedTimestamp;
109 bool _shouldHaveRun;
110
111 TestCompletedHandler(FsUtils this.fsUtils, bool this._shouldHaveRun);
112
113 void processCompletedTest(TestCase testCase) {
114 TestOutput output = testCase.output;
115
116 Expect.isFalse(output.unexpectedOutput);
117 Expect.isTrue(output.stderr.length == 0);
118 if (_shouldHaveRun) {
119 Expect.isTrue(output.stdout.length == 0);
120 Expect.isTrue(new File.fromPath(fsUtils.scriptOutputPath).existsSync());
121 } else {
122 Expect.isFalse(new File.fromPath(fsUtils.scriptOutputPath).existsSync());
123 }
124 fsUtils.cleanup();
125 }
126 }
127
128 TestCase MakeTestCase(String testName, TestCompletedHandler completedHandler) {
129 var fsUtils = completedHandler.fsUtils;
130 var config = new TestOptionsParser().parse(['--timeout', '2'])[0];
131 var scriptDirPath = new Path.fromNative(new Options().script).directoryPath;
132 var createFileScript = scriptDirPath.
133 append('test_skipping_dart2js_compilation__helper.dart').toNativePath();
134 var executable = new Options().executable;
135 var arguments = [createFileScript, fsUtils.scriptOutputPath.toNativePath()];
136 var bootstrapDeps = [
137 new Uri("file://${fsUtils.testSnapshotFilePath}")];
138 var commands = [new Dart2JsCommand(fsUtils.testJsFilePath.toNativePath(),
139 false, bootstrapDeps, executable, arguments)];
140 return new TestCase(testName, commands, config,
141 completedHandler.processCompletedTest, new Set<String>.from([PASS]));
142 }
143
144 void main() {
145 var fs_noTestJs = new FsUtils(false, true, true, true);
146 var fs_noTestJsDeps = new FsUtils(true, false, true, true);
147 var fs_noTestDart = new FsUtils(true, true, false, true);
148 var fs_noTestSnapshot = new FsUtils(true, true, true, false);
149 var fs_notUpToDate_snapshot = new FsUtils(true, true, true, true);
150 var fs_notUpToDate_dart = new FsUtils(true, true, true, true);
151 var fs_upToDate = new FsUtils(true, true, true, true);
152
153 void touchFilesAndRunTests(Timer unused) {
154 fs_notUpToDate_snapshot.touchFile(fs_notUpToDate_snapshot.testSnapshot);
155 fs_notUpToDate_dart.touchFile(fs_notUpToDate_dart.testDart);
156 fs_upToDate.touchFile(fs_upToDate.testJs);
157
158 void runTest(String name, FsUtils fsUtils, bool shouldRun) {
159 new RunningProcess(MakeTestCase(name,
160 new TestCompletedHandler(fsUtils, shouldRun))).start();
161 }
162 runTest("fs_noTestJs", fs_noTestJs, true);
163 runTest("fs_noTestJsDeps", fs_noTestJsDeps, true);
164 runTest("fs_noTestDart", fs_noTestDart, true);
165 runTest("fs_noTestSnapshot", fs_noTestSnapshot, true);
166 runTest("fs_notUpToDate_snapshot", fs_notUpToDate_snapshot, true);
167 runTest("fs_notUpToDate_dart", fs_notUpToDate_dart, true);
168 // This is the only test where all dependencies are present and the test.js
169 // file is newer than all the others. So we pass 'false' for shouldRun.
170 runTest("fs_upToDate", fs_upToDate, false);
171 }
172 // We need to wait some time to make sure that the files we 'touch' get a
173 // bigger timestamp than the old ones
174 new Timer(1000, touchFilesAndRunTests);
175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698