Skip to content

Commit

Permalink
Fix check for copied directories (#1967)
Browse files Browse the repository at this point in the history
The current tests have no useful validation and pass even if the methods
under test are empty because they check that a directory is the same as
itself.

Add a directory name argument when creating the test descriptor
directory and use the parent and copy directory name for `_create` and
`_validate` respectively. Add constants for the directory names.
  • Loading branch information
natebosch authored Jan 14, 2025
1 parent c94c563 commit 30de295
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkgs/io/test/copy_path_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,36 @@ import 'package:test_descriptor/test_descriptor.dart' as d;
void main() {
test('should copy a directory (async)', () async {
await _create();
await copyPath(p.join(d.sandbox, 'parent'), p.join(d.sandbox, 'copy'));
await copyPath(p.join(d.sandbox, _parentDir), p.join(d.sandbox, _copyDir));
await _validate();
});

test('should copy a directory (sync)', () async {
await _create();
copyPathSync(p.join(d.sandbox, 'parent'), p.join(d.sandbox, 'copy'));
copyPathSync(p.join(d.sandbox, _parentDir), p.join(d.sandbox, _copyDir));
await _validate();
});

test('should catch an infinite operation', () async {
await _create();
expect(
copyPath(
p.join(d.sandbox, 'parent'),
p.join(d.sandbox, 'parent', 'child'),
p.join(d.sandbox, _parentDir),
p.join(d.sandbox, _parentDir, 'child'),
),
throwsArgumentError,
);
});
}

d.DirectoryDescriptor _struct() => d.dir('parent', [
const _parentDir = 'parent';
const _copyDir = 'copy';

d.DirectoryDescriptor _struct(String dirName) => d.dir(dirName, [
d.dir('child', [
d.file('foo.txt'),
]),
]);

Future<void> _create() => _struct().create();
Future<void> _validate() => _struct().validate();
Future<void> _create() => _struct(_parentDir).create();
Future<void> _validate() => _struct(_copyDir).validate();

0 comments on commit 30de295

Please sign in to comment.