build_aar_test.dart 2.78 KB
Newer Older
1 2 3 4 5
// Copyright 2019 The Chromium 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:args/command_runner.dart';
6
import 'package:flutter_tools/src/android/android_builder.dart';
7 8 9
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_aar.dart';
10
import 'package:flutter_tools/src/reporting/reporting.dart';
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

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

void main() {
  Cache.disableLocking();

  group('getUsage', () {
    Directory tempDir;

    setUp(() {
      tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
    });

    tearDown(() {
      tryToDelete(tempDir);
    });

    Future<BuildAarCommand> runCommandIn(String target, { List<String> arguments }) async {
      final BuildAarCommand command = BuildAarCommand();
      final CommandRunner<void> runner = createTestCommandRunner(command);
      await runner.run(<String>[
        'aar',
        ...?arguments,
        target,
      ]);
      return command;
    }

    testUsingContext('indicate that project is a module', () async {
      final String projectPath = await createProject(tempDir,
          arguments: <String>['--no-pub', '--template=module']);

      final BuildAarCommand command = await runCommandIn(projectPath);
      expect(await command.usageValues,
46
          containsPair(CustomDimensions.commandBuildAarProjectType, 'module'));
47 48

    }, overrides: <Type, Generator>{
49
      AndroidBuilder: () => FakeAndroidBuilder(),
50 51 52 53 54 55 56 57
    }, timeout: allowForCreateFlutterProject);

    testUsingContext('indicate that project is a plugin', () async {
      final String projectPath = await createProject(tempDir,
          arguments: <String>['--no-pub', '--template=plugin', '--project-name=aar_test']);

      final BuildAarCommand command = await runCommandIn(projectPath);
      expect(await command.usageValues,
58
          containsPair(CustomDimensions.commandBuildAarProjectType, 'plugin'));
59 60

    }, overrides: <Type, Generator>{
61
      AndroidBuilder: () => FakeAndroidBuilder(),
62 63 64 65 66 67 68 69 70
    }, timeout: allowForCreateFlutterProject);

    testUsingContext('indicate the target platform', () async {
      final String projectPath = await createProject(tempDir,
          arguments: <String>['--no-pub', '--template=module']);

      final BuildAarCommand command = await runCommandIn(projectPath,
          arguments: <String>['--target-platform=android-arm']);
      expect(await command.usageValues,
71
          containsPair(CustomDimensions.commandBuildAarTargetPlatform, 'android-arm'));
72 73

    }, overrides: <Type, Generator>{
74
      AndroidBuilder: () => FakeAndroidBuilder(),
75 76 77
    }, timeout: allowForCreateFlutterProject);
  });
}