tool_backend_test.dart 3.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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:flutter_tools/src/base/io.dart';

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

final String toolBackend = fileSystem.path.join(getFlutterRoot(), 'packages', 'flutter_tools', 'bin', 'tool_backend.dart');
final String examplePath = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world');
final String dart = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'dart.bat' : 'dart');

void main() {
15
  testWithoutContext('tool_backend.dart exits if PROJECT_DIR is not set', () async {
16 17 18 19 20 21 22
    final ProcessResult result = await processManager.run(<String>[
      dart,
      toolBackend,
      'linux-x64',
      'debug',
    ]);

23 24 25 26 27 28 29
    expect(
      result,
      const ProcessResultMatcher(
        exitCode: 1,
        stderrPattern: 'PROJECT_DIR environment variable must be set to the location of Flutter project to be built.',
      ),
    );
30 31
  });

32
  testWithoutContext('tool_backend.dart exits if FLUTTER_ROOT is not set', () async {
33 34 35 36 37 38 39 40 41 42 43 44
    // Removing parent environment means that batch script cannot be run.
    final String dart = fileSystem.path.join(getFlutterRoot(), 'bin', 'cache', 'dart-sdk', 'bin', platform.isWindows ? 'dart.exe' : 'dart');

    final ProcessResult result = await processManager.run(<String>[
      dart,
      toolBackend,
      'linux-x64',
      'debug',
    ], environment: <String, String>{
      'PROJECT_DIR': examplePath,
    }, includeParentEnvironment: false); // Prevent FLUTTER_ROOT set by test environment from leaking

45 46 47 48 49 50 51
    expect(
      result,
      const ProcessResultMatcher(
        exitCode: 1,
        stderrPattern: 'FLUTTER_ROOT environment variable must be set to the location of the Flutter SDK.',
      ),
    );
52 53
  });

54
  testWithoutContext('tool_backend.dart exits if local engine does not match build mode', () async {
55 56 57 58 59 60 61 62 63 64
    final ProcessResult result = await processManager.run(<String>[
      dart,
      toolBackend,
      'linux-x64',
      'debug',
    ], environment: <String, String>{
      'PROJECT_DIR': examplePath,
      'LOCAL_ENGINE': 'release_foo_bar', // Does not contain "debug",
    });

65 66 67 68 69 70 71
    expect(
      result,
      const ProcessResultMatcher(
        exitCode: 1,
        stderrPattern: "ERROR: Requested build with Flutter local engine at 'release_foo_bar'",
      ),
    );
72
  });
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

  testWithoutContext('tool_backend.dart exits if local engine host does not match build mode', () async {
    final ProcessResult result = await processManager.run(<String>[
      dart,
      toolBackend,
      'linux-x64',
      'debug',
    ], environment: <String, String>{
      'PROJECT_DIR': examplePath,
      'LOCAL_ENGINE': 'debug_foo_bar', // OK
      'LOCAL_ENGINE_HOST': 'release_foo_bar', // Does not contain "debug",
    });

    expect(
      result,
      const ProcessResultMatcher(
        exitCode: 1,
        stderrPattern: "ERROR: Requested build with Flutter local engine host at 'release_foo_bar'",
      ),
    );
  });
94
}