OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library trydart.incremental_compilation_update_test; | 5 library trydart.incremental_compilation_update_test; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html' hide |
| 8 Element; |
8 | 9 |
9 import 'dart:async' show | 10 import 'dart:async' show |
10 Future; | 11 Future; |
11 | 12 |
12 import 'package:async_helper/async_helper.dart' show | 13 import 'package:async_helper/async_helper.dart' show |
13 asyncTest; | 14 asyncTest; |
14 | 15 |
| 16 import 'package:expect/expect.dart' show |
| 17 Expect; |
| 18 |
15 import 'package:try/src/interaction_manager.dart' show | 19 import 'package:try/src/interaction_manager.dart' show |
16 splitLines; | 20 splitLines; |
17 | 21 |
| 22 import 'package:try/poi/scope_information_visitor.dart' show |
| 23 ScopeInformationVisitor; |
| 24 |
18 import 'sandbox.dart' show | 25 import 'sandbox.dart' show |
19 appendIFrame, | 26 appendIFrame, |
20 listener; | 27 listener; |
21 | 28 |
22 import 'web_compiler_test_case.dart' show | 29 import 'web_compiler_test_case.dart' show |
23 WebCompilerTestCase, | 30 WebCompilerTestCase, |
24 WebInputProvider; | 31 WebInputProvider; |
25 | 32 |
| 33 import '../poi/compiler_test_case.dart' show |
| 34 CompilerTestCase; |
| 35 |
| 36 import 'package:compiler/src/elements/elements.dart' show |
| 37 Element, |
| 38 LibraryElement; |
| 39 |
| 40 import 'package:compiler/src/dart2jslib.dart' show |
| 41 Compiler; |
| 42 |
26 import 'program_result.dart'; | 43 import 'program_result.dart'; |
27 | 44 |
28 const int TIMEOUT = 100; | 45 const int TIMEOUT = 100; |
29 | 46 |
30 const List<List<ProgramResult>> tests = const <List<ProgramResult>>[ | 47 const List<List<ProgramResult>> tests = const <List<ProgramResult>>[ |
31 // Basic hello-world test. | 48 // Basic hello-world test. |
32 const <ProgramResult>[ | 49 const <ProgramResult>[ |
33 const ProgramResult( | 50 const ProgramResult( |
34 "main() { print('Hello, World!'); }", | 51 "main() { print('Hello, World!'); }", |
35 const <String> ['Hello, World!']), | 52 const <String> ['Hello, World!']), |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 test.incrementalCompiler.inputProvider; | 1120 test.incrementalCompiler.inputProvider; |
1104 Uri uri = test.scriptUri.resolve('?v${version++}'); | 1121 Uri uri = test.scriptUri.resolve('?v${version++}'); |
1105 inputProvider.cachedSources[uri] = new Future.value(program.code); | 1122 inputProvider.cachedSources[uri] = new Future.value(program.code); |
1106 Future future = test.incrementalCompiler.compileUpdates( | 1123 Future future = test.incrementalCompiler.compileUpdates( |
1107 {test.scriptUri: uri}, logVerbose: logger, logTime: logger); | 1124 {test.scriptUri: uri}, logVerbose: logger, logTime: logger); |
1108 return future.then((String update) { | 1125 return future.then((String update) { |
1109 print({'update': update}); | 1126 print({'update': update}); |
1110 iframe.contentWindow.postMessage(['apply-update', update], '*'); | 1127 iframe.contentWindow.postMessage(['apply-update', update], '*'); |
1111 | 1128 |
1112 return listener.expect( | 1129 return listener.expect( |
1113 program.messagesWith('iframe-dart-updated-main-done')); | 1130 program.messagesWith('iframe-dart-updated-main-done')) |
| 1131 .then((_) { |
| 1132 return new SerializeScopeTestCase( |
| 1133 program.code, test.incrementalCompiler.mainApp, |
| 1134 test.incrementalCompiler.compiler).run(); |
| 1135 }); |
1114 }); | 1136 }); |
1115 }); | 1137 }); |
1116 }); | 1138 }); |
1117 }); | 1139 }); |
1118 }).then((_) { | 1140 }).then((_) { |
1119 status.style.color = 'limegreen'; | 1141 status.style.color = 'limegreen'; |
1120 | 1142 |
1121 // Remove the iframe to work around a bug in test.dart. | 1143 // Remove the iframe to work around a bug in test.dart. |
1122 iframe.remove(); | 1144 iframe.remove(); |
1123 }); | 1145 }); |
1124 } | 1146 } |
1125 | 1147 |
| 1148 class SerializeScopeTestCase extends CompilerTestCase { |
| 1149 final String scopeInfo; |
| 1150 |
| 1151 SerializeScopeTestCase( |
| 1152 String source, |
| 1153 LibraryElement library, |
| 1154 Compiler compiler) |
| 1155 : scopeInfo = computeScopeInfo(compiler, library), |
| 1156 super(source, '${library.canonicalUri}'); |
| 1157 |
| 1158 Future run() => mainApp.then(checkScopes); |
| 1159 |
| 1160 void checkScopes(LibraryElement library) { |
| 1161 Expect.stringEquals(computeScopeInfo(compiler, library), scopeInfo); |
| 1162 } |
| 1163 |
| 1164 static String computeScopeInfo(Compiler compiler, LibraryElement library) { |
| 1165 ScopeInformationVisitor visitor = |
| 1166 new ScopeInformationVisitor(compiler, library, 0); |
| 1167 |
| 1168 visitor.ignoreImports = true; |
| 1169 visitor.sortMembers = true; |
| 1170 visitor.indented.write('[\n'); |
| 1171 visitor.indentationLevel++; |
| 1172 visitor.indented; |
| 1173 library.accept(visitor); |
| 1174 library.forEachLocalMember((Element member) { |
| 1175 if (member.isClass) { |
| 1176 visitor.buffer.write(',\n'); |
| 1177 visitor.indented; |
| 1178 member.accept(visitor); |
| 1179 } |
| 1180 }); |
| 1181 visitor.buffer.write('\n'); |
| 1182 visitor.indentationLevel--; |
| 1183 visitor.indented.write(']'); |
| 1184 return '${visitor.buffer}'; |
| 1185 } |
| 1186 } |
| 1187 |
1126 void logger(x) { | 1188 void logger(x) { |
1127 print(x); | 1189 print(x); |
1128 bool isCheckedMode = false; | 1190 bool isCheckedMode = false; |
1129 assert(isCheckedMode = true); | 1191 assert(isCheckedMode = true); |
1130 int timeout = isCheckedMode ? TIMEOUT * 2 : TIMEOUT; | 1192 int timeout = isCheckedMode ? TIMEOUT * 2 : TIMEOUT; |
1131 if (listener.elapsed > timeout) { | 1193 if (listener.elapsed > timeout) { |
1132 throw 'Test timed out.'; | 1194 throw 'Test timed out.'; |
1133 } | 1195 } |
1134 } | 1196 } |
1135 | 1197 |
1136 Element numberedLines(String code) { | 1198 DivElement numberedLines(String code) { |
1137 DivElement result = new DivElement(); | 1199 DivElement result = new DivElement(); |
1138 result.classes.add("output"); | 1200 result.classes.add("output"); |
1139 | 1201 |
1140 for (String text in splitLines(code)) { | 1202 for (String text in splitLines(code)) { |
1141 Element line = new PreElement() | 1203 PreElement line = new PreElement() |
1142 ..appendText(text.trimRight()) | 1204 ..appendText(text.trimRight()) |
1143 ..classes.add("line"); | 1205 ..classes.add("line"); |
1144 result.append(line); | 1206 result.append(line); |
1145 } | 1207 } |
1146 | 1208 |
1147 return result; | 1209 return result; |
1148 } | 1210 } |
1149 | 1211 |
1150 | 1212 |
1151 StyleElement lineNumberStyle() { | 1213 StyleElement lineNumberStyle() { |
(...skipping 21 matching lines...) Expand all Loading... |
1173 position: absolute; | 1235 position: absolute; |
1174 left: 0px; | 1236 left: 0px; |
1175 width: 3em; | 1237 width: 3em; |
1176 text-align: right; | 1238 text-align: right; |
1177 background-color: lightgoldenrodyellow; | 1239 background-color: lightgoldenrodyellow; |
1178 } | 1240 } |
1179 '''); | 1241 '''); |
1180 style.type = 'text/css'; | 1242 style.type = 'text/css'; |
1181 return style; | 1243 return style; |
1182 } | 1244 } |
OLD | NEW |