Unverified Commit 1196f91f authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix local test failures in flutter_tools (#42015)

* Minor clean-up in terminal.dart

* Don't wrap text in tests (otherwise we'll be sensitive to the terminal width).
parent f4b4616f
...@@ -9,15 +9,6 @@ import '../globals.dart'; ...@@ -9,15 +9,6 @@ import '../globals.dart';
import 'context.dart'; import 'context.dart';
import 'io.dart' as io; import 'io.dart' as io;
import 'platform.dart'; import 'platform.dart';
import 'utils.dart';
final AnsiTerminal _kAnsiTerminal = AnsiTerminal();
AnsiTerminal get terminal {
return (context == null || context.get<AnsiTerminal>() == null)
? _kAnsiTerminal
: context.get<AnsiTerminal>();
}
enum TerminalColor { enum TerminalColor {
red, red,
...@@ -29,11 +20,15 @@ enum TerminalColor { ...@@ -29,11 +20,15 @@ enum TerminalColor {
grey, grey,
} }
final OutputPreferences _kOutputPreferences = OutputPreferences(); AnsiTerminal get terminal {
return context?.get<AnsiTerminal>() ?? _defaultAnsiTerminal;
}
final AnsiTerminal _defaultAnsiTerminal = AnsiTerminal();
OutputPreferences get outputPreferences => (context == null || context.get<OutputPreferences>() == null) OutputPreferences get outputPreferences {
? _kOutputPreferences return context?.get<OutputPreferences>() ?? _defaultOutputPreferences;
: context.get<OutputPreferences>(); }
final OutputPreferences _defaultOutputPreferences = OutputPreferences();
/// A class that contains the context settings for command text output to the /// A class that contains the context settings for command text output to the
/// console. /// console.
...@@ -42,31 +37,32 @@ class OutputPreferences { ...@@ -42,31 +37,32 @@ class OutputPreferences {
bool wrapText, bool wrapText,
int wrapColumn, int wrapColumn,
bool showColor, bool showColor,
}) : wrapText = wrapText ?? io.stdio?.hasTerminal ?? const io.Stdio().hasTerminal, }) : wrapText = wrapText ?? io.stdio.hasTerminal,
_overrideWrapColumn = wrapColumn, _overrideWrapColumn = wrapColumn,
showColor = showColor ?? platform.stdoutSupportsAnsi ?? false; showColor = showColor ?? platform.stdoutSupportsAnsi ?? false;
/// A version of this class for use in tests.
OutputPreferences.test() : wrapText = false, _overrideWrapColumn = null, showColor = false;
/// If [wrapText] is true, then any text sent to the context's [Logger] /// If [wrapText] is true, then any text sent to the context's [Logger]
/// instance (e.g. from the [printError] or [printStatus] functions) will be /// instance (e.g. from the [printError] or [printStatus] functions) will be
/// wrapped (newlines added between words) to be no longer than the /// wrapped (newlines added between words) to be no longer than the
/// [wrapColumn] specifies. Defaults to true if there is a terminal. To /// [wrapColumn] specifies. Defaults to true if there is a terminal. To
/// determine if there's a terminal, [OutputPreferences] asks the context's /// determine if there's a terminal, [OutputPreferences] asks the context's
/// stdio to see, and if that's not set, it tries creating a new [io.Stdio] /// stdio.
/// and asks it if there is a terminal.
final bool wrapText; final bool wrapText;
/// The terminal width used by the [wrapText] function if there is no terminal
/// attached to [io.Stdio], --wrap is on, and --wrap-columns was not specified.
static const int kDefaultTerminalColumns = 100;
/// The column at which output sent to the context's [Logger] instance /// The column at which output sent to the context's [Logger] instance
/// (e.g. from the [printError] or [printStatus] functions) will be wrapped. /// (e.g. from the [printError] or [printStatus] functions) will be wrapped.
/// Ignored if [wrapText] is false. Defaults to the width of the output /// Ignored if [wrapText] is false. Defaults to the width of the output
/// terminal, or to [kDefaultTerminalColumns] if not writing to a terminal. /// terminal, or to [kDefaultTerminalColumns] if not writing to a terminal.
/// To find out if we're writing to a terminal, it tries the context's stdio,
/// and if that's not set, it tries creating a new [io.Stdio] and asks it, if
/// that doesn't have an idea of the terminal width, then we just use a
/// default of 100. It will be ignored if [wrapText] is false.
final int _overrideWrapColumn; final int _overrideWrapColumn;
int get wrapColumn { int get wrapColumn {
return _overrideWrapColumn ?? io.stdio?.terminalColumns return _overrideWrapColumn ?? io.stdio.terminalColumns ?? kDefaultTerminalColumns;
?? const io.Stdio().terminalColumns ?? kDefaultTerminalColumns;
} }
/// Whether or not to output ANSI color codes when writing to the output /// Whether or not to output ANSI color codes when writing to the output
......
...@@ -307,9 +307,6 @@ class Poller { ...@@ -307,9 +307,6 @@ class Poller {
Future<List<T>> waitGroup<T>(Iterable<Future<T>> futures) { Future<List<T>> waitGroup<T>(Iterable<Future<T>> futures) {
return Future.wait<T>(futures.where((Future<T> future) => future != null)); return Future.wait<T>(futures.where((Future<T> future) => future != null));
} }
/// The terminal width used by the [wrapText] function if there is no terminal
/// attached to [io.Stdio], --wrap is on, and --wrap-columns was not specified.
const int kDefaultTerminalColumns = 100;
/// Smallest column that will be used for text wrapping. If the requested column /// Smallest column that will be used for text wrapping. If the requested column
/// width is smaller than this, then this is what will be used. /// width is smaller than this, then this is what will be used.
......
...@@ -82,7 +82,7 @@ void testUsingContext( ...@@ -82,7 +82,7 @@ void testUsingContext(
when(mock.getAttachedDevices()).thenAnswer((Invocation _) async => <IOSSimulator>[]); when(mock.getAttachedDevices()).thenAnswer((Invocation _) async => <IOSSimulator>[]);
return mock; return mock;
}, },
OutputPreferences: () => OutputPreferences(showColor: false), OutputPreferences: () => OutputPreferences.test(),
Logger: () => BufferLogger(), Logger: () => BufferLogger(),
OperatingSystemUtils: () => FakeOperatingSystemUtils(), OperatingSystemUtils: () => FakeOperatingSystemUtils(),
SimControl: () => MockSimControl(), SimControl: () => MockSimControl(),
......
...@@ -33,7 +33,7 @@ final Map<Type, Generator> _testbedDefaults = <Type, Generator>{ ...@@ -33,7 +33,7 @@ final Map<Type, Generator> _testbedDefaults = <Type, Generator>{
FileSystem: () => MemoryFileSystem(style: platform.isWindows ? FileSystemStyle.windows : FileSystemStyle.posix), FileSystem: () => MemoryFileSystem(style: platform.isWindows ? FileSystemStyle.windows : FileSystemStyle.posix),
Logger: () => BufferLogger(), // Allows reading logs and prevents stdout. Logger: () => BufferLogger(), // Allows reading logs and prevents stdout.
OperatingSystemUtils: () => FakeOperatingSystemUtils(), OperatingSystemUtils: () => FakeOperatingSystemUtils(),
OutputPreferences: () => OutputPreferences(showColor: false), // configures BufferLogger to avoid color codes. OutputPreferences: () => OutputPreferences.test(), // configures BufferLogger to avoid color codes.
Usage: () => NoOpUsage(), // prevent addition of analytics from burdening test mocks Usage: () => NoOpUsage(), // prevent addition of analytics from burdening test mocks
FlutterVersion: () => FakeFlutterVersion(), // prevent requirement to mock git for test runner. FlutterVersion: () => FakeFlutterVersion(), // prevent requirement to mock git for test runner.
Signals: () => FakeSignals(), // prevent registering actual signal handlers. Signals: () => FakeSignals(), // prevent registering actual signal handlers.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment