Stop wrapping adb, gradle and ios logger output, and update terminal wrapping column dynamically. (#23592)

Subcommand output (gradle, adb, etc) is no longer wrapped, and wrapping notices when the terminal column width changes dynamically now.

Fixes #23267.
Fixes #23266.
This commit is contained in:
Greg Spencer
2018-10-30 16:00:50 -07:00
committed by GitHub
parent be7226f08e
commit 4559ae1a6b
15 changed files with 139 additions and 35 deletions

View File

@@ -3,19 +3,22 @@
// found in the LICENSE file.
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart' show MockProcess, MockProcessManager;
void main() {
group('process exceptions', () {
ProcessManager mockProcessManager;
setUp(() {
mockProcessManager = MockProcessManager();
mockProcessManager = PlainMockProcessManager();
});
testUsingContext('runCheckedAsync exceptions should be ProcessException objects', () async {
@@ -56,6 +59,35 @@ void main() {
expect(cleanup, 4);
});
});
group('output formatting', () {
MockProcessManager mockProcessManager;
BufferLogger mockLogger;
setUp(() {
mockProcessManager = MockProcessManager();
mockLogger = BufferLogger();
});
MockProcess Function(List<String>) processMetaFactory(List<String> stdout, {List<String> stderr = const <String>[]}) {
final Stream<List<int>> stdoutStream =
Stream<List<int>>.fromIterable(stdout.map<List<int>>((String s) => s.codeUnits));
final Stream<List<int>> stderrStream =
Stream<List<int>>.fromIterable(stderr.map<List<int>>((String s) => s.codeUnits));
return (List<String> command) => MockProcess(stdout: stdoutStream, stderr: stderrStream);
}
testUsingContext('Command output is not wrapped.', () async {
final List<String> testString = <String>['0123456789' * 10];
mockProcessManager.processFactory = processMetaFactory(testString, stderr: testString);
await runCommandAndStreamOutput(<String>['command']);
expect(mockLogger.statusText, equals('${testString[0]}\n'));
expect(mockLogger.errorText, equals('${testString[0]}\n'));
}, overrides: <Type, Generator>{
Logger: () => mockLogger,
ProcessManager: () => mockProcessManager,
OutputPreferences: () => OutputPreferences(wrapText: true, wrapColumn: 40),
});
});
}
class MockProcessManager extends Mock implements ProcessManager {}
class PlainMockProcessManager extends Mock implements ProcessManager {}

View File

@@ -4,6 +4,7 @@
import 'dart:async';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/utils.dart';
import 'package:flutter_tools/src/base/version.dart';
import 'package:flutter_tools/src/base/terminal.dart';
@@ -165,7 +166,8 @@ baz=qux
await Future<void>.delayed(kShortDelay);
}, kShortDelay);
final Duration duration = await completer.future;
expect(duration, greaterThanOrEqualTo(Duration(milliseconds: kShortDelay.inMilliseconds * 2)));
expect(
duration, greaterThanOrEqualTo(Duration(milliseconds: kShortDelay.inMilliseconds * 2)));
});
});
@@ -200,14 +202,16 @@ baz=qux
const String _shortLine = 'Short line.';
const String _indentedLongLine = ' This is an indented long line that needs to be '
'wrapped and indentation preserved.';
final FakeStdio fakeStdio = FakeStdio();
void testWrap(String description, Function body) {
testUsingContext(description, body, overrides: <Type, Generator> {
void testWrap(String description, Function body) {
testUsingContext(description, body, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(wrapText: true, wrapColumn: _lineLength),
});
}
void testNoWrap(String description, Function body) {
testUsingContext(description, body, overrides: <Type, Generator> {
void testNoWrap(String description, Function body) {
testUsingContext(description, body, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(wrapText: false),
});
}
@@ -215,6 +219,14 @@ baz=qux
test('does not wrap by default in tests', () {
expect(wrapText(_longLine), equals(_longLine));
});
testNoWrap('can override wrap preference if preference is off', () {
expect(wrapText(_longLine, columnWidth: _lineLength, shouldWrap: true), equals('''
This is a long line that needs to be
wrapped.'''));
});
testWrap('can override wrap preference if preference is on', () {
expect(wrapText(_longLine, shouldWrap: false), equals(_longLine));
});
testNoWrap('does not wrap at all if not told to wrap', () {
expect(wrapText(_longLine), equals(_longLine));
});
@@ -226,6 +238,20 @@ baz=qux
This is a long line that needs to be
wrapped.'''));
});
testUsingContext('able to handle dynamically changing terminal column size', () {
fakeStdio.currentColumnSize = 20;
expect(wrapText(_longLine), equals('''
This is a long line
that needs to be
wrapped.'''));
fakeStdio.currentColumnSize = _lineLength;
expect(wrapText(_longLine), equals('''
This is a long line that needs to be
wrapped.'''));
}, overrides: <Type, Generator>{
OutputPreferences: () => OutputPreferences(wrapText: true),
Stdio: () => fakeStdio,
});
testWrap('wrap long lines with no whitespace', () {
expect(wrapText('0123456789' * 5, columnWidth: _lineLength), equals('''
0123456789012345678901234567890123456789
@@ -335,3 +361,12 @@ needs to be wrapped.
});
});
}
class FakeStdio extends Stdio {
FakeStdio();
int currentColumnSize = 20;
@override
int get terminalColumns => currentColumnSize;
}