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

Side by Side Diff: pkg/front_end/lib/src/fasta/testing/validating_instrumentation.dart

Issue 2843103002: A couple of tweaks in ValidatingInstrumentation. (Closed)
Patch Set: Created 3 years, 7 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async'; 4 import 'dart:async';
5 import 'dart:convert'; 5 import 'dart:convert';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:front_end/src/base/instrumentation.dart'; 8 import 'package:front_end/src/base/instrumentation.dart';
9 import 'package:front_end/src/fasta/messages.dart'; 9 import 'package:front_end/src/fasta/messages.dart';
10 import 'package:front_end/src/fasta/scanner.dart'; 10 import 'package:front_end/src/fasta/scanner.dart';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 /// Indicates whether any expectation mismatches were found. 46 /// Indicates whether any expectation mismatches were found.
47 /// 47 ///
48 /// Should be called after [finish]. 48 /// Should be called after [finish].
49 bool get hasProblems => _problems.isNotEmpty; 49 bool get hasProblems => _problems.isNotEmpty;
50 50
51 /// Gets a description of all expectation mismatches that were found, in a 51 /// Gets a description of all expectation mismatches that were found, in a
52 /// form suitable for printing to the console. 52 /// form suitable for printing to the console.
53 /// 53 ///
54 /// Should be called after [finish]. 54 /// Should be called after [finish].
55 get problemsAsString => _problems.join('\n'); 55 String get problemsAsString => _problems.join('\n');
56 56
57 /// Checks whether the property/value pairs passed to [record] match the 57 /// Checks whether the property/value pairs passed to [record] match the
58 /// expectations loaded by [loadExpectations]. 58 /// expectations loaded by [loadExpectations].
59 void finish() { 59 void finish() {
60 _unsatisfiedExpectations.forEach((uri, expectationsForUri) { 60 _unsatisfiedExpectations.forEach((uri, expectationsForUri) {
61 expectationsForUri.forEach((offset, expectationsAtOffset) { 61 expectationsForUri.forEach((offset, expectationsAtOffset) {
62 for (var expectation in expectationsAtOffset) { 62 for (var expectation in expectationsAtOffset) {
63 _problem( 63 _problem(
64 uri, 64 uri,
65 offset, 65 offset,
66 'expected ${expectation.property}=${expectation.value}, ' 66 'expected ${expectation.property}=${expectation.value}, '
67 'got nothing', 67 'got nothing',
68 new _Fix( 68 new _Fix(
69 expectation.commentOffset, expectation.commentLength, '')); 69 expectation.commentOffset, expectation.commentLength, ''));
70 } 70 }
71 }); 71 });
72 }); 72 });
73 } 73 }
74 74
75 /// Updates the source file at [uri] based on the actual property/value 75 /// Updates the source file at [uri] based on the actual property/value
76 /// pairs that were observed. 76 /// pairs that were observed.
77 Future<Null> fixSource(Uri uri) async { 77 Future<Null> fixSource(Uri uri) async {
78 var fixes = _fixes[uri]; 78 var fixes = _fixes[uri];
79 if (fixes == null) return; 79 if (fixes == null) return;
80 var bytes = 80 File file = new File.fromUri(uri);
81 (await readBytesFromFile(uri, ensureZeroTermination: false)).toList(); 81 var bytes = await file.readAsBytes();
82 // Apply the fixes in reverse order so that offsets don't need to be 82 // Apply the fixes in reverse order so that offsets don't need to be
83 // adjusted after each fix. 83 // adjusted after each fix.
84 fixes.sort((a, b) => b.offset.compareTo(a.offset)); 84 fixes.sort((a, b) => b.offset.compareTo(a.offset));
85 for (var fix in fixes) { 85 for (var fix in fixes) {
86 bytes.replaceRange( 86 bytes.replaceRange(
87 fix.offset, fix.offset + fix.length, UTF8.encode(fix.replacement)); 87 fix.offset, fix.offset + fix.length, UTF8.encode(fix.replacement));
88 } 88 }
89 await new File.fromUri(uri).writeAsBytes(bytes); 89 await file.writeAsBytes(bytes);
90 } 90 }
91 91
92 /// Loads expectations from the source file located at [uri]. 92 /// Loads expectations from the source file located at [uri].
93 /// 93 ///
94 /// Should be called before [finish]. 94 /// Should be called before [finish].
95 Future<Null> loadExpectations(Uri uri) async { 95 Future<Null> loadExpectations(Uri uri) async {
96 var bytes = await readBytesFromFile(uri); 96 var bytes = await readBytesFromFile(uri);
97 var expectations = _unsatisfiedExpectations.putIfAbsent(uri, () => {}); 97 var expectations = _unsatisfiedExpectations.putIfAbsent(uri, () => {});
98 var testedFeaturesState = _testedFeaturesState.putIfAbsent(uri, () => {}); 98 var testedFeaturesState = _testedFeaturesState.putIfAbsent(uri, () => {});
99 ScannerResult result = scan(bytes, includeComments: true); 99 ScannerResult result = scan(bytes, includeComments: true);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 this.property, this.value, this.commentOffset, this.commentLength); 220 this.property, this.value, this.commentOffset, this.commentLength);
221 } 221 }
222 222
223 class _Fix { 223 class _Fix {
224 final int offset; 224 final int offset;
225 final int length; 225 final int length;
226 final String replacement; 226 final String replacement;
227 227
228 _Fix(this.offset, this.length, this.replacement); 228 _Fix(this.offset, this.length, this.replacement);
229 } 229 }
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