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

Side by Side Diff: tests/compiler/dart2js/sourcemaps/source_mapping_test_viewer.dart

Issue 1250633002: Add operators test to source_mapping_test. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Cleanup Created 5 years, 5 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 /// Visualization of source mappings generated and tested in
6 /// 'source_mapping_test.dart'.
7
8 library source_mapping.test.viewer;
9
10 import 'dart:async';
11 import 'package:compiler/src/filenames.dart';
12 import 'package:compiler/src/util/util.dart';
13 import 'source_mapping_test.dart';
14 import 'sourcemap_helper.dart';
15 import 'sourcemap_html_helper.dart';
16 import 'sourcemap_html_templates.dart';
17
18
19 main(List<String> arguments) async {
20 bool measure = false;
21 String outputPath = 'out.js.map.html';
karlklose 2015/07/22 09:06:48 Consider pulling this to toplevel as a constant.
Johnni Winther 2015/07/22 10:50:05 Done.
22 Set<String> configurations = new Set<String>();
23 Set<String> files = new Set<String>();
24 for (String argument in arguments) {
25 if (argument.startsWith('-')) {
26 if (argument == '-m') {
27 /// Measure instead of reporting the number of missing code points.
28 measure = true;
29 } else if (argument.startsWith('--out=')) {
30 /// Generate visualization for the first configuration.
31 outputPath = argument.substring('--out='.length);
32
33 } else if (argument.startsWith('-o')) {
34 /// Generate visualization for the first configuration.
35 outputPath = argument.substring('-o'.length);
36 } else {
37 print("Unknown option '$argument'.");
38 return;
39 }
40 } else {
41 if (TEST_CONFIGURATIONS.containsKey(argument)) {
karlklose 2015/07/22 09:06:48 Maybe you can share this argument parsing too.
Johnni Winther 2015/07/22 10:50:05 Done.
42 configurations.add(argument);
43 } else if (TEST_FILES.containsKey(argument)) {
44 files.add(argument);
45 } else {
46 print("Unknown configuration or file '$argument'. "
47 "Must be one of '${TEST_CONFIGURATIONS.keys.join("', '")}' or "
48 "'${TEST_FILES.keys.join("', '")}'.");
49 return;
50 }
51
52 }
53 }
54
55 if (configurations.isEmpty) {
56 configurations.addAll(TEST_CONFIGURATIONS.keys);
57 if (!measure) {
58 configurations.remove('old');
59 }
60 }
61 if (files.isEmpty) {
62 files.addAll(TEST_FILES.keys);
63 }
64
65 OutputConfigurations outputConfigurations =
66 new OutputConfigurations(configurations, files);
67 bool generateMultiConfigs = false;
68 if (outputPath != null) {
69 if (configurations.length > 1 || files.length > 1) {
70 for (String config in configurations) {
71 for (String file in files) {
72 String path = '$outputPath.$config.$file';
73 Uri uri = Uri.base.resolve(nativeToUriPath(path));
74 outputConfigurations.registerPathUri(config, file, path, uri);
75 }
76 }
77 generateMultiConfigs = true;
78 } else {
79 outputConfigurations.registerPathUri(
80 configurations.first,
81 files.first,
82 outputPath,
83 Uri.base.resolve(nativeToUriPath(outputPath)));
84 }
85 }
86
87 List<Measurement> measurements = <Measurement>[];
88 for (String config in configurations) {
89 List<String> options = TEST_CONFIGURATIONS[config];
90 for (String file in files) {
91 Measurement measurement = await runTest(
92 config, TEST_FILES[file], options,
93 outputUri: outputConfigurations.getUri(config, file),
94 verbose: !measure);
95 measurements.add(measurement);
96 }
97 }
98 for (Measurement measurement in measurements) {
99 print(measurement);
100 }
101 if (generateMultiConfigs) {
102 outputMultiConfigs(
103 Uri.base.resolve(outputPath),
104 outputConfigurations);
105 }
106 }
107
108 class OutputConfigurations implements Configurations {
109 final Iterable<String> configs;
110 final Iterable<String> files;
111 final Map<Pair, String> pathMap = {};
112 final Map<Pair, Uri> uriMap = {};
113
114 OutputConfigurations(this.configs, this.files);
115
116 void registerPathUri(String config, String file, String path, Uri uri) {
117 Pair key = new Pair(config, file);
118 pathMap[key] = path;
119 uriMap[key] = uri;
120 }
121
122 Uri getUri(String config, String file) {
123 Pair key = new Pair(config, file);
124 return uriMap[key];
125 }
126
127 @override
128 String getPath(String config, String file) {
129 Pair key = new Pair(config, file);
130 return pathMap[key];
131 }
132 }
133
134 Future<Measurement> runTest(
135 String config,
136 String filename,
137 List<String> options,
138 {Uri outputUri,
139 bool verbose}) async {
140 TestResult result =
141 await runTests(config, filename, options, verbose: verbose);
142 if (outputUri != null) {
143 if (result.failureMap.isNotEmpty) {
144 result.failureMap.forEach((info, missingCodePoints) {
145 print("Missing code points for ${info.element} in '$filename' "
146 "in config '$config':");
147 for (CodePoint codePoint in missingCodePoints) {
148 print(" $codePoint");
149 }
150 });
151 }
152 createTraceSourceMapHtml(outputUri, result.processor, result.userInfoList);
153 }
154 return new Measurement(config, filename,
155 result.failureMap.values.fold(0, (s, i) => s + i.length),
156 result.userInfoList.fold(0, (s, i) => s + i.codePoints.length));
157 }
158
159 class Measurement {
160 final String config;
161 final String filename;
162
163 final int missing;
164 final int count;
165
166 Measurement(this.config, this.filename, this.missing, this.count);
167
168 String toString() {
169 double percentage = 100 * missing / count;
170 return "Config '${config}', file: '${filename}': "
171 "$missing of $count ($percentage%) missing";
172 }
173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698