Enable Travis-CI (dart-lang/test_descriptor#8)
* dartfmt
* Rename analysis_options, enable travis
diff --git a/pkgs/test_descriptor/.travis.yml b/pkgs/test_descriptor/.travis.yml
new file mode 100644
index 0000000..a0653e3
--- /dev/null
+++ b/pkgs/test_descriptor/.travis.yml
@@ -0,0 +1,25 @@
+language: dart
+
+dart:
+ - dev
+ - stable
+
+dart_task:
+ - test
+
+# Only run one instance of the formatter and the analyzer, rather than running
+# them against each Dart version.
+matrix:
+ include:
+ - dart: dev
+ dart_task: dartfmt
+ - dart: dev
+ dart_task: dartanalyzer
+
+# Only building master means that we don't run two builds for each pull request.
+branches:
+ only: [master]
+
+cache:
+ directories:
+ - $HOME/.pub-cache
diff --git a/pkgs/test_descriptor/.analysis_options b/pkgs/test_descriptor/analysis_options.yaml
similarity index 100%
rename from pkgs/test_descriptor/.analysis_options
rename to pkgs/test_descriptor/analysis_options.yaml
diff --git a/pkgs/test_descriptor/lib/src/directory_descriptor.dart b/pkgs/test_descriptor/lib/src/directory_descriptor.dart
index 0034e61..32b2e07 100644
--- a/pkgs/test_descriptor/lib/src/directory_descriptor.dart
+++ b/pkgs/test_descriptor/lib/src/directory_descriptor.dart
@@ -34,20 +34,21 @@
/// Creates a directory descriptor named [name] that describes the physical
/// directory at [path].
factory DirectoryDescriptor.fromFilesystem(String name, String path) {
- return new DirectoryDescriptor(name,
+ return new DirectoryDescriptor(
+ name,
new Directory(path).listSync().map((entity) {
- // Ignore hidden files.
- if (p.basename(entity.path).startsWith(".")) return null;
+ // Ignore hidden files.
+ if (p.basename(entity.path).startsWith(".")) return null;
- if (entity is Directory) {
- return new DirectoryDescriptor.fromFilesystem(
- p.basename(entity.path), entity.path);
- } else if (entity is File) {
- return new FileDescriptor(
- p.basename(entity.path), entity.readAsBytesSync());
- }
- // Ignore broken symlinks.
- }).where((path) => path != null));
+ if (entity is Directory) {
+ return new DirectoryDescriptor.fromFilesystem(
+ p.basename(entity.path), entity.path);
+ } else if (entity is File) {
+ return new FileDescriptor(
+ p.basename(entity.path), entity.readAsBytesSync());
+ }
+ // Ignore broken symlinks.
+ }).where((path) => path != null));
}
Future create([String parent]) async {
@@ -93,19 +94,17 @@
var file = split.length == 1;
var matchingEntries = contents.where((entry) {
return entry.name == split.first &&
- (file
- ? entry is FileDescriptor
- : entry is DirectoryDescriptor);
+ (file ? entry is FileDescriptor : entry is DirectoryDescriptor);
}).toList();
var type = file ? 'file' : 'directory';
var parentsAndSelf = parents == null ? name : p.url.join(parents, name);
if (matchingEntries.isEmpty) {
fail('Couldn\'t find a $type descriptor named "${split.first}" within '
- '"$parentsAndSelf".');
+ '"$parentsAndSelf".');
} else if (matchingEntries.length > 1) {
fail('Found multiple $type descriptors named "${split.first}" within '
- '"$parentsAndSelf".');
+ '"$parentsAndSelf".');
} else {
var remainingPath = split.sublist(1);
if (remainingPath.isEmpty) {
@@ -124,16 +123,16 @@
var buffer = new StringBuffer();
buffer.writeln(name);
for (var entry in contents.take(contents.length - 1)) {
- var entryString = prefixLines(
- entry.describe(), '${glyph.verticalLine} ',
- first: '${glyph.teeRight}${glyph.horizontalLine}'
- '${glyph.horizontalLine} ');
+ var entryString =
+ prefixLines(entry.describe(), '${glyph.verticalLine} ',
+ first: '${glyph.teeRight}${glyph.horizontalLine}'
+ '${glyph.horizontalLine} ');
buffer.writeln(entryString);
}
var lastEntryString = prefixLines(contents.last.describe(), ' ',
first: '${glyph.bottomLeftCorner}${glyph.horizontalLine}'
- '${glyph.horizontalLine} ');
+ '${glyph.horizontalLine} ');
buffer.write(lastEntryString);
return buffer.toString();
}
diff --git a/pkgs/test_descriptor/lib/src/file_descriptor.dart b/pkgs/test_descriptor/lib/src/file_descriptor.dart
index e10c2c6..1d7a109 100644
--- a/pkgs/test_descriptor/lib/src/file_descriptor.dart
+++ b/pkgs/test_descriptor/lib/src/file_descriptor.dart
@@ -128,8 +128,8 @@
throw fail(_textMismatchMessage(prettyPath, _contents, actualContentsText));
}
- String _textMismatchMessage(String prettyPath, String expected,
- String actual) {
+ String _textMismatchMessage(
+ String prettyPath, String expected, String actual) {
final expectedLines = expected.split('\n');
final actualLines = actual.split('\n');
@@ -183,8 +183,7 @@
void _validate(String prettyPath, List<int> actualContents) {
try {
expect(
- _isBinary ? actualContents : utf8.decode(actualContents),
- _matcher);
+ _isBinary ? actualContents : utf8.decode(actualContents), _matcher);
} on TestFailure catch (error) {
throw new TestFailure(
'Invalid contents for file "$prettyPath":\n' + error.message);
diff --git a/pkgs/test_descriptor/lib/src/nothing_descriptor.dart b/pkgs/test_descriptor/lib/src/nothing_descriptor.dart
index f067ba3..2d62cb0 100644
--- a/pkgs/test_descriptor/lib/src/nothing_descriptor.dart
+++ b/pkgs/test_descriptor/lib/src/nothing_descriptor.dart
@@ -16,8 +16,7 @@
///
/// Calling [create] does nothing.
class NothingDescriptor extends Descriptor {
- NothingDescriptor(String name)
- : super(name);
+ NothingDescriptor(String name) : super(name);
Future create([String parent]) async {}
diff --git a/pkgs/test_descriptor/lib/src/pattern_descriptor.dart b/pkgs/test_descriptor/lib/src/pattern_descriptor.dart
index 2511238..60cd131 100644
--- a/pkgs/test_descriptor/lib/src/pattern_descriptor.dart
+++ b/pkgs/test_descriptor/lib/src/pattern_descriptor.dart
@@ -44,7 +44,8 @@
Future validate([String parent]) async {
var inSandbox = parent == null;
parent ??= sandbox;
- var matchingEntries = await new Directory(parent).list()
+ var matchingEntries = await new Directory(parent)
+ .list()
.map((entry) =>
entry is File ? entry.resolveSymbolicLinksSync() : entry.path)
.where((entry) => matchesAll(pattern, p.basename(entry)))
@@ -75,8 +76,8 @@
await waitAndReportErrors(results.map((result) => result.asFuture));
} else if (successes.length > 1) {
fail('Multiple valid entries found in $location matching '
- '$_patternDescription:\n'
- '${bullet(successes.map((result) => result.asValue.value))}');
+ '$_patternDescription:\n'
+ '${bullet(successes.map((result) => result.asValue.value))}');
}
}
diff --git a/pkgs/test_descriptor/lib/src/sandbox.dart b/pkgs/test_descriptor/lib/src/sandbox.dart
index 6311629..eee1252 100644
--- a/pkgs/test_descriptor/lib/src/sandbox.dart
+++ b/pkgs/test_descriptor/lib/src/sandbox.dart
@@ -16,7 +16,8 @@
if (_sandbox != null) return _sandbox;
// Resolve symlinks so we don't end up with inconsistent paths on Mac OS where
// /tmp is symlinked.
- _sandbox = Directory.systemTemp.createTempSync('dart_test_')
+ _sandbox = Directory.systemTemp
+ .createTempSync('dart_test_')
.resolveSymbolicLinksSync();
addTearDown(() async {
@@ -27,6 +28,7 @@
return _sandbox;
}
+
String _sandbox;
/// Whether [sandbox] has been created.
diff --git a/pkgs/test_descriptor/lib/src/utils.dart b/pkgs/test_descriptor/lib/src/utils.dart
index bd2d78c..3e1d12e 100644
--- a/pkgs/test_descriptor/lib/src/utils.dart
+++ b/pkgs/test_descriptor/lib/src/utils.dart
@@ -16,9 +16,7 @@
/// Prepends a vertical bar to [text].
String addBar(String text) => prefixLines(text, "${glyph.verticalLine} ",
- first: "${glyph.downEnd} ",
- last: "${glyph.upEnd} ",
- single: "| ");
+ first: "${glyph.downEnd} ", last: "${glyph.upEnd} ", single: "| ");
/// Indents [text], and adds a bullet at the beginning.
String addBullet(String text) =>
@@ -33,8 +31,8 @@
/// prefixed with those instead. If [single] is passed, it's used if there's
/// only a single line; otherwise, [first], [last], or [prefix] is used, in that
/// order of precedence.
-String prefixLines(String text, String prefix, {String first, String last,
- String single}) {
+String prefixLines(String text, String prefix,
+ {String first, String last, String single}) {
first ??= prefix;
last ??= prefix;
single ??= first ?? last ?? prefix;
diff --git a/pkgs/test_descriptor/test/directory_test.dart b/pkgs/test_descriptor/test/directory_test.dart
index cea9627..5507ea4 100644
--- a/pkgs/test_descriptor/test/directory_test.dart
+++ b/pkgs/test_descriptor/test/directory_test.dart
@@ -32,10 +32,12 @@
completion(equals('contents1')));
expect(new File(p.join(d.sandbox, 'dir', 'file2.txt')).readAsString(),
completion(equals('contents2')));
- expect(new File(p.join(d.sandbox, 'dir', 'subdir', 'subfile1.txt'))
+ expect(
+ new File(p.join(d.sandbox, 'dir', 'subdir', 'subfile1.txt'))
.readAsString(),
completion(equals('subcontents1')));
- expect(new File(p.join(d.sandbox, 'dir', 'subdir', 'subfile2.txt'))
+ expect(
+ new File(p.join(d.sandbox, 'dir', 'subdir', 'subfile2.txt'))
.readAsString(),
completion(equals('subcontents2')));
});
@@ -78,16 +80,17 @@
await new File(p.join(dirPath, 'file1.txt')).writeAsString('contents1');
await new File(p.join(dirPath, 'file2.txt')).writeAsString('contents2');
- expect(d.dir('dir', [
- d.dir('subdir', [
- d.file('subfile1.txt', 'subcontents1'),
- d.file('subfile2.txt', 'subcontents2')
- ]),
- d.file('file1.txt', 'contents1'),
- d.file('file2.txt', 'contents2')
- ]).validate(),
- throwsA(toString(equals(
- 'Directory not found: "${p.join('dir', 'subdir')}".'))));
+ expect(
+ d.dir('dir', [
+ d.dir('subdir', [
+ d.file('subfile1.txt', 'subcontents1'),
+ d.file('subfile2.txt', 'subcontents2')
+ ]),
+ d.file('file1.txt', 'contents1'),
+ d.file('file2.txt', 'contents2')
+ ]).validate(),
+ throwsA(toString(
+ equals('Directory not found: "${p.join('dir', 'subdir')}".'))));
});
test("emits an error for each child that fails to validate", () async {
@@ -109,37 +112,38 @@
d.file('file1.txt', 'contents1'),
d.file('file2.txt', 'contents2')
]).validate();
- }, onError: expectAsync1((error) {
- errors++;
- controller.add(error.toString());
- if (errors == 3) controller.close();
- }, count: 3));
+ },
+ onError: expectAsync1((error) {
+ errors++;
+ controller.add(error.toString());
+ if (errors == 3) controller.close();
+ }, count: 3));
- expect(controller.stream.toList(), completion(allOf([
- contains('File not found: "${p.join('dir', 'subdir', 'subfile1.txt')}".'),
- contains('File not found: "${p.join('dir', 'file2.txt')}".'),
- contains(startsWith('File "${p.join('dir', 'subdir', 'subfile2.txt')}" '
- 'should contain:')),
- ])));
+ expect(
+ controller.stream.toList(),
+ completion(allOf([
+ contains(
+ 'File not found: "${p.join('dir', 'subdir', 'subfile1.txt')}".'),
+ contains('File not found: "${p.join('dir', 'file2.txt')}".'),
+ contains(
+ startsWith('File "${p.join('dir', 'subdir', 'subfile2.txt')}" '
+ 'should contain:')),
+ ])));
});
});
group("load()", () {
test("loads a file", () {
- var dir = d.dir('dir', [
- d.file('name.txt', 'contents'),
- d.file('other.txt', 'wrong')
- ]);
+ var dir = d.dir('dir',
+ [d.file('name.txt', 'contents'), d.file('other.txt', 'wrong')]);
expect(UTF8.decodeStream(dir.load('name.txt')),
completion(equals('contents')));
});
test("loads a deeply-nested file", () {
var dir = d.dir('dir', [
- d.dir('subdir', [
- d.file('name.txt', 'subcontents'),
- d.file('other.txt', 'wrong')
- ]),
+ d.dir('subdir',
+ [d.file('name.txt', 'subcontents'), d.file('other.txt', 'wrong')]),
d.dir('otherdir', [d.file('other.txt', 'wrong')]),
d.file('name.txt', 'contents')
]);
@@ -156,7 +160,8 @@
d.file('name.txt', 'contents')
]);
- expect(dir.load('subdir/subsubdir').toList(),
+ expect(
+ dir.load('subdir/subsubdir').toList(),
throwsA(toString(equals('Couldn\'t find a file descriptor named '
'"subsubdir" within "dir/subdir".'))));
});
@@ -176,20 +181,20 @@
d.dir('subdir', [d.file('name.txt', 'contents')])
]);
- expect(dir.load('subdir/not-name.txt').toList(),
+ expect(
+ dir.load('subdir/not-name.txt').toList(),
throwsA(toString(equals('Couldn\'t find a file descriptor named '
'"not-name.txt" within "dir/subdir".'))));
});
test("fails to load a file that exists multiple times", () {
var dir = d.dir('dir', [
- d.dir('subdir', [
- d.file('name.txt', 'contents'),
- d.file('name.txt', 'contents')
- ])
+ d.dir('subdir',
+ [d.file('name.txt', 'contents'), d.file('name.txt', 'contents')])
]);
- expect(dir.load('subdir/name.txt').toList(),
+ expect(
+ dir.load('subdir/name.txt').toList(),
throwsA(toString(equals('Found multiple file descriptors named '
'"name.txt" within "dir/subdir".'))));
});
@@ -200,8 +205,8 @@
d.dir('name', [d.file('subfile', 'contents')])
]);
- expect(UTF8.decodeStream(dir.load('name')),
- completion(equals('contents')));
+ expect(
+ UTF8.decodeStream(dir.load('name')), completion(equals('contents')));
});
});
@@ -217,15 +222,14 @@
});
test("lists the contents of the directory", () {
- var dir = d.dir('dir', [
- d.file('file1.txt', 'contents1'),
- d.file('file2.txt', 'contents2')
- ]);
+ var dir = d.dir('dir',
+ [d.file('file1.txt', 'contents1'), d.file('file2.txt', 'contents2')]);
- expect(dir.describe(), equals(
- "dir\n"
- "+-- file1.txt\n"
- "'-- file2.txt"));
+ expect(
+ dir.describe(),
+ equals("dir\n"
+ "+-- file1.txt\n"
+ "'-- file2.txt"));
});
test("lists the contents of nested directories", () {
@@ -234,22 +238,21 @@
d.dir('subdir', [
d.file('subfile1.txt', 'subcontents1'),
d.file('subfile2.txt', 'subcontents2'),
- d.dir('subsubdir', [
- d.file('subsubfile.txt', 'subsubcontents')
- ])
+ d.dir('subsubdir', [d.file('subsubfile.txt', 'subsubcontents')])
]),
d.file('file2.txt', 'contents2')
]);
- expect(dir.describe(), equals(
- "dir\n"
- "+-- file1.txt\n"
- "+-- subdir\n"
- "| +-- subfile1.txt\n"
- "| +-- subfile2.txt\n"
- "| '-- subsubdir\n"
- "| '-- subsubfile.txt\n"
- "'-- file2.txt"));
+ expect(
+ dir.describe(),
+ equals("dir\n"
+ "+-- file1.txt\n"
+ "+-- subdir\n"
+ "| +-- subfile1.txt\n"
+ "| +-- subfile2.txt\n"
+ "| '-- subsubdir\n"
+ "| '-- subsubfile.txt\n"
+ "'-- file2.txt"));
});
test("with no contents returns the directory name", () {
@@ -290,10 +293,8 @@
await descriptor.create();
await d.dir('dir2', [
- d.dir('subdir', [
- d.file('subfile1.txt', 'subcontents1'),
- d.nothing('.hidden')
- ]),
+ d.dir('subdir',
+ [d.file('subfile1.txt', 'subcontents1'), d.nothing('.hidden')]),
d.file('file1.txt', 'contents1'),
d.nothing('.DS_Store')
]).validate();
diff --git a/pkgs/test_descriptor/test/file_test.dart b/pkgs/test_descriptor/test/file_test.dart
index 4cdc184..b3be840 100644
--- a/pkgs/test_descriptor/test/file_test.dart
+++ b/pkgs/test_descriptor/test/file_test.dart
@@ -31,8 +31,8 @@
});
test('fails to create a matcher file', () async {
- expect(d.file('name.txt', contains('foo')).create(),
- throwsUnsupportedError);
+ expect(
+ d.file('name.txt', contains('foo')).create(), throwsUnsupportedError);
});
test('overwrites an existing file', () async {
@@ -81,7 +81,8 @@
test("fails if the binary contents don't match", () async {
await new File(p.join(d.sandbox, 'name.txt')).writeAsBytes([5, 4, 3, 2]);
- expect(d.file('name.txt', [0, 1, 2, 3]).validate(),
+ expect(
+ d.file('name.txt', [0, 1, 2, 3]).validate(),
throwsA(toString(equals(
'File "name.txt" didn\'t contain the expected binary data.'))));
});
@@ -89,9 +90,10 @@
test("fails if the text contents don't match the matcher", () async {
await new File(p.join(d.sandbox, 'name.txt')).writeAsString('wrong');
- expect(d.file('name.txt', contains('ent')).validate(),
- throwsA(toString(startsWith(
- 'Invalid contents for file "name.txt":'))));
+ expect(
+ d.file('name.txt', contains('ent')).validate(),
+ throwsA(
+ toString(startsWith('Invalid contents for file "name.txt":'))));
});
test("fails if the binary contents don't match the matcher", () async {
@@ -100,16 +102,18 @@
expect(
new d.FileDescriptor.binaryMatcher('name.txt', contains(1))
.validate(),
- throwsA(toString(startsWith(
- 'Invalid contents for file "name.txt":'))));
+ throwsA(
+ toString(startsWith('Invalid contents for file "name.txt":'))));
});
test("fails if invalid UTF-8 doesn't match a text matcher", () async {
await new File(p.join(d.sandbox, 'name.txt')).writeAsBytes([0xC3, 0x28]);
- expect(d.file('name.txt', isEmpty).validate(), throwsA(toString(allOf([
- startsWith('Invalid contents for file "name.txt":'),
- contains('�')
- ]))));
+ expect(
+ d.file('name.txt', isEmpty).validate(),
+ throwsA(toString(allOf([
+ startsWith('Invalid contents for file "name.txt":'),
+ contains('�')
+ ]))));
});
test("fails if there's no file", () {
@@ -130,8 +134,7 @@
});
test("read() fails for a matcher file", () {
- expect(d.file('name.txt', contains('hi')).read,
- throwsUnsupportedError);
+ expect(d.file('name.txt', contains('hi')).read, throwsUnsupportedError);
});
test("readAsBytes() returns the contents of a text file as a byte stream",
diff --git a/pkgs/test_descriptor/test/nothing_test.dart b/pkgs/test_descriptor/test/nothing_test.dart
index 916c396..d2935d0 100644
--- a/pkgs/test_descriptor/test/nothing_test.dart
+++ b/pkgs/test_descriptor/test/nothing_test.dart
@@ -17,8 +17,8 @@
test("create() does nothing", () async {
await d.nothing('foo').create();
expect(new File(p.join(d.sandbox, 'foo')).exists(), completion(isFalse));
- expect(new Directory(p.join(d.sandbox, 'foo')).exists(),
- completion(isFalse));
+ expect(
+ new Directory(p.join(d.sandbox, 'foo')).exists(), completion(isFalse));
});
group("validate()", () {
@@ -28,20 +28,26 @@
test("fails if there's a file", () async {
await d.file('name.txt', 'contents').create();
- expect(d.nothing('name.txt').validate(), throwsA(toString(equals(
- 'Expected nothing to exist at "name.txt", but found a file.'))));
+ expect(
+ d.nothing('name.txt').validate(),
+ throwsA(toString(equals(
+ 'Expected nothing to exist at "name.txt", but found a file.'))));
});
test("fails if there's a directory", () async {
await d.dir('dir').create();
- expect(d.nothing('dir').validate(), throwsA(toString(equals(
- 'Expected nothing to exist at "dir", but found a directory.'))));
+ expect(
+ d.nothing('dir').validate(),
+ throwsA(toString(equals(
+ 'Expected nothing to exist at "dir", but found a directory.'))));
});
test("fails if there's a broken link", () async {
await new Link(p.join(d.sandbox, 'link')).create('nonexistent');
- expect(d.nothing('link').validate(), throwsA(toString(equals(
- 'Expected nothing to exist at "link", but found a link.'))));
+ expect(
+ d.nothing('link').validate(),
+ throwsA(toString(equals(
+ 'Expected nothing to exist at "link", but found a link.'))));
});
});
}
diff --git a/pkgs/test_descriptor/test/pattern_test.dart b/pkgs/test_descriptor/test/pattern_test.dart
index e5f1969..fb9b5bb 100644
--- a/pkgs/test_descriptor/test/pattern_test.dart
+++ b/pkgs/test_descriptor/test/pattern_test.dart
@@ -20,16 +20,13 @@
test("succeeds if there's a directory matching the pattern and the child",
() async {
- await d.dir('foo', [
- d.file('bar', 'baz')
- ]).create();
+ await d.dir('foo', [d.file('bar', 'baz')]).create();
- await d.dirPattern(new RegExp(r'f..'), [
- d.file('bar', 'baz')
- ]).validate();
+ await d.dirPattern(new RegExp(r'f..'), [d.file('bar', 'baz')]).validate();
});
- test("succeeds if multiple files match the pattern but only one matches "
+ test(
+ "succeeds if multiple files match the pattern but only one matches "
"the child entry", () async {
await d.file('foo', 'blap').create();
await d.file('fee', 'blak').create();
@@ -39,9 +36,10 @@
});
test("fails if there's no file matching the pattern", () {
- expect(d.filePattern(new RegExp(r'f..'), 'bar').validate(),
- throwsA(toString(equals(
- 'No entries found in sandbox matching /f../.'))));
+ expect(
+ d.filePattern(new RegExp(r'f..'), 'bar').validate(),
+ throwsA(
+ toString(equals('No entries found in sandbox matching /f../.'))));
});
test("fails if there's a file matching the pattern but not the entry",
@@ -52,23 +50,22 @@
});
test("fails if there's a dir matching the pattern but not the entry",
- () async{
- await d.dir('foo', [
- d.file('bar', 'bap')
- ]).create();
+ () async {
+ await d.dir('foo', [d.file('bar', 'bap')]).create();
- expect(d.dirPattern(new RegExp(r'f..'), [
- d.file('bar', 'baz')
- ]).validate(),
+ expect(
+ d.dirPattern(new RegExp(r'f..'), [d.file('bar', 'baz')]).validate(),
throwsA(toString(startsWith('File "foo/bar" should contain:'))));
});
- test("fails if there are multiple files matching the pattern and the child "
+ test(
+ "fails if there are multiple files matching the pattern and the child "
"entry", () async {
await d.file('foo', 'bar').create();
await d.file('fee', 'bar').create();
await d.file('faa', 'bar').create();
- expect(d.filePattern(new RegExp(r'f..'), 'bar').validate(),
+ expect(
+ d.filePattern(new RegExp(r'f..'), 'bar').validate(),
throwsA(toString(startsWith(
"Multiple valid entries found in sandbox matching /f../:"))));
});