| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 /// Visualization of source mappings generated and tested in | 5 /// Visualization of source mappings generated and tested in |
| 6 /// 'source_mapping_test.dart'. | 6 /// 'source_mapping_test.dart'. |
| 7 | 7 |
| 8 library source_mapping.test.viewer; | 8 library source_mapping.test.viewer; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 Set<String> configurations = new Set<String>(); | 23 Set<String> configurations = new Set<String>(); |
| 24 Set<String> files = new Set<String>(); | 24 Set<String> files = new Set<String>(); |
| 25 for (String argument in arguments) { | 25 for (String argument in arguments) { |
| 26 if (argument.startsWith('-')) { | 26 if (argument.startsWith('-')) { |
| 27 if (argument == '-m') { | 27 if (argument == '-m') { |
| 28 /// Measure instead of reporting the number of missing code points. | 28 /// Measure instead of reporting the number of missing code points. |
| 29 measure = true; | 29 measure = true; |
| 30 } else if (argument.startsWith('--out=')) { | 30 } else if (argument.startsWith('--out=')) { |
| 31 /// Generate visualization for the first configuration. | 31 /// Generate visualization for the first configuration. |
| 32 outputPath = argument.substring('--out='.length); | 32 outputPath = argument.substring('--out='.length); |
| 33 | |
| 34 } else if (argument.startsWith('-o')) { | 33 } else if (argument.startsWith('-o')) { |
| 35 /// Generate visualization for the first configuration. | 34 /// Generate visualization for the first configuration. |
| 36 outputPath = argument.substring('-o'.length); | 35 outputPath = argument.substring('-o'.length); |
| 37 } else { | 36 } else { |
| 38 print("Unknown option '$argument'."); | 37 print("Unknown option '$argument'."); |
| 39 return; | 38 return; |
| 40 } | 39 } |
| 41 } else { | 40 } else { |
| 42 if (!parseArgument(argument, configurations, files)) { | 41 if (!parseArgument(argument, configurations, files)) { |
| 43 return; | 42 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 62 if (configurations.length > 1 || files.length > 1) { | 61 if (configurations.length > 1 || files.length > 1) { |
| 63 for (String config in configurations) { | 62 for (String config in configurations) { |
| 64 for (String file in files) { | 63 for (String file in files) { |
| 65 String path = '$outputPath.$config.$file'; | 64 String path = '$outputPath.$config.$file'; |
| 66 Uri uri = Uri.base.resolve(nativeToUriPath(path)); | 65 Uri uri = Uri.base.resolve(nativeToUriPath(path)); |
| 67 outputConfigurations.registerPathUri(config, file, path, uri); | 66 outputConfigurations.registerPathUri(config, file, path, uri); |
| 68 } | 67 } |
| 69 } | 68 } |
| 70 generateMultiConfigs = true; | 69 generateMultiConfigs = true; |
| 71 } else { | 70 } else { |
| 72 outputConfigurations.registerPathUri( | 71 outputConfigurations.registerPathUri(configurations.first, files.first, |
| 73 configurations.first, | 72 outputPath, Uri.base.resolve(nativeToUriPath(outputPath))); |
| 74 files.first, | |
| 75 outputPath, | |
| 76 Uri.base.resolve(nativeToUriPath(outputPath))); | |
| 77 } | 73 } |
| 78 } | 74 } |
| 79 | 75 |
| 80 List<Measurement> measurements = <Measurement>[]; | 76 List<Measurement> measurements = <Measurement>[]; |
| 81 for (String config in configurations) { | 77 for (String config in configurations) { |
| 82 List<String> options = TEST_CONFIGURATIONS[config]; | 78 List<String> options = TEST_CONFIGURATIONS[config]; |
| 83 for (String file in files) { | 79 for (String file in files) { |
| 84 Measurement measurement = await runTest( | 80 Measurement measurement = await runTest(config, TEST_FILES[file], options, |
| 85 config, TEST_FILES[file], options, | |
| 86 outputUri: outputConfigurations.getUri(config, file), | 81 outputUri: outputConfigurations.getUri(config, file), |
| 87 verbose: !measure); | 82 verbose: !measure); |
| 88 measurements.add(measurement); | 83 measurements.add(measurement); |
| 89 } | 84 } |
| 90 } | 85 } |
| 91 for (Measurement measurement in measurements) { | 86 for (Measurement measurement in measurements) { |
| 92 print(measurement); | 87 print(measurement); |
| 93 } | 88 } |
| 94 if (generateMultiConfigs) { | 89 if (generateMultiConfigs) { |
| 95 outputMultiConfigs( | 90 outputMultiConfigs(Uri.base.resolve(outputPath), outputConfigurations); |
| 96 Uri.base.resolve(outputPath), | |
| 97 outputConfigurations); | |
| 98 } | 91 } |
| 99 } | 92 } |
| 100 | 93 |
| 101 class OutputConfigurations implements Configurations { | 94 class OutputConfigurations implements Configurations { |
| 102 final Iterable<String> configs; | 95 final Iterable<String> configs; |
| 103 final Iterable<String> files; | 96 final Iterable<String> files; |
| 104 final Map<Pair, String> pathMap = {}; | 97 final Map<Pair, String> pathMap = {}; |
| 105 final Map<Pair, Uri> uriMap = {}; | 98 final Map<Pair, Uri> uriMap = {}; |
| 106 | 99 |
| 107 OutputConfigurations(this.configs, this.files); | 100 OutputConfigurations(this.configs, this.files); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 118 } | 111 } |
| 119 | 112 |
| 120 @override | 113 @override |
| 121 String getPath(String config, String file) { | 114 String getPath(String config, String file) { |
| 122 Pair key = new Pair(config, file); | 115 Pair key = new Pair(config, file); |
| 123 return pathMap[key]; | 116 return pathMap[key]; |
| 124 } | 117 } |
| 125 } | 118 } |
| 126 | 119 |
| 127 Future<Measurement> runTest( | 120 Future<Measurement> runTest( |
| 128 String config, | 121 String config, String filename, List<String> options, |
| 129 String filename, | 122 {Uri outputUri, bool verbose}) async { |
| 130 List<String> options, | |
| 131 {Uri outputUri, | |
| 132 bool verbose}) async { | |
| 133 TestResult result = | 123 TestResult result = |
| 134 await runTests(config, filename, options, verbose: verbose); | 124 await runTests(config, filename, options, verbose: verbose); |
| 135 if (outputUri != null) { | 125 if (outputUri != null) { |
| 136 if (result.missingCodePointsMap.isNotEmpty) { | 126 if (result.missingCodePointsMap.isNotEmpty) { |
| 137 result.printMissingCodePoints(); | 127 result.printMissingCodePoints(); |
| 138 } | 128 } |
| 139 if (result.multipleNodesMap.isNotEmpty) { | 129 if (result.multipleNodesMap.isNotEmpty) { |
| 140 result.printMultipleNodes(); | 130 result.printMultipleNodes(); |
| 141 } | 131 } |
| 142 if (result.multipleOffsetsMap.isNotEmpty) { | 132 if (result.multipleOffsetsMap.isNotEmpty) { |
| 143 result.printMultipleOffsets(); | 133 result.printMultipleOffsets(); |
| 144 } | 134 } |
| 145 createTraceSourceMapHtml(outputUri, result.processor, result.userInfoList); | 135 createTraceSourceMapHtml(outputUri, result.processor, result.userInfoList); |
| 146 } | 136 } |
| 147 return new Measurement(config, filename, | 137 return new Measurement( |
| 138 config, |
| 139 filename, |
| 148 result.missingCodePointsMap.values.fold(0, (s, i) => s + i.length), | 140 result.missingCodePointsMap.values.fold(0, (s, i) => s + i.length), |
| 149 result.userInfoList.fold(0, (s, i) => s + i.codePoints.length)); | 141 result.userInfoList.fold(0, (s, i) => s + i.codePoints.length)); |
| 150 } | 142 } |
| 151 | 143 |
| 152 class Measurement { | 144 class Measurement { |
| 153 final String config; | 145 final String config; |
| 154 final String filename; | 146 final String filename; |
| 155 | 147 |
| 156 final int missing; | 148 final int missing; |
| 157 final int count; | 149 final int count; |
| 158 | 150 |
| 159 Measurement(this.config, this.filename, this.missing, this.count); | 151 Measurement(this.config, this.filename, this.missing, this.count); |
| 160 | 152 |
| 161 String toString() { | 153 String toString() { |
| 162 double percentage = 100 * missing / count; | 154 double percentage = 100 * missing / count; |
| 163 return "Config '${config}', file: '${filename}': " | 155 return "Config '${config}', file: '${filename}': " |
| 164 "$missing of $count ($percentage%) missing"; | 156 "$missing of $count ($percentage%) missing"; |
| 165 } | 157 } |
| 166 } | 158 } |
| OLD | NEW |