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

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

Issue 1027193004: Respect top-level @TestOn declarations. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Add another test. Created 5 years, 9 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
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.load_exception; 5 library unittest.runner.load_exception;
6 6
7 import 'dart:isolate'; 7 import 'dart:isolate';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 import 'package:source_span/source_span.dart';
10 11
11 import '../utils.dart'; 12 import '../utils.dart';
12 13
13 class LoadException implements Exception { 14 class LoadException implements Exception {
14 final String path; 15 final String path;
15 16
16 final innerError; 17 final innerError;
17 18
18 LoadException(this.path, this.innerError); 19 LoadException(this.path, this.innerError);
19 20
20 String toString() { 21 String toString({bool color: false}) {
21 var buffer = new StringBuffer('Failed to load "$path":'); 22 var buffer = new StringBuffer();
23 if (color) buffer.write('\u001b[31m'); // red
24 buffer.write('Failed to load "$path":');
25 if (color) buffer.write('\u001b[0m'); // no color
22 26
23 var innerString = getErrorMessage(innerError); 27 var innerString = getErrorMessage(innerError);
24 if (innerError is IsolateSpawnException) { 28 if (innerError is IsolateSpawnException) {
25 // If this is a parse error, get rid of the noisy preamble. 29 // If this is a parse error, get rid of the noisy preamble.
26 innerString = innerString 30 innerString = innerString
27 .replaceFirst("'${p.toUri(p.absolute(path))}': error: ", ""); 31 .replaceFirst("'${p.toUri(p.absolute(path))}': error: ", "");
28 32
29 // If this is a file system error, get rid of both the preamble and the 33 // If this is a file system error, get rid of both the preamble and the
30 // useless stack trace. 34 // useless stack trace.
31 innerString = innerString.replaceFirst( 35 innerString = innerString.replaceFirst(
32 "Unhandled exception:\n" 36 "Unhandled exception:\n"
33 "Uncaught Error: Load Error: FileSystemException: ", 37 "Uncaught Error: Load Error: FileSystemException: ",
34 ""); 38 "");
35 innerString = innerString.split("Stack Trace:\n").first.trim(); 39 innerString = innerString.split("Stack Trace:\n").first.trim();
40 } if (innerError is SourceSpanException) {
41 innerString = innerError.toString(color: color)
42 .replaceFirst(" of $path", "");
36 } 43 }
37 44
38 buffer.write(innerString.contains("\n") ? "\n" : " "); 45 buffer.write(innerString.contains("\n") ? "\n" : " ");
39 buffer.write(innerString); 46 buffer.write(innerString);
40 return buffer.toString(); 47 return buffer.toString();
41 } 48 }
42 } 49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698