Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions lib/src/base/file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:file/memory.dart';
import 'package:file/record_replay.dart';
import 'package:meta/meta.dart';

import 'common.dart' show throwToolExit;
Expand All @@ -25,33 +24,6 @@ const FileSystem _kLocalFs = LocalFileSystem();
/// with [MemoryFileSystem].
FileSystem get fs => context.get<FileSystem>() ?? _kLocalFs;

/// Gets a [FileSystem] that will record file system activity to the specified
/// base recording [location].
///
/// Activity will be recorded in a subdirectory of [location] named `"file"`.
/// It is permissible for [location] to represent an existing non-empty
/// directory as long as there is no collision with the `"file"` subdirectory.
RecordingFileSystem getRecordingFileSystem(String location) {
final Directory dir = getRecordingSink(location, _kRecordingType);
final RecordingFileSystem fileSystem = RecordingFileSystem(
delegate: _kLocalFs, destination: dir);
addShutdownHook(() async {
await fileSystem.recording.flush();
}, ShutdownStage.SERIALIZE_RECORDING);
return fileSystem;
}

/// Gets a [FileSystem] that replays invocation activity from a previously
/// recorded set of invocations.
///
/// [location] must represent a directory to which file system activity has
/// been recorded (i.e. the result of having been previously passed to
/// [getRecordingFileSystem]), or a [ToolExit] will be thrown.
ReplayFileSystem getReplayFileSystem(String location) {
final Directory dir = getReplaySource(location, _kRecordingType);
return ReplayFileSystem(recording: dir);
}

/// Create the ancestor directories of a file path if they do not already exist.
void ensureDirectoryExists(String filePath) {
final String dirPath = fs.path.dirname(filePath);
Expand Down
37 changes: 0 additions & 37 deletions lib/src/base/process_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:async';

import 'package:process/process.dart';
import 'package:process/record_replay.dart';

import 'common.dart';
import 'context.dart';
Expand All @@ -17,39 +16,3 @@ const ProcessManager _kLocalProcessManager = LocalProcessManager();

/// The active process manager.
ProcessManager get processManager => context.get<ProcessManager>() ?? _kLocalProcessManager;

/// Gets a [ProcessManager] that will record process invocation activity to the
/// specified base recording [location].
///
/// Activity will be recorded in a subdirectory of [location] named `"process"`.
/// It is permissible for [location] to represent an existing non-empty
/// directory as long as there is no collision with the `"process"`
/// subdirectory.
RecordingProcessManager getRecordingProcessManager(String location) {
final Directory dir = getRecordingSink(location, _kRecordingType);
const ProcessManager delegate = LocalProcessManager();
final RecordingProcessManager manager = RecordingProcessManager(delegate, dir);
addShutdownHook(() async {
await manager.flush(finishRunningProcesses: true);
}, ShutdownStage.SERIALIZE_RECORDING);
return manager;
}

/// Gets a [ProcessManager] that replays process activity from a previously
/// recorded set of invocations.
///
/// [location] must represent a directory to which process activity has been
/// recorded (i.e. the result of having been previously passed to
/// [getRecordingProcessManager]), or a [ToolExit] will be thrown.
Future<ReplayProcessManager> getReplayProcessManager(String location) async {
final Directory dir = getReplaySource(location, _kRecordingType);

ProcessManager manager;
try {
manager = await ReplayProcessManager.create(dir);
} on ArgumentError catch (error) {
throwToolExit('Invalid replay-from: $error');
}

return manager;
}
15 changes: 8 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
name: tool_base
description: Base for developing command line apps. Take from Flutter Tools.
version: 1.9.5+3
version: 2.0.0
homepage: https://github.com/mmcc007/tool_base
author: Maurice McCabe <[email protected]>

environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.2.2 <3.0.0"
sdk: ">=2.10.0 <3.0.0"

dependencies:
# To update these, use "flutter update-packages --force-upgrade".
archive: ^2.0.9
file: ^5.0.8
platform: ^2.2.0
process: ^3.0.9
file: ^6.0.0-nullsafety.1
intl: ^0.16.1
platform: ^3.0.0-nullsafety.2
process: ^4.0.0-nullsafety.2
pub_cache: ^0.2.3

dev_dependencies:
pedantic: ^1.0.0
test: ^1.0.0
pedantic: ^1.10.0-nullsafety.1
test: ^1.16.0-nullsafety.5
mockito: ^4.1.0
quiver: ^2.0.3
file_testing: 2.1.0
28 changes: 14 additions & 14 deletions test/base/logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart';

final Generator _kNoAnsiPlatform = () =>
FakePlatform.fromPlatform(const LocalPlatform())
..stdoutSupportsAnsi = false;
final Generator _kNoAnsiPlatform = () => MutablePlatform()..stdoutSupportsAnsi = false;

void main() {
final String red = RegExp.escape(AnsiTerminal.red);
Expand Down Expand Up @@ -68,7 +66,7 @@ void main() {
r'\n$'));
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
});
});

Expand Down Expand Up @@ -143,7 +141,7 @@ void main() {
});
expect(done, isTrue);
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(operatingSystem: testOs),
Platform: () => MutablePlatform()..operatingSystem = testOs,
Stdio: () => mockStdio,
});

Expand Down Expand Up @@ -171,7 +169,7 @@ void main() {
});
expect(done, isTrue);
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(operatingSystem: testOs),
Platform: () => MutablePlatform()..operatingSystem = testOs,
Stdio: () => mockStdio,
Stopwatch: () => mockStopwatch,
});
Expand Down Expand Up @@ -208,8 +206,9 @@ void main() {
}, overrides: <Type, Generator>{
Logger: () => StdoutLogger(),
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () =>
FakePlatform(operatingSystem: testOs)..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()
..operatingSystem = testOs
..stdoutSupportsAnsi = true,
Stdio: () => mockStdio,
});

