|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter_tools/src/base/common.dart'; |
| 6 | +import 'package:flutter_tools/src/base/io.dart'; |
| 7 | +import 'package:flutter_tools/src/base/terminal.dart'; |
| 8 | +import 'package:flutter_tools/src/base/user_messages.dart'; |
| 9 | +import 'package:mockito/mockito.dart'; |
| 10 | + |
| 11 | +import '../src/common.dart'; |
| 12 | + |
| 13 | +void main() { |
| 14 | + testWithoutContext('Defaults to a wrapped terminal columns with color if no ' |
| 15 | + 'args are provided', () { |
| 16 | + final MockUserMessage userMessages = MockUserMessage(); |
| 17 | + final MockStdio stdio = MockStdio(); |
| 18 | + when(stdio.terminalColumns).thenReturn(80); |
| 19 | + |
| 20 | + final OutputPreferences preferences = OutputPreferences.fromArguments( |
| 21 | + <String>[], |
| 22 | + userMessages: userMessages, |
| 23 | + stdio: stdio, |
| 24 | + ); |
| 25 | + |
| 26 | + expect(preferences.showColor, true); |
| 27 | + expect(preferences.wrapText, true); |
| 28 | + expect(preferences.wrapColumn, 80); |
| 29 | + }); |
| 30 | + |
| 31 | + testWithoutContext('Can be configured with --no-color', () { |
| 32 | + final MockUserMessage userMessages = MockUserMessage(); |
| 33 | + final MockStdio stdio = MockStdio(); |
| 34 | + when(stdio.terminalColumns).thenReturn(80); |
| 35 | + |
| 36 | + final OutputPreferences preferences = OutputPreferences.fromArguments( |
| 37 | + <String>['--no-color'], |
| 38 | + userMessages: userMessages, |
| 39 | + stdio: stdio, |
| 40 | + ); |
| 41 | + |
| 42 | + expect(preferences.showColor, false); |
| 43 | + expect(preferences.wrapText, true); |
| 44 | + expect(preferences.wrapColumn, 80); |
| 45 | + }); |
| 46 | + |
| 47 | + testWithoutContext('Can be configured with a specific wrap length', () { |
| 48 | + final MockUserMessage userMessages = MockUserMessage(); |
| 49 | + final MockStdio stdio = MockStdio(); |
| 50 | + when(stdio.terminalColumns).thenReturn(80); |
| 51 | + |
| 52 | + final OutputPreferences preferences = OutputPreferences.fromArguments( |
| 53 | + <String>['--wrap-column=123'], |
| 54 | + userMessages: userMessages, |
| 55 | + stdio: stdio, |
| 56 | + ); |
| 57 | + |
| 58 | + expect(preferences.showColor, true); |
| 59 | + expect(preferences.wrapText, true); |
| 60 | + expect(preferences.wrapColumn, 123); |
| 61 | + }); |
| 62 | + |
| 63 | + testWithoutContext('Will wrap to 100 when there is no terminal columns available', () { |
| 64 | + final MockUserMessage userMessages = MockUserMessage(); |
| 65 | + final MockStdio stdio = MockStdio(); |
| 66 | + when(stdio.terminalColumns).thenReturn(null); |
| 67 | + |
| 68 | + final OutputPreferences preferences = OutputPreferences.fromArguments( |
| 69 | + <String>['--wrap'], |
| 70 | + userMessages: userMessages, |
| 71 | + stdio: stdio, |
| 72 | + ); |
| 73 | + |
| 74 | + expect(preferences.showColor, true); |
| 75 | + expect(preferences.wrapText, true); |
| 76 | + expect(preferences.wrapColumn, 100); |
| 77 | + }); |
| 78 | + |
| 79 | + testWithoutContext('Can be configured to disable wrapping', () { |
| 80 | + final MockUserMessage userMessages = MockUserMessage(); |
| 81 | + final MockStdio stdio = MockStdio(); |
| 82 | + when(stdio.terminalColumns).thenReturn(80); |
| 83 | + |
| 84 | + final OutputPreferences preferences = OutputPreferences.fromArguments( |
| 85 | + <String>['--no-wrap'], |
| 86 | + userMessages: userMessages, |
| 87 | + stdio: stdio, |
| 88 | + ); |
| 89 | + |
| 90 | + expect(preferences.showColor, true); |
| 91 | + expect(preferences.wrapText, false); |
| 92 | + }); |
| 93 | + |
| 94 | + testWithoutContext('Throws a tool exit when an invalid wrap number is given', () { |
| 95 | + final MockUserMessage userMessages = MockUserMessage(); |
| 96 | + final MockStdio stdio = MockStdio(); |
| 97 | + when(stdio.terminalColumns).thenReturn(80); |
| 98 | + |
| 99 | + expect(() => OutputPreferences.fromArguments( |
| 100 | + <String>['--wrap-column=a'], |
| 101 | + userMessages: userMessages, |
| 102 | + stdio: stdio, |
| 103 | + ), throwsA(isA<ToolExit>())); |
| 104 | + }); |
| 105 | + |
| 106 | + testWithoutContext('Throws a tool exit when wrap is given without a number', () { |
| 107 | + final MockUserMessage userMessages = MockUserMessage(); |
| 108 | + final MockStdio stdio = MockStdio(); |
| 109 | + when(stdio.terminalColumns).thenReturn(80); |
| 110 | + |
| 111 | + expect(() => OutputPreferences.fromArguments( |
| 112 | + <String>['--wrap-column='], |
| 113 | + userMessages: userMessages, |
| 114 | + stdio: stdio, |
| 115 | + ), throwsA(isA<ToolExit>())); |
| 116 | + }); |
| 117 | +} |
| 118 | + |
| 119 | +class MockUserMessage extends Mock implements UserMessages {} |
| 120 | +class MockStdio extends Mock implements Stdio {} |
0 commit comments