Enable more "File > open" tests (#145)
* Enable more "File > open" tests
When I added a `MemoryFileSystem`-based implementation of
`RandomAccessFile` in https://github.com/google/file.dart/pull/136,
I enabled `File > open` tests for `test/memory_test.dart` but did not
notice that various other tests depend on `MemoryFileSystem` and also
explicitly disabled them.
Enable them for `chroot_test.dart` and for `recording_test.dart`.
Enabling them for `replay_test.dart` currently does not work due to
other failures that I don't yet understand (see
https://github.com/google/file.dart/issues/144).
* Fix type error when attempting to enable "File > open" replay tests
Fix `ReplayFile.read`/`readSync` to explicitly convert the input
(read from a JSON integer array) into a `Uint8List`.
Fixes one of the failures in https://github.com/google/file.dart/issues/144.
* Fix analysis error
* Disable "File > open" replay tests more selectively
Record/replay currently doesn't work with `RandomAccessFile.readInto`,
but we can enable other `RandomAccessFile` tests.
diff --git a/packages/file/lib/src/backends/record_replay/codecs.dart b/packages/file/lib/src/backends/record_replay/codecs.dart
index c40234e..1febe07 100644
--- a/packages/file/lib/src/backends/record_replay/codecs.dart
+++ b/packages/file/lib/src/backends/record_replay/codecs.dart
@@ -456,6 +456,15 @@
List<T> convert(T input) => <T>[input];
}
+/// Converts a simple [List<int>] to a [Uint8List].
+class ToUint8List extends Converter<List<int>, Uint8List> {
+ /// Creates a new [ToUint8List].
+ const ToUint8List();
+
+ @override
+ Uint8List convert(List<int> input) => Uint8List.fromList(input);
+}
+
/// Revives a [Directory] entity reference into a [ReplayDirectory].
class ReviveDirectory extends Converter<String, Directory> {
/// Creates a new [ReviveDirectory].
diff --git a/packages/file/lib/src/backends/record_replay/replay_random_access_file.dart b/packages/file/lib/src/backends/record_replay/replay_random_access_file.dart
index 5c6fd44..eb4d0cc 100644
--- a/packages/file/lib/src/backends/record_replay/replay_random_access_file.dart
+++ b/packages/file/lib/src/backends/record_replay/replay_random_access_file.dart
@@ -23,13 +23,18 @@
Converter<String, Future<RandomAccessFile>> reviveRandomAccessFileAsFuture =
ReviveRandomAccessFile(_fileSystem).fuse(toFuture);
+ Converter<List<dynamic>, Uint8List> reviveUint8List =
+ const CastList<dynamic, int>().fuse(const ToUint8List());
+ Converter<List<dynamic>, Future<Uint8List>> reviveUint8ListFuture =
+ reviveUint8List.fuse(const ToFuture<Uint8List>());
+
methods.addAll(<Symbol, Converter<dynamic, dynamic>>{
#close: reviveRandomAccessFileAsFuture,
#closeSync: const Passthrough<Null>(),
#readByte: const ToFuture<int>(),
#readByteSync: const Passthrough<int>(),
- #read: const ToFuture<Uint8List>(),
- #readSync: const Passthrough<Uint8List>(),
+ #read: reviveUint8ListFuture,
+ #readSync: reviveUint8List,
#readInto: const ToFuture<int>(),
#readIntoSync: const Passthrough<int>(),
#writeByte: reviveRandomAccessFileAsFuture,
diff --git a/packages/file/test/chroot_test.dart b/packages/file/test/chroot_test.dart
index 65a78ba..6a8b07a 100644
--- a/packages/file/test/chroot_test.dart
+++ b/packages/file/test/chroot_test.dart
@@ -23,12 +23,7 @@
}
group('memoryBacked', () {
- runCommonTests(
- createMemoryBackedChrootFileSystem,
- skip: <String>[
- 'File > open', // Not yet implemented in MemoryFileSystem
- ],
- );
+ runCommonTests(createMemoryBackedChrootFileSystem);
});
group('localBacked', () {
diff --git a/packages/file/test/recording_test.dart b/packages/file/test/recording_test.dart
index 3c04437..ed61f18 100644
--- a/packages/file/test/recording_test.dart
+++ b/packages/file/test/recording_test.dart
@@ -333,12 +333,7 @@
recording = fs.recording;
});
- runCommonTests(
- () => fs,
- skip: <String>[
- 'File > open', // Not yet implemented in MemoryFileSystem
- ],
- );
+ runCommonTests(() => fs);
group('recording', () {
test('supportsMultipleActions', () {
diff --git a/packages/file/test/replay_test.dart b/packages/file/test/replay_test.dart
index e54f28d..9bcb4d5 100644
--- a/packages/file/test/replay_test.dart
+++ b/packages/file/test/replay_test.dart
@@ -49,7 +49,11 @@
'File > openWrite > ioSink > addStream > blocks.*',
'File > openWrite > ioSink > ignoresDataWrittenAfterClose',
- 'File > open', // Not yet implemented in MemoryFileSystem
+ // TODO(jamesderlin): ReplayFileSystem does not yet support functions
+ // that mutate arguments, and error-checking for async functions is not
+ // implemented (https://github.com/google/file.dart/issues/144)
+ 'File > open .* RandomAccessFile .* readInto.*',
+ 'File > open .* RandomAccessFile .* throwsIfAsyncUnawaited',
],
);