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

Side by Side Diff: tools/testing/dart/utils.dart

Issue 12417004: Update the test runner to use the new dart:io API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes Created 7 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 | Annotate | Revision Log
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 utils; 5 library utils;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:utf' as utf; 8 import 'dart:utf' as utf;
9 9
10 class DebugLogger { 10 class DebugLogger {
11 static OutputStream _stream; 11 static IOSink _sink;
12 12
13 /** 13 /**
14 * If [path] was null, the DebugLogger will write messages to stdout. 14 * If [path] was null, the DebugLogger will write messages to stdout.
15 */ 15 */
16 static init(Path path, {append: false}) { 16 static init(Path path, {append: false}) {
17 if (path != null) { 17 if (path != null) {
18 var mode = append ? FileMode.APPEND : FileMode.WRITE; 18 var mode = append ? FileMode.APPEND : FileMode.WRITE;
19 _stream = new File.fromPath(path).openOutputStream(mode); 19 _sink = new File.fromPath(path).openWrite(mode: mode);
20 } 20 }
21 } 21 }
22 22
23 static void close() { 23 static void close() {
24 if (_stream != null) { 24 if (_sink != null) {
25 _stream.close(); 25 _sink.close();
26 _stream = null; 26 _sink = null;
27 } 27 }
28 } 28 }
29 29
30 static void info(String msg) { 30 static void info(String msg) {
31 _print("Info: $msg"); 31 _print("Info: $msg");
32 } 32 }
33 33
34 static void warning(String msg) { 34 static void warning(String msg) {
35 _print("Warning: $msg"); 35 _print("Warning: $msg");
36 } 36 }
37 37
38 static void error(String msg) { 38 static void error(String msg) {
39 _print("Error: $msg"); 39 _print("Error: $msg");
40 } 40 }
41 41
42 static void _print(String msg) { 42 static void _print(String msg) {
43 if (_stream != null) { 43 if (_sink != null) {
44 _stream.write(encodeUtf8(msg)); 44 _sink.writeln(msg);
45 _stream.write([0x0a]);
46 } else { 45 } else {
47 print(msg); 46 print(msg);
48 } 47 }
49 } 48 }
50 } 49 }
51 50
52 List<int> encodeUtf8(String string) { 51 List<int> encodeUtf8(String string) {
53 return utf.encodeUtf8(string); 52 return utf.encodeUtf8(string);
54 } 53 }
55 54
56 // TODO(kustermann,ricow): As soon we have a debug log we should log 55 // TODO(kustermann,ricow): As soon we have a debug log we should log
57 // invalid utf8-encoded input to the log. 56 // invalid utf8-encoded input to the log.
58 // Currently invalid bytes will be replaced by a replacement character. 57 // Currently invalid bytes will be replaced by a replacement character.
59 String decodeUtf8(List<int> bytes) { 58 String decodeUtf8(List<int> bytes) {
60 return utf.decodeUtf8(bytes); 59 return utf.decodeUtf8(bytes);
61 } 60 }
62 61
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698