Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 import 'dart:convert'; | |
| 7 import 'dart:io'; | |
| 8 | |
| 9 import 'package:async_helper/async_helper.dart'; | |
| 10 import 'package:compiler/compiler_new.dart'; | |
| 11 import 'package:compiler/src/apiimpl.dart'; | |
| 12 import 'package:compiler/src/commandline_options.dart'; | |
| 13 import 'package:compiler/src/dart2js.dart' as entry; | |
| 14 import 'package:expect/expect.dart'; | |
| 15 import 'package:source_maps/source_maps.dart'; | |
| 16 import 'package:source_maps/src/utils.dart'; | |
| 17 | |
| 18 import '../annotated_code_helper.dart'; | |
| 19 import '../memory_compiler.dart'; | |
| 20 import '../source_map_validator_helper.dart'; | |
| 21 | |
| 22 const List<String> TESTS = const <String>[ | |
| 23 ''' | |
| 24 main() {} | |
| 25 ''', | |
| 26 ]; | |
| 27 | |
| 28 void main(List<String> arguments) { | |
| 29 bool verbose = false; | |
| 30 bool writeJs = false; | |
| 31 List<int> indices; | |
| 32 for (String arg in arguments) { | |
|
Siggi Cherem (dart-lang)
2017/02/09 21:58:41
seems like a lot of this is in common with the oth
Johnni Winther
2017/02/10 08:59:04
Copied, but they tend to drift over time.
| |
| 33 if (arg == '-v') { | |
| 34 verbose = true; | |
| 35 } else if (arg == '--write-js') { | |
| 36 writeJs = true; | |
| 37 } else { | |
| 38 int index = int.parse(arg, onError: (_) => null); | |
| 39 if (index != null) { | |
| 40 indices ??= <int>[]; | |
| 41 if (index < 0 || index >= TESTS.length * 2) { | |
| 42 print('Index $index out of bounds: [0;${TESTS.length - 1}]'); | |
| 43 } else { | |
| 44 indices.add(index); | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 if (indices == null) { | |
| 50 indices = new List<int>.generate(TESTS.length * 2, (i) => i); | |
|
Siggi Cherem (dart-lang)
2017/02/09 21:58:41
nit: might be simpler to follow below if you do:
f
Johnni Winther
2017/02/10 08:59:04
The latter was the motivation!
| |
| 51 } | |
| 52 asyncTest(() async { | |
| 53 for (int index in indices) { | |
| 54 bool useNewSourceInfo = index % 2 == 1; | |
| 55 await runTest(index, TESTS[index ~/ 2], | |
| 56 writeJs: writeJs, | |
| 57 verbose: verbose, | |
| 58 useNewSourceInfo: useNewSourceInfo); | |
| 59 } | |
| 60 }); | |
| 61 } | |
| 62 | |
| 63 Future runTest(int index, String code, | |
| 64 {bool writeJs, bool verbose: false, bool useNewSourceInfo: false}) async { | |
| 65 print("--$index------------------------------------------------------------"); | |
| 66 print("Compiling dart2js ${useNewSourceInfo ? Flags.useNewSourceInfo : ''}\n" | |
| 67 "${code}"); | |
| 68 OutputCollector collector = new OutputCollector(); | |
| 69 List<String> options = <String>['--out=out.js', '--source-map=out.js.map']; | |
| 70 if (useNewSourceInfo) { | |
| 71 options.add(Flags.useNewSourceInfo); | |
| 72 } | |
| 73 CompilationResult compilationResult = await runCompiler( | |
| 74 entryPoint: Uri.parse('memory:main.dart'), | |
| 75 memorySourceFiles: {'main.dart': code}, | |
| 76 outputProvider: collector, | |
| 77 options: options); | |
| 78 Expect.isTrue(compilationResult.isSuccess, | |
| 79 "Unsuccessful compilation of test:\n${code}"); | |
| 80 String sourceMapText = collector.getOutput('', 'js.map'); | |
| 81 SingleMapping sourceMap = parse(sourceMapText); | |
| 82 if (writeJs) { | |
| 83 new File('out.js').writeAsStringSync(collector.getOutput('', 'js')); | |
| 84 new File('out.js.map').writeAsStringSync(sourceMapText); | |
| 85 } | |
| 86 Expect.isTrue(sourceMap.lines.isNotEmpty); | |
| 87 TargetLineEntry firstLineEntry = sourceMap.lines.first; | |
| 88 Expect.isTrue(firstLineEntry.entries.isNotEmpty); | |
| 89 TargetEntry firstEntry = firstLineEntry.entries.first; | |
| 90 Expect.isNull( | |
| 91 firstEntry.sourceUrlId, | |
| 92 "Unexpected first entry: " | |
| 93 "${entryToString(firstLineEntry, firstEntry, sourceMap)}"); | |
| 94 TargetLineEntry lastLineEntry = sourceMap.lines.last; | |
| 95 Expect.isTrue(lastLineEntry.entries.isNotEmpty); | |
| 96 TargetEntry lastEntry = firstLineEntry.entries.last; | |
| 97 Expect.isNull( | |
| 98 lastEntry.sourceUrlId, | |
| 99 "Unexpected last entry: " | |
| 100 "${entryToString(lastLineEntry, lastEntry, sourceMap)}"); | |
| 101 } | |
| 102 | |
| 103 String entryToString( | |
| 104 TargetLineEntry lineEntry, TargetEntry entry, SingleMapping mapping) { | |
| 105 StringBuffer sb = new StringBuffer(); | |
| 106 sb.write('[line='); | |
| 107 sb.write(lineEntry.line); | |
| 108 sb.write(',column='); | |
| 109 sb.write(entry.column); | |
| 110 sb.write(','); | |
| 111 if (entry.sourceUrlId != null) { | |
| 112 sb.write('sourceUrl='); | |
| 113 sb.write(mapping.urls[entry.sourceUrlId]); | |
| 114 sb.write(','); | |
| 115 } | |
| 116 if (entry.sourceNameId != null) { | |
| 117 sb.write('sourceName='); | |
| 118 sb.write(mapping.names[entry.sourceNameId]); | |
| 119 sb.write(','); | |
| 120 } | |
| 121 if (entry.sourceLine != null) { | |
| 122 sb.write('sourceLine='); | |
| 123 sb.write(entry.sourceLine); | |
| 124 sb.write(',sourceColumn='); | |
| 125 sb.write(entry.sourceColumn); | |
| 126 } | |
| 127 sb.write(']'); | |
| 128 return sb.toString(); | |
| 129 } | |
| OLD | NEW |