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 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 Loading... |
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); |
OLD | NEW |