| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/compiler_new.dart'; | 10 import 'package:compiler/compiler_new.dart'; |
| 11 import 'package:compiler/src/apiimpl.dart'; | 11 import 'package:compiler/src/apiimpl.dart'; |
| 12 import 'package:compiler/src/commandline_options.dart'; | 12 import 'package:compiler/src/commandline_options.dart'; |
| 13 import 'package:compiler/src/dart2js.dart' as entry; | 13 import 'package:compiler/src/dart2js.dart' as entry; |
| 14 import 'package:expect/expect.dart'; | 14 import 'package:expect/expect.dart'; |
| 15 import 'package:source_maps/source_maps.dart'; | 15 import 'package:source_maps/source_maps.dart'; |
| 16 import 'package:source_maps/src/utils.dart'; | 16 import 'package:source_maps/src/utils.dart'; |
| 17 | 17 |
| 18 import '../annotated_code_helper.dart'; |
| 18 import '../source_map_validator_helper.dart'; | 19 import '../source_map_validator_helper.dart'; |
| 19 | 20 |
| 20 const String EXCEPTION_MARKER = '>ExceptionMarker<'; | 21 const String EXCEPTION_MARKER = '>ExceptionMarker<'; |
| 21 const String INPUT_FILE_NAME = 'in.dart'; | 22 const String INPUT_FILE_NAME = 'in.dart'; |
| 22 | 23 |
| 23 const List<String> TESTS = const <String>[ | 24 const List<String> TESTS = const <String>[ |
| 24 ''' | 25 ''' |
| 25 main() { | 26 main() { |
| 26 @{1:main}throw '$EXCEPTION_MARKER'; | 27 @{1:main}throw '$EXCEPTION_MARKER'; |
| 27 } | 28 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 final List<StackTraceLine> unexpectedLines; | 178 final List<StackTraceLine> unexpectedLines; |
| 178 | 179 |
| 179 Test(this.code, this.expectedLines, this.unexpectedLines); | 180 Test(this.code, this.expectedLines, this.unexpectedLines); |
| 180 } | 181 } |
| 181 | 182 |
| 182 const int _LF = 0x0A; | 183 const int _LF = 0x0A; |
| 183 const int _CR = 0x0D; | 184 const int _CR = 0x0D; |
| 184 const int _LBRACE = 0x7B; | 185 const int _LBRACE = 0x7B; |
| 185 | 186 |
| 186 Test processTestCode(String code) { | 187 Test processTestCode(String code) { |
| 187 StringBuffer codeBuffer = new StringBuffer(); | |
| 188 Map<int, StackTraceLine> stackTraceMap = <int, StackTraceLine>{}; | 188 Map<int, StackTraceLine> stackTraceMap = <int, StackTraceLine>{}; |
| 189 List<StackTraceLine> unexpectedLines = <StackTraceLine>[]; | 189 List<StackTraceLine> unexpectedLines = <StackTraceLine>[]; |
| 190 int index = 0; | 190 AnnotatedCode annotatedCode = new AnnotatedCode(code); |
| 191 int lineNo = 1; | 191 for (Annotation annotation in annotatedCode.annotations) { |
| 192 int columnNo = 1; | 192 int colonIndex = annotation.text.indexOf(':'); |
| 193 while (index < code.length) { | 193 String indexText = annotation.text.substring(0, colonIndex); |
| 194 int charCode = code.codeUnitAt(index); | 194 String methodName = annotation.text.substring(colonIndex + 1); |
| 195 switch (charCode) { | 195 StackTraceLine stackTraceLine = new StackTraceLine( |
| 196 case _LF: | 196 methodName, INPUT_FILE_NAME, annotation.lineNo, annotation.columnNo); |
| 197 codeBuffer.write('\n'); | 197 if (indexText == '') { |
| 198 lineNo++; | 198 unexpectedLines.add(stackTraceLine); |
| 199 columnNo = 1; | 199 } else { |
| 200 break; | 200 int stackTraceIndex = int.parse(indexText); |
| 201 case _CR: | 201 assert(!stackTraceMap.containsKey(stackTraceIndex)); |
| 202 if (index + 1 < code.length && code.codeUnitAt(index + 1) == _LF) { | 202 stackTraceMap[stackTraceIndex] = stackTraceLine; |
| 203 index++; | |
| 204 } | |
| 205 codeBuffer.write('\n'); | |
| 206 lineNo++; | |
| 207 columnNo = 1; | |
| 208 break; | |
| 209 case 0x40: | |
| 210 if (index + 1 < code.length && code.codeUnitAt(index + 1) == _LBRACE) { | |
| 211 int colonIndex = code.indexOf(':', index); | |
| 212 int endIndex = code.indexOf('}', index); | |
| 213 String methodName = code.substring(colonIndex + 1, endIndex); | |
| 214 String indexText = code.substring(index + 2, colonIndex); | |
| 215 StackTraceLine stackTraceLine = | |
| 216 new StackTraceLine(methodName, INPUT_FILE_NAME, lineNo, columnNo); | |
| 217 if (indexText == '') { | |
| 218 unexpectedLines.add(stackTraceLine); | |
| 219 } else { | |
| 220 int stackTraceIndex = int.parse(indexText); | |
| 221 assert(!stackTraceMap.containsKey(stackTraceIndex)); | |
| 222 stackTraceMap[stackTraceIndex] = stackTraceLine; | |
| 223 } | |
| 224 index = endIndex; | |
| 225 } else { | |
| 226 codeBuffer.writeCharCode(charCode); | |
| 227 columnNo++; | |
| 228 } | |
| 229 break; | |
| 230 default: | |
| 231 codeBuffer.writeCharCode(charCode); | |
| 232 columnNo++; | |
| 233 } | 203 } |
| 234 index++; | |
| 235 } | 204 } |
| 236 List<StackTraceLine> expectedLines = <StackTraceLine>[]; | 205 List<StackTraceLine> expectedLines = <StackTraceLine>[]; |
| 237 for (int stackTraceIndex in (stackTraceMap.keys.toList()..sort()).reversed) { | 206 for (int stackTraceIndex in (stackTraceMap.keys.toList()..sort()).reversed) { |
| 238 expectedLines.add(stackTraceMap[stackTraceIndex]); | 207 expectedLines.add(stackTraceMap[stackTraceIndex]); |
| 239 } | 208 } |
| 240 return new Test(codeBuffer.toString(), expectedLines, unexpectedLines); | 209 return new Test(annotatedCode.sourceCode, expectedLines, unexpectedLines); |
| 241 } | 210 } |
| 242 | 211 |
| 243 void main(List<String> arguments) { | 212 void main(List<String> arguments) { |
| 244 bool verbose = false; | 213 bool verbose = false; |
| 245 bool printJs = false; | 214 bool printJs = false; |
| 246 List<int> indices; | 215 List<int> indices; |
| 247 for (String arg in arguments) { | 216 for (String arg in arguments) { |
| 248 if (arg == '-v') { | 217 if (arg == '-v') { |
| 249 verbose = true; | 218 verbose = true; |
| 250 } else if (arg == '--print-js') { | 219 } else if (arg == '--print-js') { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 String get d8executable { | 464 String get d8executable { |
| 496 if (Platform.isWindows) { | 465 if (Platform.isWindows) { |
| 497 return 'third_party/d8/windows/d8.exe'; | 466 return 'third_party/d8/windows/d8.exe'; |
| 498 } else if (Platform.isLinux) { | 467 } else if (Platform.isLinux) { |
| 499 return 'third_party/d8/linux/d8'; | 468 return 'third_party/d8/linux/d8'; |
| 500 } else if (Platform.isMacOS) { | 469 } else if (Platform.isMacOS) { |
| 501 return 'third_party/d8/macos/d8'; | 470 return 'third_party/d8/macos/d8'; |
| 502 } | 471 } |
| 503 throw new UnsupportedError('Unsupported platform.'); | 472 throw new UnsupportedError('Unsupported platform.'); |
| 504 } | 473 } |
| OLD | NEW |