Migrate file_sample_test to async_minitest

Refactored to use Futures for asynchronous tests.

Change-Id: I95c7b3e0230f9c8d81b32b7323aa58ff339eadea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139493
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Srujan Gaddam 2020-03-16 17:48:48 +00:00 committed by commit-bot@chromium.org
parent 739e79e863
commit 5f8df3af03

View file

@ -4,7 +4,7 @@ import 'dart:async';
import 'dart:html';
import 'package:async_helper/async_helper.dart';
import 'package:unittest/unittest.dart';
import 'package:expect/minitest.dart';
// Expected output from all functions, asynchronous, and event routines.
const String log_results = 'test-first\n' +
@ -99,44 +99,47 @@ Future<List<Entry>> readEntries(DirectoryEntry directory) async {
return entries;
}
Future testFileSystemRequest() async {
testLog.log('test-first');
var fs = await fileSystem;
testLog.log('first START');
expect(fs != null, true);
expect(fs.root != null, true);
expect(fs.runtimeType, FileSystem);
expect(fs.root.runtimeType, DirectoryEntry);
testLog.log('first END');
}
Future testFileSystemRequestCreateRW() async {
testLog.log('test-second');
var fs = await fileSystem;
testLog.log('second START');
expect(fs != null, true);
expect(fs.root != null, true);
expect(fs.runtimeType, FileSystem);
expect(fs.root.runtimeType, DirectoryEntry);
testLog.log('second END');
FileEntry fileEntry = await createFile();
expect(fileEntry.name, 'log.txt');
List<Entry> entries = await readEntries(fs.root);
expect(entries.length > 0, true);
expect(entries[0].isDirectory, true);
expect(entries[0].name, 'my_directory');
List<Entry> myEntries = await readEntries(_myDirectory);
expect(myEntries.length, 1);
expect(myEntries[0].isFile, true);
expect(myEntries[0].name, 'log.txt');
// Validate every function, async and event mechanism successfully ran.
expect(testLog.contents, log_results);
}
main() {
group('test FileSystem', () {
test('FileSystem request #1', () async {
testLog.log('test-first');
var fs = await fileSystem;
testLog.log('first START');
expect(fs != null, true);
expect(fs.root != null, true);
expect(fs.runtimeType, FileSystem);
expect(fs.root.runtimeType, DirectoryEntry);
testLog.log('first END');
});
test('FileSystem request, create, R/W', () async {
testLog.log('test-second');
var fs = await fileSystem;
testLog.log('second START');
expect(fs != null, true);
expect(fs.root != null, true);
expect(fs.runtimeType, FileSystem);
expect(fs.root.runtimeType, DirectoryEntry);
testLog.log('second END');
FileEntry fileEntry = await createFile();
expect(fileEntry.name, 'log.txt');
List<Entry> entries = await readEntries(fs.root);
expect(entries.length > 0, true);
expect(entries[0].isDirectory, true);
expect(entries[0].name, 'my_directory');
List<Entry> myEntries = await readEntries(_myDirectory);
expect(myEntries.length, 1);
expect(myEntries[0].isFile, true);
expect(myEntries[0].name, 'log.txt');
// Validate every function, async and event mechanism successfully ran.
expect(testLog.contents, log_results);
});
asyncTest(() async {
await testFileSystemRequest();
await testFileSystemRequestCreateRW();
});
}