Files
packages/script/tool/test/lint_android_command_test.dart
stuartmorgan dcf97f741f [flutter_plugin_tool] Add support for building UWP plugins (#4047)
This allows building UWP plugin examples with `build-examples --winuwp`. As with previous pre-stable-template desktop support, this avoids the issue of unstable app templates by running `flutter create` on the fly before trying to build, so a template that will bitrot doesn't need to be checked in.

Also adds no-op "support" for `drive-examples --winuwp`, with warnings about it not doing anything. This is to handle the fact that the LUCI recipe is shared between Win32 and UWP, and didn't conditionalize `drive`. Rather than change that, then change it back later, this just adds the no-op support now (since changing the tooling is much easier than changing LUCI recipes currently).

This required some supporting tool changes:
- Adds the ability to check for the new platform variants in a pubspec
- Adds the ability to write test pubspecs that include variants, for testing

Part of https://github.com/flutter/flutter/issues/82817
2021-08-26 12:07:33 -07:00

159 lines
4.7 KiB
Dart

// Copyright 2013 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 'dart:io' as io;
import 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';
import 'package:flutter_plugin_tools/src/common/plugin_utils.dart';
import 'package:flutter_plugin_tools/src/lint_android_command.dart';
import 'package:test/test.dart';
import 'mocks.dart';
import 'util.dart';
void main() {
group('$LintAndroidCommand', () {
FileSystem fileSystem;
late Directory packagesDir;
late CommandRunner<void> runner;
late MockPlatform mockPlatform;
late RecordingProcessRunner processRunner;
setUp(() {
fileSystem = MemoryFileSystem(style: FileSystemStyle.posix);
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
mockPlatform = MockPlatform();
processRunner = RecordingProcessRunner();
final LintAndroidCommand command = LintAndroidCommand(
packagesDir,
processRunner: processRunner,
platform: mockPlatform,
);
runner = CommandRunner<void>(
'lint_android_test', 'Test for $LintAndroidCommand');
runner.addCommand(command);
});
test('runs gradle lint', () async {
final Directory pluginDir =
createFakePlugin('plugin1', packagesDir, extraFiles: <String>[
'example/android/gradlew',
], platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
});
final Directory androidDir =
pluginDir.childDirectory('example').childDirectory('android');
final List<String> output =
await runCapturingPrint(runner, <String>['lint-android']);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
androidDir.childFile('gradlew').path,
const <String>['plugin1:lintDebug'],
androidDir.path,
),
]),
);
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for plugin1'),
contains('No issues found!'),
]));
});
test('fails if gradlew is missing', () async {
createFakePlugin('plugin1', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
});
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['lint-android'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Build example before linting'),
],
));
});
test('fails if linting finds issues', () async {
createFakePlugin('plugin1', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.inline)
});
processRunner.mockProcessesForExecutable['gradlew'] = <io.Process>[
MockProcess(exitCode: 1),
];
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['lint-android'], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(
<Matcher>[
contains('Build example before linting'),
],
));
});
test('skips non-Android plugins', () async {
createFakePlugin('plugin1', packagesDir);
final List<String> output =
await runCapturingPrint(runner, <String>['lint-android']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains(
'SKIPPING: Plugin does not have an Android implemenatation.')
],
));
});
test('skips non-inline plugins', () async {
createFakePlugin('plugin1', packagesDir,
platformSupport: <String, PlatformDetails>{
kPlatformAndroid: const PlatformDetails(PlatformSupport.federated)
});
final List<String> output =
await runCapturingPrint(runner, <String>['lint-android']);
expect(
output,
containsAllInOrder(
<Matcher>[
contains(
'SKIPPING: Plugin does not have an Android implemenatation.')
],
));
});
});
}