Files
packages/script/tool/test/common/plugin_utils_test.dart
stuartmorgan 41f1c806f2 [flutter_plugin_tools] Introduce a class for packages (#4252)
Packages are the primary conceptual object in the tool, but currently they are represented simply as Directory (or occasionally a path string). This introduces an object for packages and:
- moves a number of existing utility methods into it
- sweeps the code for the obvious cases of using `Directory` to represent a package, especially in method signatures and migrates them
- notes a few places where we should migrate later, to avoid ballooning the size of the PR

There are no doubt other cases not caught in the sweep, but this gives us a foundation both for new code, and to migrate incrementally toward as we find existing code that was missed.
2021-08-24 13:29:56 -07:00

205 lines
7.6 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 '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/common/repository_package.dart';
import 'package:test/test.dart';
import '../util.dart';
void main() {
late FileSystem fileSystem;
late Directory packagesDir;
setUp(() {
fileSystem = MemoryFileSystem();
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
});
group('pluginSupportsPlatform', () {
test('no platforms', () async {
final RepositoryPackage plugin =
RepositoryPackage(createFakePlugin('plugin', packagesDir));
expect(pluginSupportsPlatform(kPlatformAndroid, plugin), isFalse);
expect(pluginSupportsPlatform(kPlatformIos, plugin), isFalse);
expect(pluginSupportsPlatform(kPlatformLinux, plugin), isFalse);
expect(pluginSupportsPlatform(kPlatformMacos, plugin), isFalse);
expect(pluginSupportsPlatform(kPlatformWeb, plugin), isFalse);
expect(pluginSupportsPlatform(kPlatformWindows, plugin), isFalse);
});
test('all platforms', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin', packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
kPlatformLinux: PlatformSupport.inline,
kPlatformMacos: PlatformSupport.inline,
kPlatformWeb: PlatformSupport.inline,
kPlatformWindows: PlatformSupport.inline,
}));
expect(pluginSupportsPlatform(kPlatformAndroid, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformIos, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformLinux, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformMacos, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformWeb, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformWindows, plugin), isTrue);
});
test('some platforms', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformLinux: PlatformSupport.inline,
kPlatformWeb: PlatformSupport.inline,
},
));
expect(pluginSupportsPlatform(kPlatformAndroid, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformIos, plugin), isFalse);
expect(pluginSupportsPlatform(kPlatformLinux, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformMacos, plugin), isFalse);
expect(pluginSupportsPlatform(kPlatformWeb, plugin), isTrue);
expect(pluginSupportsPlatform(kPlatformWindows, plugin), isFalse);
});
test('inline plugins are only detected as inline', () async {
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.inline,
kPlatformIos: PlatformSupport.inline,
kPlatformLinux: PlatformSupport.inline,
kPlatformMacos: PlatformSupport.inline,
kPlatformWeb: PlatformSupport.inline,
kPlatformWindows: PlatformSupport.inline,
},
));
expect(
pluginSupportsPlatform(kPlatformAndroid, plugin,
requiredMode: PlatformSupport.inline),
isTrue);
expect(
pluginSupportsPlatform(kPlatformAndroid, plugin,
requiredMode: PlatformSupport.federated),
isFalse);
expect(
pluginSupportsPlatform(kPlatformIos, plugin,
requiredMode: PlatformSupport.inline),
isTrue);
expect(
pluginSupportsPlatform(kPlatformIos, plugin,
requiredMode: PlatformSupport.federated),
isFalse);
expect(
pluginSupportsPlatform(kPlatformLinux, plugin,
requiredMode: PlatformSupport.inline),
isTrue);
expect(
pluginSupportsPlatform(kPlatformLinux, plugin,
requiredMode: PlatformSupport.federated),
isFalse);
expect(
pluginSupportsPlatform(kPlatformMacos, plugin,
requiredMode: PlatformSupport.inline),
isTrue);
expect(
pluginSupportsPlatform(kPlatformMacos, plugin,
requiredMode: PlatformSupport.federated),
isFalse);
expect(
pluginSupportsPlatform(kPlatformWeb, plugin,
requiredMode: PlatformSupport.inline),
isTrue);
expect(
pluginSupportsPlatform(kPlatformWeb, plugin,
requiredMode: PlatformSupport.federated),
isFalse);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
requiredMode: PlatformSupport.inline),
isTrue);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
requiredMode: PlatformSupport.federated),
isFalse);
});
test('federated plugins are only detected as federated', () async {
const String pluginName = 'plugin';
final RepositoryPackage plugin = RepositoryPackage(createFakePlugin(
pluginName,
packagesDir,
platformSupport: <String, PlatformSupport>{
kPlatformAndroid: PlatformSupport.federated,
kPlatformIos: PlatformSupport.federated,
kPlatformLinux: PlatformSupport.federated,
kPlatformMacos: PlatformSupport.federated,
kPlatformWeb: PlatformSupport.federated,
kPlatformWindows: PlatformSupport.federated,
},
));
expect(
pluginSupportsPlatform(kPlatformAndroid, plugin,
requiredMode: PlatformSupport.federated),
isTrue);
expect(
pluginSupportsPlatform(kPlatformAndroid, plugin,
requiredMode: PlatformSupport.inline),
isFalse);
expect(
pluginSupportsPlatform(kPlatformIos, plugin,
requiredMode: PlatformSupport.federated),
isTrue);
expect(
pluginSupportsPlatform(kPlatformIos, plugin,
requiredMode: PlatformSupport.inline),
isFalse);
expect(
pluginSupportsPlatform(kPlatformLinux, plugin,
requiredMode: PlatformSupport.federated),
isTrue);
expect(
pluginSupportsPlatform(kPlatformLinux, plugin,
requiredMode: PlatformSupport.inline),
isFalse);
expect(
pluginSupportsPlatform(kPlatformMacos, plugin,
requiredMode: PlatformSupport.federated),
isTrue);
expect(
pluginSupportsPlatform(kPlatformMacos, plugin,
requiredMode: PlatformSupport.inline),
isFalse);
expect(
pluginSupportsPlatform(kPlatformWeb, plugin,
requiredMode: PlatformSupport.federated),
isTrue);
expect(
pluginSupportsPlatform(kPlatformWeb, plugin,
requiredMode: PlatformSupport.inline),
isFalse);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
requiredMode: PlatformSupport.federated),
isTrue);
expect(
pluginSupportsPlatform(kPlatformWindows, plugin,
requiredMode: PlatformSupport.inline),
isFalse);
});
});
}