flutter_build_config_only_test.dart 1.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// 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_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';

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

// Test that configOnly creates the gradlew file and does not assemble and app.
void main() {
  late Directory tempDir;
  late String flutterBin;
  late Directory exampleAppDir;

  setUp(() async {
    tempDir = createResolvedTempDirectorySync('flutter_build_test.');
    flutterBin = fileSystem.path.join(
      getFlutterRoot(),
      'bin',
      'flutter',
    );
    exampleAppDir = tempDir.childDirectory('bbb').childDirectory('example');

27 28 29 30 31 32 33 34 35 36 37 38
    processManager.runSync(
      <String>[
        flutterBin,
        ...getLocalEngineArguments(),
        'create',
        '--template=plugin',
        '--platforms=android',
        'bbb',
        '-v',
      ],
      workingDirectory: tempDir.path,
    );
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  });

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

  test(
    'flutter build apk --config-only should create gradlew and not assemble',
    () async {
      final File gradleFile = fileSystem
          .directory(exampleAppDir)
          .childDirectory('android')
          .childFile(platform.isWindows ? 'gradlew.bat' : 'gradlew');
      // Ensure file is gone prior to configOnly running.
      await gradleFile.delete();

55 56 57 58 59 60 61 62 63 64 65
      final ProcessResult result = processManager.runSync(
        <String>[
          flutterBin,
          ...getLocalEngineArguments(),
          'build',
          'apk',
          '--target-platform=android-arm',
          '--config-only',
        ],
        workingDirectory: exampleAppDir.path,
      );
66 67 68 69 70 71 72

      expect(gradleFile, exists);
      expect(result.stdout, contains(RegExp(r'Config complete')));
      expect(result.stdout, isNot(contains(RegExp(r'Running Gradle task'))));
    },
  );
}