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

Side by Side Diff: pkg/testing/lib/src/analyze.dart

Issue 2823293003: Parse escapes in analyzer machine output and handle Windows file names. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library testing.analyze; 5 library testing.analyze;
6 6
7 import 'dart:async' show Stream, Future; 7 import 'dart:async' show Stream, Future;
8 8
9 import 'dart:convert' show LineSplitter, UTF8; 9 import 'dart:convert' show LineSplitter, UTF8;
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 final Uri uri; 61 final Uri uri;
62 62
63 final int line; 63 final int line;
64 64
65 final int startColumn; 65 final int startColumn;
66 66
67 final int endColumn; 67 final int endColumn;
68 68
69 final String message; 69 final String message;
70 70
71 static final Pattern unescapePattern = new RegExp(r"\\(.)");
72
71 AnalyzerDiagnostic(this.kind, this.detailedKind, this.code, this.uri, 73 AnalyzerDiagnostic(this.kind, this.detailedKind, this.code, this.uri,
72 this.line, this.startColumn, this.endColumn, this.message); 74 this.line, this.startColumn, this.endColumn, this.message);
73 75
74 factory AnalyzerDiagnostic.fromLine(String line) { 76 factory AnalyzerDiagnostic.fromLine(String line) {
75 List<String> parts = line.split("|"); 77 List<String> parts = <String>[];
78 int start = 0;
79 int index = line.indexOf("|");
80 while (index != -1) {
81 if (index > 0 && line[index - 1] == "\\") {
ahe 2017/04/19 04:05:28 This is not correct for cases like this: \\|
82 index = line.indexOf("|", index + 1);
83 } else {
84 parts.add(line
85 .substring(start, index)
86 .replaceAllMapped(unescapePattern, (Match m) => m[1]));
87 start = index + 1;
88 index = line.indexOf("|", start);
89 }
90 }
91 parts.add(line
92 .substring(start)
93 .replaceAllMapped(unescapePattern, (Match m) => m[1]));
76 if (parts.length != 8) { 94 if (parts.length != 8) {
77 throw "Malformed output: $line"; 95 throw "Malformed output: $line $parts";
78 } 96 }
79 return new AnalyzerDiagnostic( 97 return new AnalyzerDiagnostic(
80 parts[0], 98 parts[0],
81 parts[1], 99 parts[1],
82 parts[2], 100 parts[2],
83 Uri.base.resolve(parts[3]), 101 Uri.base.resolveUri(new Uri.file(parts[3])),
84 int.parse(parts[4]), 102 int.parse(parts[4]),
85 int.parse(parts[5]), 103 int.parse(parts[5]),
86 int.parse(parts[6]), 104 int.parse(parts[6]),
87 parts[7]); 105 parts[7]);
88 } 106 }
89 107
90 String toString() { 108 String toString() {
91 return "$uri:$line:$startColumn: " 109 return "${uri.toFilePath()}:$line:$startColumn: "
92 "${kind == 'INFO' ? 'warning: hint' : kind.toLowerCase()}:\n" 110 "${kind == 'INFO' ? 'warning: hint' : kind.toLowerCase()}:\n"
93 "[$code] $message"; 111 "[$code] $message";
94 } 112 }
95 } 113 }
96 114
97 Stream<AnalyzerDiagnostic> parseAnalyzerOutput( 115 Stream<AnalyzerDiagnostic> parseAnalyzerOutput(
98 Stream<List<int>> stream) async* { 116 Stream<List<int>> stream) async* {
99 Stream<String> lines = 117 Stream<String> lines =
100 stream.transform(UTF8.decoder).transform(new LineSplitter()); 118 stream.transform(UTF8.decoder).transform(new LineSplitter());
101 await for (String line in lines) { 119 await for (String line in lines) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 hasOutput = true; 164 hasOutput = true;
147 print(message); 165 print(message);
148 } 166 }
149 } 167 }
150 if (hasOutput) { 168 if (hasOutput) {
151 throw "Non-empty output from analyzer."; 169 throw "Non-empty output from analyzer.";
152 } 170 }
153 sw.stop(); 171 sw.stop();
154 print("Running analyzer took: ${sw.elapsed}."); 172 print("Running analyzer took: ${sw.elapsed}.");
155 } 173 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698