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

Side by Side Diff: lib/src/runner/parse_metadata.dart

Issue 1034813004: Add code to contextualize a span relative to its original source file. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Created 5 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 | lib/src/util/dart.dart » ('j') | 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) 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 library unittest.runner.parse_metadata; 5 library unittest.runner.parse_metadata;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 throw new SourceSpanFormatException( 89 throw new SourceSpanFormatException(
90 "TestOn takes a String.", _spanFor(args.first, path)); 90 "TestOn takes a String.", _spanFor(args.first, path));
91 } 91 }
92 92
93 if (testOn != null) { 93 if (testOn != null) {
94 throw new SourceSpanFormatException( 94 throw new SourceSpanFormatException(
95 "Only a single TestOn annotation may be used for a given test file.", 95 "Only a single TestOn annotation may be used for a given test file.",
96 _spanFor(annotation, path)); 96 _spanFor(annotation, path));
97 } 97 }
98 98
99 testOn = args.first.stringValue; 99 testOn = args.first;
100 } 100 }
101 101
102 return new Metadata.parse(testOn: testOn); 102 try {
103 return new Metadata.parse(
104 testOn: testOn == null ? null : testOn.stringValue);
105 } on SourceSpanFormatException catch (error) {
106 var file = new SourceFile(new File(path).readAsStringSync(),
107 url: p.toUri(path));
108 var span = contextualizeSpan(error.span, testOn, file);
109 if (span == null) rethrow;
110 throw new SourceSpanFormatException(error.message, span);
111 }
103 } 112 }
104 113
105 /// Creates a [SourceSpan] for [node]. 114 /// Creates a [SourceSpan] for [node].
106 SourceSpan _spanFor(AstNode node, String path) => 115 SourceSpan _spanFor(AstNode node, String path) =>
107 // Load a SourceFile from scratch here since we're only ever going to emit 116 // Load a SourceFile from scratch here since we're only ever going to emit
108 // one error per file anyway. 117 // one error per file anyway.
109 new SourceFile(new File(path).readAsStringSync(), url: p.toUri(path)) 118 new SourceFile(new File(path).readAsStringSync(), url: p.toUri(path))
110 .span(node.offset, node.end); 119 .span(node.offset, node.end);
OLDNEW
« no previous file with comments | « no previous file | lib/src/util/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698