flutter/packages/flutter_tools/test/general.shard/base/io_test.dart
Ian Hickson 449f4a6673
License update (#45373)
* Update project.pbxproj files to say Flutter rather than Chromium

Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright.

* Update the copyright notice checker to require a standard notice on all files

* Update copyrights on Dart files. (This was a mechanical commit.)

* Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine.

Some were already marked "The Flutter Authors", not clear why. Their
dates have been normalized. Some were missing the blank line after the
license. Some were randomly different in trivial ways for no apparent
reason (e.g. missing the trailing period).

* Clean up the copyrights in non-Dart files. (Manual edits.)

Also, make sure templates don't have copyrights.

* Fix some more ORGANIZATIONNAMEs
2019-11-27 15:04:02 -08:00

74 lines
3 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io' as io;
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/io.dart';
void main() {
test('IOOverrides can inject a memory file system', () async {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem();
final FlutterIOOverrides flutterIOOverrides = FlutterIOOverrides(fileSystem: memoryFileSystem);
await io.IOOverrides.runWithIOOverrides(() async {
// statics delegate correctly.
expect(io.FileSystemEntity.isWatchSupported, memoryFileSystem.isWatchSupported);
expect(io.Directory.systemTemp.path, memoryFileSystem.systemTempDirectory.path);
// can create and write to files/directories sync.
final io.File file = io.File('abc');
file.writeAsStringSync('def');
final io.Directory directory = io.Directory('foobar');
directory.createSync();
expect(memoryFileSystem.file('abc').existsSync(), true);
expect(memoryFileSystem.file('abc').readAsStringSync(), 'def');
expect(memoryFileSystem.directory('foobar').existsSync(), true);
// can create and write to files/directories async.
final io.File fileB = io.File('xyz');
await fileB.writeAsString('def');
final io.Directory directoryB = io.Directory('barfoo');
await directoryB.create();
expect(memoryFileSystem.file('xyz').existsSync(), true);
expect(memoryFileSystem.file('xyz').readAsStringSync(), 'def');
expect(memoryFileSystem.directory('barfoo').existsSync(), true);
// Links
final io.Link linkA = io.Link('hhh');
final io.Link linkB = io.Link('ggg');
io.File('jjj').createSync();
io.File('lll').createSync();
await linkA.create('jjj');
linkB.createSync('lll');
expect(await memoryFileSystem.link('hhh').resolveSymbolicLinks(), await linkA.resolveSymbolicLinks());
expect(memoryFileSystem.link('ggg').resolveSymbolicLinksSync(), linkB.resolveSymbolicLinksSync());
}, flutterIOOverrides);
});
testUsingContext('ProcessSignal signals are properly delegated', () async {
final MockIoProcessSignal mockSignal = MockIoProcessSignal();
final ProcessSignal signalUnderTest = ProcessSignal(mockSignal);
final StreamController<io.ProcessSignal> controller = StreamController<io.ProcessSignal>();
when(mockSignal.watch()).thenAnswer((Invocation invocation) => controller.stream);
controller.add(mockSignal);
expect(signalUnderTest, await signalUnderTest.watch().first);
});
testUsingContext('ProcessSignal toString() works', () async {
expect(io.ProcessSignal.sigint.toString(), ProcessSignal.SIGINT.toString());
});
}
class MockIoProcessSignal extends Mock implements io.ProcessSignal {}