Unverified Commit 06fcf514 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Inject logger and fs into printHowToConsumeAar, test without context (#56331)

parent 90233746
......@@ -84,6 +84,8 @@ class _AndroidBuilderImpl extends AndroidBuilder {
androidPackage: project.manifest.androidPackage,
repoDirectory: getRepoDirectory(outputDirectory),
buildNumber: buildNumber,
logger: globals.logger,
fileSystem: globals.fs,
);
} finally {
globals.androidSdk?.reinitialize();
......
......@@ -634,6 +634,8 @@ void printHowToConsumeAar({
@required Set<String> buildModes,
@required String androidPackage,
@required Directory repoDirectory,
@required Logger logger,
@required FileSystem fileSystem,
String buildNumber,
}) {
assert(buildModes != null && buildModes.isNotEmpty);
......@@ -641,10 +643,9 @@ void printHowToConsumeAar({
assert(repoDirectory != null);
buildNumber ??= '1.0';
globals.printStatus('''
${globals.terminal.bolden('Consuming the Module')}
1. Open ${globals.fs.path.join('<host>', 'app', 'build.gradle')}
logger.printStatus('\nConsuming the Module', emphasis: true);
logger.printStatus('''
1. Open ${fileSystem.path.join('<host>', 'app', 'build.gradle')}
2. Ensure you have the repositories configured, otherwise add them:
repositories {
......@@ -661,16 +662,16 @@ ${globals.terminal.bolden('Consuming the Module')}
dependencies {''');
for (final String buildMode in buildModes) {
globals.printStatus("""
logger.printStatus("""
${buildMode}Implementation '$androidPackage:flutter_$buildMode:$buildNumber'""");
}
globals.printStatus('''
logger.printStatus('''
}
''');
if (buildModes.contains('profile')) {
globals.printStatus('''
logger.printStatus('''
4. Add the `profile` build type:
......@@ -684,7 +685,7 @@ ${globals.terminal.bolden('Consuming the Module')}
''');
}
globals.printStatus('To learn more, visit https://flutter.dev/go/build-aar');
logger.printStatus('To learn more, visit https://flutter.dev/go/build-aar');
}
String _hex(List<int> bytes) {
......
......@@ -15,6 +15,7 @@ import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
......@@ -2349,16 +2350,26 @@ plugin1=${plugin1.path}
});
group('printHowToConsumeAar', () {
testUsingContext('stdout contains release, debug and profile', () async {
BufferLogger logger;
FileSystem fileSystem;
setUp(() {
logger = BufferLogger.test();
fileSystem = MemoryFileSystem.test();
});
testWithoutContext('stdout contains release, debug and profile', () async {
printHowToConsumeAar(
buildModes: const <String>{'release', 'debug', 'profile'},
androidPackage: 'com.mycompany',
repoDirectory: globals.fs.directory('build/'),
repoDirectory: fileSystem.directory('build/'),
buildNumber: '2.2',
logger: logger,
fileSystem: fileSystem,
);
expect(
testLogger.statusText,
logger.statusText,
contains(
'\n'
'Consuming the Module\n'
......@@ -2396,21 +2407,19 @@ plugin1=${plugin1.path}
'To learn more, visit https://flutter.dev/go/build-aar\n'
)
);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
Platform: () => fakePlatform('android'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('stdout contains release', () async {
testWithoutContext('stdout contains release', () async {
printHowToConsumeAar(
buildModes: const <String>{'release'},
androidPackage: 'com.mycompany',
repoDirectory: globals.fs.directory('build/'),
repoDirectory: fileSystem.directory('build/'),
logger: logger,
fileSystem: fileSystem,
);
expect(
testLogger.statusText,
logger.statusText,
contains(
'\n'
'Consuming the Module\n'
......@@ -2435,21 +2444,19 @@ plugin1=${plugin1.path}
'To learn more, visit https://flutter.dev/go/build-aar\n'
)
);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
Platform: () => fakePlatform('android'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('stdout contains debug', () async {
testWithoutContext('stdout contains debug', () async {
printHowToConsumeAar(
buildModes: const <String>{'debug'},
androidPackage: 'com.mycompany',
repoDirectory: globals.fs.directory('build/'),
repoDirectory: fileSystem.directory('build/'),
logger: logger,
fileSystem: fileSystem,
);
expect(
testLogger.statusText,
logger.statusText,
contains(
'\n'
'Consuming the Module\n'
......@@ -2474,22 +2481,20 @@ plugin1=${plugin1.path}
'To learn more, visit https://flutter.dev/go/build-aar\n'
)
);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
Platform: () => fakePlatform('android'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('stdout contains profile', () async {
testWithoutContext('stdout contains profile', () async {
printHowToConsumeAar(
buildModes: const <String>{'profile'},
androidPackage: 'com.mycompany',
repoDirectory: globals.fs.directory('build/'),
repoDirectory: fileSystem.directory('build/'),
buildNumber: '1.0',
logger: logger,
fileSystem: fileSystem,
);
expect(
testLogger.statusText,
logger.statusText,
contains(
'\n'
'Consuming the Module\n'
......@@ -2525,10 +2530,6 @@ plugin1=${plugin1.path}
'To learn more, visit https://flutter.dev/go/build-aar\n'
)
);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
Platform: () => fakePlatform('android'),
ProcessManager: () => FakeProcessManager.any(),
});
});
}
......
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