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

Side by Side Diff: lib/src/utils.dart

Issue 1036943002: Add a testOn parameter to test() and group(). (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: 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
« no previous file with comments | « lib/src/runner/vm/isolate_test.dart ('k') | lib/unittest.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.utils; 5 library unittest.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:path/path.dart' as p;
9 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
10 11
12 import 'backend/operating_system.dart';
13
11 /// A typedef for a possibly-asynchronous function. 14 /// A typedef for a possibly-asynchronous function.
12 /// 15 ///
13 /// The return type should only ever by [Future] or void. 16 /// The return type should only ever by [Future] or void.
14 typedef AsyncFunction(); 17 typedef AsyncFunction();
15 18
16 /// A regular expression to match the exception prefix that some exceptions' 19 /// A regular expression to match the exception prefix that some exceptions'
17 /// [Object.toString] values contain. 20 /// [Object.toString] values contain.
18 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); 21 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): ');
19 22
23 /// Directories that are specific to OS X.
24 ///
25 /// This is used to try to distinguish OS X and Linux in [currentOsGuess].
26 final _macOsDirectories = new Set<String>.from([
27 "/Applications",
28 "/Library",
29 "/Network",
30 "/System",
31 "/Users"
32 ]);
33
34 /// Returns the best guess for the current operating system without using
35 /// `dart:io`.
36 ///
37 /// This is useful for running test files directly and skipping tests as
38 /// appropriate. The only OS-specific information we have is the current path,
39 /// which we try to use to figure out the OS.
40 final OperatingSystem currentOsGuess = (() {
41 if (p.style == p.Style.url) return OperatingSystem.none;
42 if (p.style == p.Style.windows) return OperatingSystem.windows;
43 if (_macOsDirectories.any(p.current.startsWith)) return OperatingSystem.macOs;
44 return OperatingSystem.linux;
45 })();
46
20 /// Get a string description of an exception. 47 /// Get a string description of an exception.
21 /// 48 ///
22 /// Many exceptions include the exception class name at the beginning of their 49 /// Many exceptions include the exception class name at the beginning of their
23 /// [toString], so we remove that if it exists. 50 /// [toString], so we remove that if it exists.
24 String getErrorMessage(error) => 51 String getErrorMessage(error) =>
25 error.toString().replaceFirst(_exceptionPrefix, ''); 52 error.toString().replaceFirst(_exceptionPrefix, '');
26 53
27 /// Indent each line in [str] by two spaces. 54 /// Indent each line in [str] by two spaces.
28 String indent(String str) => 55 String indent(String str) =>
29 str.replaceAll(new RegExp("^", multiLine: true), " "); 56 str.replaceAll(new RegExp("^", multiLine: true), " ");
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 134
108 // Otherwise truncate to return the trailing text, but attempt to start at 135 // Otherwise truncate to return the trailing text, but attempt to start at
109 // the beginning of a word. 136 // the beginning of a word.
110 var result = text.substring(text.length - maxLength + 4); 137 var result = text.substring(text.length - maxLength + 4);
111 var firstSpace = result.indexOf(' '); 138 var firstSpace = result.indexOf(' ');
112 if (firstSpace > 0) { 139 if (firstSpace > 0) {
113 result = result.substring(firstSpace); 140 result = result.substring(firstSpace);
114 } 141 }
115 return '...$result'; 142 return '...$result';
116 } 143 }
OLDNEW
« no previous file with comments | « lib/src/runner/vm/isolate_test.dart ('k') | lib/unittest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698