Chromium Code Reviews| Index: pkg/scheduled_test/lib/src/descriptor/file.dart |
| diff --git a/pkg/scheduled_test/lib/src/descriptor/file.dart b/pkg/scheduled_test/lib/src/descriptor/file.dart |
| index 15b9ef46f3f0d665dcafc2b7031cdfd210eb587f..2454c460dc0fd28bb77e1aba1046d46549aa4780 100644 |
| --- a/pkg/scheduled_test/lib/src/descriptor/file.dart |
| +++ b/pkg/scheduled_test/lib/src/descriptor/file.dart |
| @@ -14,7 +14,6 @@ import '../../../../../pkg/pathos/lib/path.dart' as path; |
| import '../../descriptor.dart' as descriptor; |
| import '../../scheduled_test.dart'; |
| import '../utils.dart'; |
| -import 'utils.dart'; |
| /// A descriptor describing a single file. |
| class File extends descriptor.Entry { |
| @@ -28,80 +27,78 @@ class File extends descriptor.Entry { |
| /// The contents of the file as a String. Assumes UTF-8 encoding. |
| String get textContents => new String.fromCharCodes(contents); |
| - File.binary(Pattern name, List<int> contents) |
| + File.binary(String name, List<int> contents) |
| : this._(name, contents, true); |
| - File(Pattern name, String contents) |
| + File(String name, String contents) |
| : this._(name, encodeUtf8(contents), false); |
| - File._(Pattern name, this.contents, this.isBinary) |
| + File._(String name, this.contents, this.isBinary) |
| : super(name); |
| Future create([String parent]) => schedule(() { |
| if (parent == null) parent = descriptor.defaultRoot; |
| - return new io.File(path.join(parent, stringName)).writeAsBytes(contents); |
| - }, 'creating file $nameDescription'); |
| + return new io.File(path.join(parent, name)).writeAsBytes(contents); |
| + }, "creating file '$name'"); |
| - Future validate([String parent]) => schedule(() { |
| + Future validate([String parent]) => |
| + schedule(() => validateNow(parent), "validating file '$name'"); |
| + |
| + Future validateNow([String parent]) { |
| if (parent == null) parent = descriptor.defaultRoot; |
| - var fullPath = entryMatchingPattern('File', parent, name); |
| + var fullPath = path.join(parent, name); |
| + if (!new io.File(fullPath).existsSync()) { |
| + throw "File not found: '$fullPath'."; |
| + } |
| + |
| return new io.File(fullPath).readAsBytes() |
| .then((actualContents) { |
| if (orderedIterableEquals(contents, actualContents)) return; |
| if (isBinary) { |
| // TODO(nweiz): show a hex dump here if the data is small enough. |
| - throw "File $nameDescription didn't contain the expected binary " |
| - "data."; |
| + throw "File '$name' didn't contain the expected binary data."; |
| } |
| - var description = nameDescription; |
| - if (name is! String) { |
| - description = "'${path.basename(fullPath)}' (matching $description)"; |
| - } |
| - throw _textMismatchMessage(description, textContents, |
| - new String.fromCharCodes(actualContents));; |
| + throw _textMismatchMessage(textContents, |
| + new String.fromCharCodes(actualContents)); |
| }); |
| - }, 'validating file $nameDescription'); |
| + } |
| Stream<List<int>> read() => new Future.immediate(contents).asStream(); |
| - String describe() { |
| - if (name is String) return name; |
| - return 'file matching $nameDescription'; |
| - } |
| -} |
| + String describe() => name; |
| + |
| + String _textMismatchMessage(String expected, String actual) { |
| + final expectedLines = expected.split('\n'); |
| + final actualLines = actual.split('\n'); |
| + |
| + var results = []; |
| -String _textMismatchMessage(String description, String expected, |
| - String actual) { |
| - final expectedLines = expected.split('\n'); |
| - final actualLines = actual.split('\n'); |
| - |
| - var results = []; |
| - |
| - // Compare them line by line to see which ones match. |
| - var length = math.max(expectedLines.length, actualLines.length); |
| - for (var i = 0; i < length; i++) { |
| - if (i >= actualLines.length) { |
| - // Missing output. |
| - results.add('? ${expectedLines[i]}'); |
| - } else if (i >= expectedLines.length) { |
| - // Unexpected extra output. |
| - results.add('X ${actualLines[i]}'); |
| - } else { |
| - var expectedLine = expectedLines[i]; |
| - var actualLine = actualLines[i]; |
| - |
| - if (expectedLine != actualLine) { |
| - // Mismatched lines. |
| - results.add('X $actualLine'); |
| + // Compare them line by line to see which ones match. |
| + var length = math.max(expectedLines.length, actualLines.length); |
| + for (var i = 0; i < length; i++) { |
| + if (i >= actualLines.length) { |
| + // Missing output. |
| + results.add('? ${expectedLines[i]}'); |
| + } else if (i >= expectedLines.length) { |
| + // Unexpected extra output. |
| + results.add('X ${actualLines[i]}'); |
| } else { |
| - // Matched lines. |
| - results.add('| $actualLine'); |
| + var expectedLine = expectedLines[i]; |
| + var actualLine = actualLines[i]; |
| + |
| + if (expectedLine != actualLine) { |
| + // Mismatched lines. |
| + results.add('X $actualLine'); |
| + } else { |
| + // Matched lines. |
| + results.add('| $actualLine'); |
| + } |
| } |
| } |
| - } |
| - return "File $description should contain:\n" |
| - "${prefixLines(expected)}\n" |
| - "but actually contained:\n" |
| - "${results.join('\n')}"; |
| + return "File '$name' should contain:\n" |
| + "${prefixLines(expected)}\n" |
|
Bob Nystrom
2013/03/15 21:58:46
Indent +2.
nweiz
2013/03/15 23:17:21
Done.
|
| + "but actually contained:\n" |
| + "${results.join('\n')}"; |
| + } |
| } |