forked from flutter/flutter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flutter_tools] inject output preferences at the top level (flutter#5…
…8875) The tool was setting the output preferences in a sub-context. Originally these were not injected before the arg parsers were created, though that was fixed by the lazy command creation. Once local engine is removed, the inner flutter_command Zone can be removed.
- Loading branch information
1 parent
e7b4d2b
commit dca6320
Showing
5 changed files
with
167 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/flutter_tools/test/general.shard/output_preferences_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// 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 'package:flutter_tools/src/base/common.dart'; | ||
import 'package:flutter_tools/src/base/io.dart'; | ||
import 'package:flutter_tools/src/base/terminal.dart'; | ||
import 'package:flutter_tools/src/base/user_messages.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
import '../src/common.dart'; | ||
|
||
void main() { | ||
testWithoutContext('Defaults to a wrapped terminal columns with color if no ' | ||
'args are provided', () { | ||
final MockUserMessage userMessages = MockUserMessage(); | ||
final MockStdio stdio = MockStdio(); | ||
when(stdio.terminalColumns).thenReturn(80); | ||
|
||
final OutputPreferences preferences = OutputPreferences.fromArguments( | ||
<String>[], | ||
userMessages: userMessages, | ||
stdio: stdio, | ||
); | ||
|
||
expect(preferences.showColor, true); | ||
expect(preferences.wrapText, true); | ||
expect(preferences.wrapColumn, 80); | ||
}); | ||
|
||
testWithoutContext('Can be configured with --no-color', () { | ||
final MockUserMessage userMessages = MockUserMessage(); | ||
final MockStdio stdio = MockStdio(); | ||
when(stdio.terminalColumns).thenReturn(80); | ||
|
||
final OutputPreferences preferences = OutputPreferences.fromArguments( | ||
<String>['--no-color'], | ||
userMessages: userMessages, | ||
stdio: stdio, | ||
); | ||
|
||
expect(preferences.showColor, false); | ||
expect(preferences.wrapText, true); | ||
expect(preferences.wrapColumn, 80); | ||
}); | ||
|
||
testWithoutContext('Can be configured with a specific wrap length', () { | ||
final MockUserMessage userMessages = MockUserMessage(); | ||
final MockStdio stdio = MockStdio(); | ||
when(stdio.terminalColumns).thenReturn(80); | ||
|
||
final OutputPreferences preferences = OutputPreferences.fromArguments( | ||
<String>['--wrap-column=123'], | ||
userMessages: userMessages, | ||
stdio: stdio, | ||
); | ||
|
||
expect(preferences.showColor, true); | ||
expect(preferences.wrapText, true); | ||
expect(preferences.wrapColumn, 123); | ||
}); | ||
|
||
testWithoutContext('Will wrap to 100 when there is no terminal columns available', () { | ||
final MockUserMessage userMessages = MockUserMessage(); | ||
final MockStdio stdio = MockStdio(); | ||
when(stdio.terminalColumns).thenReturn(null); | ||
|
||
final OutputPreferences preferences = OutputPreferences.fromArguments( | ||
<String>['--wrap'], | ||
userMessages: userMessages, | ||
stdio: stdio, | ||
); | ||
|
||
expect(preferences.showColor, true); | ||
expect(preferences.wrapText, true); | ||
expect(preferences.wrapColumn, 100); | ||
}); | ||
|
||
testWithoutContext('Can be configured to disable wrapping', () { | ||
final MockUserMessage userMessages = MockUserMessage(); | ||
final MockStdio stdio = MockStdio(); | ||
when(stdio.terminalColumns).thenReturn(80); | ||
|
||
final OutputPreferences preferences = OutputPreferences.fromArguments( | ||
<String>['--no-wrap'], | ||
userMessages: userMessages, | ||
stdio: stdio, | ||
); | ||
|
||
expect(preferences.showColor, true); | ||
expect(preferences.wrapText, false); | ||
}); | ||
|
||
testWithoutContext('Throws a tool exit when an invalid wrap number is given', () { | ||
final MockUserMessage userMessages = MockUserMessage(); | ||
final MockStdio stdio = MockStdio(); | ||
when(stdio.terminalColumns).thenReturn(80); | ||
|
||
expect(() => OutputPreferences.fromArguments( | ||
<String>['--wrap-column=a'], | ||
userMessages: userMessages, | ||
stdio: stdio, | ||
), throwsA(isA<ToolExit>())); | ||
}); | ||
|
||
testWithoutContext('Throws a tool exit when wrap is given without a number', () { | ||
final MockUserMessage userMessages = MockUserMessage(); | ||
final MockStdio stdio = MockStdio(); | ||
when(stdio.terminalColumns).thenReturn(80); | ||
|
||
expect(() => OutputPreferences.fromArguments( | ||
<String>['--wrap-column='], | ||
userMessages: userMessages, | ||
stdio: stdio, | ||
), throwsA(isA<ToolExit>())); | ||
}); | ||
} | ||
|
||
class MockUserMessage extends Mock implements UserMessages {} | ||
class MockStdio extends Mock implements Stdio {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters