dartdoc_test.dart 2.5 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:platform/platform.dart';
import 'package:test/test.dart';

import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
9
import '../dartdoc.dart' show getBranchName, runPubProcess;
10 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

void main() {
  const String branchName = 'stable';
  test('getBranchName does not call git if env LUCI_BRANCH provided', () {
    final Platform platform = FakePlatform(
      environment: <String, String>{
        'LUCI_BRANCH': branchName,
      },
    );

    final ProcessManager processManager = FakeProcessManager.empty();

    expect(
      getBranchName(
        platform: platform,
        processManager: processManager,
      ),
      branchName,
    );
  });

  test('getBranchName calls git if env LUCI_BRANCH not provided', () {
    final Platform platform = FakePlatform(
      environment: <String, String>{},
    );

    final ProcessManager processManager = FakeProcessManager.list(
      <FakeCommand>[
        const FakeCommand(
          command: <String>['git', 'status', '-b', '--porcelain'],
          stdout: '## $branchName',
        ),
      ],
    );

    expect(
      getBranchName(
        platform: platform,
        processManager: processManager,
      ),
      branchName,
    );
    expect(processManager, hasNoRemainingExpectations);
  });

  test('getBranchName calls git if env LUCI_BRANCH is empty', () {
    final Platform platform = FakePlatform(
      environment: <String, String>{
        'LUCI_BRANCH': '',
      },
    );

    final ProcessManager processManager = FakeProcessManager.list(
      <FakeCommand>[
        const FakeCommand(
          command: <String>['git', 'status', '-b', '--porcelain'],
          stdout: '## $branchName',
        ),
      ],
    );

    expect(
      getBranchName(
        platform: platform,
        processManager: processManager,
      ),
      branchName,
    );
    expect(processManager, hasNoRemainingExpectations);
  });
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

  test("runPubProcess doesn't use the pub binary", () {
    final ProcessManager processManager = FakeProcessManager.list(
      <FakeCommand>[
        const FakeCommand(
          command: <String>['dart', 'pub', '--one', '--two'],
        ),
      ],
    );

    runPubProcess(
      dartBinaryPath: 'dart',
      arguments: <String>['--one', '--two'],
      processManager: processManager,
    );

    expect(processManager, hasNoRemainingExpectations);
  });
98
}