plugins_test.dart 1.98 KB
Newer Older
1 2 3 4 5 6 7 8
// 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:file/file.dart';
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/template.dart';
9
import 'package:flutter_tools/src/flutter_plugins.dart';
10 11 12 13 14 15 16 17 18 19 20
import 'package:flutter_tools/src/isolated/mustache_template.dart';
import 'package:flutter_tools/src/platform_plugins.dart';
import 'package:flutter_tools/src/plugins.dart';
import 'package:flutter_tools/src/project.dart';

import '../../src/common.dart';

const TemplateRenderer renderer = MustacheTemplateRenderer();

void main() {

21
  testWithoutContext('Win32 injects Win32 plugins', () async {
22 23 24 25 26 27 28 29
    final FileSystem fileSystem = MemoryFileSystem.test();
    setUpProject(fileSystem);
    final FlutterProject flutterProject = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);

    await writeWindowsPluginFiles(flutterProject, <Plugin>[
      Plugin(
        name: 'test',
        path: 'foo',
30 31
        defaultPackagePlatforms: const <String, String>{},
        pluginDartClassPlatforms: const <String, String>{},
32 33 34 35 36
        platforms: const <String, PluginPlatform>{
          WindowsPlugin.kConfigKey: WindowsPlugin(
            name: 'test',
            pluginClass: 'Foo',
            variants: <PluginPlatformVariant>{PluginPlatformVariant.win32},
37 38
          ),
        },
39
        dependencies: <String>[],
40
        isDirectDependency: true,
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
      ),
    ], renderer);

    final Directory managed = flutterProject.windows.managedDirectory;
    expect(flutterProject.windows.generatedPluginCmakeFile, exists);
    expect(managed.childFile('generated_plugin_registrant.h'), exists);
    expect(
      managed.childFile('generated_plugin_registrant.cc').readAsStringSync(),
      contains('#include <test/foo.h>'),
    );
  });
}

void setUpProject(FileSystem fileSystem) {
  fileSystem.file('pubspec.yaml').createSync();
}