Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 descriptor.file; | 5 library descriptor.file; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| 11 | 11 |
| 12 import 'package:path/path.dart' as path; | 12 import 'package:path/path.dart' as path; |
| 13 import 'package:stack_trace/stack_trace.dart'; | |
| 14 | 13 |
| 15 import '../../descriptor.dart'; | 14 import '../../descriptor.dart'; |
| 16 import '../../scheduled_test.dart'; | 15 import '../../scheduled_test.dart'; |
| 17 import '../utils.dart'; | 16 import '../utils.dart'; |
| 18 | 17 |
| 19 /// A descriptor describing a single file. | 18 /// A descriptor describing a single file. |
| 20 abstract class FileDescriptor extends Descriptor implements ReadableDescriptor { | 19 abstract class FileDescriptor extends Descriptor implements ReadableDescriptor { |
| 21 /// The contents of the file, in bytes. | 20 /// The contents of the file, in bytes. |
| 22 final List<int> contents; | 21 final List<int> contents; |
| 23 | 22 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 74 |
| 76 Stream<List<int>> read() => new Future.value(contents).asStream(); | 75 Stream<List<int>> read() => new Future.value(contents).asStream(); |
| 77 | 76 |
| 78 String describe() => name; | 77 String describe() => name; |
| 79 } | 78 } |
| 80 | 79 |
| 81 class _BinaryFileDescriptor extends FileDescriptor { | 80 class _BinaryFileDescriptor extends FileDescriptor { |
| 82 _BinaryFileDescriptor(String name, List<int> contents) | 81 _BinaryFileDescriptor(String name, List<int> contents) |
| 83 : super._(name, contents); | 82 : super._(name, contents); |
| 84 | 83 |
| 85 Future _validateNow(List<int> actualContents) { | 84 Future _validateNow(List<int> actualContents) async { |
|
nweiz
2015/06/04 19:20:10
Don't use async/await in scheduled test until issu
kevmoo
2015/06/04 19:23:46
Done.
| |
| 86 if (orderedIterableEquals(contents, actualContents)) return null; | 85 if (orderedIterableEquals(contents, actualContents)) return null; |
| 87 // TODO(nweiz): show a hex dump here if the data is small enough. | 86 // TODO(nweiz): show a hex dump here if the data is small enough. |
| 88 fail("File '$name' didn't contain the expected binary data."); | 87 throw new TestFailure( |
| 88 "File '$name' didn't contain the expected binary data."); | |
|
nweiz
2015/06/04 19:20:10
Why aren't you calling fail() here anymore?
kevmoo
2015/06/04 19:23:46
analyzer yells about having one flow w/ a return v
| |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 class _StringFileDescriptor extends FileDescriptor { | 92 class _StringFileDescriptor extends FileDescriptor { |
| 93 _StringFileDescriptor(String name, String contents) | 93 _StringFileDescriptor(String name, String contents) |
| 94 : super._(name, UTF8.encode(contents)); | 94 : super._(name, UTF8.encode(contents)); |
| 95 | 95 |
| 96 Future _validateNow(List<int> actualContents) { | 96 Future _validateNow(List<int> actualContents) { |
| 97 if (orderedIterableEquals(contents, actualContents)) return null; | 97 if (orderedIterableEquals(contents, actualContents)) return null; |
| 98 throw _textMismatchMessage(textContents, | 98 throw new TestFailure(_textMismatchMessage( |
| 99 new String.fromCharCodes(actualContents)); | 99 textContents, new String.fromCharCodes(actualContents))); |
| 100 } | 100 } |
| 101 | 101 |
| 102 String _textMismatchMessage(String expected, String actual) { | 102 String _textMismatchMessage(String expected, String actual) { |
| 103 final expectedLines = expected.split('\n'); | 103 final expectedLines = expected.split('\n'); |
| 104 final actualLines = actual.split('\n'); | 104 final actualLines = actual.split('\n'); |
| 105 | 105 |
| 106 var results = []; | 106 var results = []; |
| 107 | 107 |
| 108 // Compare them line by line to see which ones match. | 108 // Compare them line by line to see which ones match. |
| 109 var length = math.max(expectedLines.length, actualLines.length); | 109 var length = math.max(expectedLines.length, actualLines.length); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 | 141 |
| 142 _MatcherFileDescriptor(String name, this._matcher, {bool isBinary}) | 142 _MatcherFileDescriptor(String name, this._matcher, {bool isBinary}) |
| 143 : _isBinary = isBinary == true ? true : false, | 143 : _isBinary = isBinary == true ? true : false, |
| 144 super._(name, <int>[]); | 144 super._(name, <int>[]); |
| 145 | 145 |
| 146 void _validateNow(List<int> actualContents) => | 146 void _validateNow(List<int> actualContents) => |
| 147 expect( | 147 expect( |
| 148 _isBinary ? actualContents : new String.fromCharCodes(actualContents), | 148 _isBinary ? actualContents : new String.fromCharCodes(actualContents), |
| 149 _matcher); | 149 _matcher); |
| 150 } | 150 } |
| OLD | NEW |