Expand Down Expand Up @@ -251,8 +250,9 @@ void main() {
}, overrides: <Type, Generator>{
Logger: () => StdoutLogger(),
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () =>
FakePlatform(operatingSystem: testOs)..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()
..operatingSystem = testOs
..stdoutSupportsAnsi = true,
Stdio: () => mockStdio,
});

Expand Down Expand Up @@ -290,7 +290,7 @@ void main() {
});
expect(done, isTrue);
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(operatingSystem: testOs),
Platform: () => MutablePlatform()..operatingSystem = testOs,
Stdio: () => mockStdio,
Stopwatch: () => mockStopwatch,
});
Expand Down Expand Up @@ -335,7 +335,7 @@ void main() {
});
expect(done, isTrue);
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(operatingSystem: testOs),
Platform: () => MutablePlatform()..operatingSystem = testOs,
Stdio: () => mockStdio,
Stopwatch: () => mockStopwatch,
});
Expand Down Expand Up @@ -386,7 +386,7 @@ void main() {
});
expect(done, isTrue);
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(operatingSystem: testOs),
Platform: () => MutablePlatform()..operatingSystem = testOs,
Stdio: () => mockStdio,
Stopwatch: () => mockStopwatch,
});
Expand Down Expand Up @@ -596,7 +596,7 @@ void main() {
}, overrides: <Type, Generator>{
Logger: () => StdoutLogger(),
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
Stdio: () => mockStdio,
});

Expand Down
3 changes: 2 additions & 1 deletion test/base/net_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:quiver/testing/async.dart';

import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart' show MutablePlatform;

void main() {
testUsingContext('retry from 500', () async {
Expand Down Expand Up @@ -125,7 +126,7 @@ void main() {
HttpClientFactory: () => () => MockHttpClientThrowing(
ArgumentError('test exception handling'),
),
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
Platform: () => MutablePlatform()
..environment = <String, String>{
'FLUTTER_STORAGE_BASE_URL': 'example.invalid'
},
Expand Down
4 changes: 2 additions & 2 deletions test/base/process_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:process/process.dart';

import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart' show MockProcess, MockProcessManager;
import '../src/mocks.dart' show MockProcess, MockProcessManager, MutablePlatform;

void main() {
group('process exceptions', () {
Expand Down Expand Up @@ -95,7 +95,7 @@ void main() {
ProcessManager: () => mockProcessManager,
OutputPreferences: () =>
OutputPreferences(wrapText: true, wrapColumn: 40),
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
Platform: () => MutablePlatform()
..stdoutSupportsAnsi = false,
});
});
Expand Down
15 changes: 8 additions & 7 deletions test/base/terminal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:tool_base/src/globals.dart';

import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart' show MutablePlatform;

void main() {
group('output preferences', () {
Expand All @@ -26,7 +27,7 @@ void main() {
printStatus(testString);
expect(testLogger.statusText, equals('$testString\n'));
}, overrides: <Type, Generator>{
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
OutputPreferences: () => OutputPreferences(wrapText: false),
});
});
Expand All @@ -48,7 +49,7 @@ void main() {
}
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
});

testUsingContext('adding bold works', () {
Expand All @@ -58,7 +59,7 @@ void main() {
);
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
});

testUsingContext('nesting bold within color works', () {
Expand All @@ -75,7 +76,7 @@ void main() {
);
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
});

testUsingContext('nesting color within bold works', () {
Expand All @@ -92,7 +93,7 @@ void main() {
);
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
});

testUsingContext('nesting color within color works', () {
Expand All @@ -111,7 +112,7 @@ void main() {
);
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
});

testUsingContext('nesting bold within bold works', () {
Expand All @@ -126,7 +127,7 @@ void main() {
);
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(showColor: true),
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
Platform: () => MutablePlatform()..stdoutSupportsAnsi = true,
});
});

Expand Down
7 changes: 4 additions & 3 deletions test/cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:tool_base/src/base/os.dart';

import 'src/common.dart';
import 'src/context.dart';
import 'src/mocks.dart' show MutablePlatform;
import 'src/testbed.dart';

void main() {
Expand Down Expand Up @@ -87,7 +88,7 @@ void main() {
testUsingContext('should not throw when FLUTTER_ALREADY_LOCKED is set', () async {
Cache.checkLockAcquired();
}, overrides: <Type, Generator>{
Platform: () => FakePlatform()..environment = <String, String>{'FLUTTER_ALREADY_LOCKED': 'true'},
Platform: () => MutablePlatform()..environment = <String, String>{'FLUTTER_ALREADY_LOCKED': 'true'},
});
});

Expand Down Expand Up @@ -215,14 +216,14 @@ void main() {

group('EngineCachedArtifact', () {
FakeHttpClient fakeHttpClient;
FakePlatform fakePlatform;
MutablePlatform fakePlatform;
MemoryFileSystem memoryFileSystem;
MockCache mockCache;
MockOperatingSystemUtils mockOperatingSystemUtils;

setUp(() {
fakeHttpClient = FakeHttpClient();
fakePlatform = FakePlatform()..environment = const <String, String>{};
fakePlatform = MutablePlatform()..environment = const <String, String>{};
memoryFileSystem = MemoryFileSystem();
mockCache = MockCache();
mockOperatingSystemUtils = MockOperatingSystemUtils();
Expand Down
Loading