downgrade_upgrade_integration_test.dart 4.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/base/terminal.dart';

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

14
const String _kInitialVersion = '3.0.0';
15
const String _kBranch = 'beta';
16

17
final Stdio stdio = Stdio();
18
final BufferLogger logger = BufferLogger.test(
19
  terminal: AnsiTerminal(
20
    platform: platform,
21
    stdio: stdio,
22 23
  ),
  outputPreferences: OutputPreferences.test(wrapText: true),
24 25
);
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: logger);
26
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
27 28 29

/// A test for flutter upgrade & downgrade that checks out a parallel flutter repo.
void main() {
30
  late Directory parentDirectory;
31 32 33 34 35 36 37 38

  setUp(() {
    parentDirectory = fileSystem.systemTempDirectory
      .createTempSync('flutter_tools.');
    parentDirectory.createSync(recursive: true);
  });

  tearDown(() {
39
    tryToDelete(parentDirectory);
40 41
  });

42
  testWithoutContext('Can upgrade and downgrade a Flutter checkout', () async {
43 44 45 46 47 48 49 50
    final Directory testDirectory = parentDirectory.childDirectory('flutter');
    testDirectory.createSync(recursive: true);

    // Enable longpaths for windows integration test.
    await processManager.run(<String>[
      'git', 'config', '--system', 'core.longpaths', 'true',
    ]);

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    void checkExitCode(int code) {
      expect(
        exitCode,
        0,
        reason: '''
trace:
${logger.traceText}

status:
${logger.statusText}

error:
${logger.errorText}''',
      );
    }

67
    printOnFailure('Step 1 - clone the $_kBranch of flutter into the test directory');
68
    exitCode = await processUtils.stream(<String>[
69 70 71 72
      'git',
      'clone',
      'https://github.com/flutter/flutter.git',
    ], workingDirectory: parentDirectory.path, trace: true);
73
    checkExitCode(exitCode);
74

75
    printOnFailure('Step 2 - switch to the $_kBranch');
76
    exitCode = await processUtils.stream(<String>[
77 78 79 80 81 82 83
      'git',
      'checkout',
      '--track',
      '-b',
      _kBranch,
      'origin/$_kBranch',
    ], workingDirectory: testDirectory.path, trace: true);
84
    checkExitCode(exitCode);
85

86
    printOnFailure('Step 3 - revert back to $_kInitialVersion');
87
    exitCode = await processUtils.stream(<String>[
88 89 90 91 92
      'git',
      'reset',
      '--hard',
      _kInitialVersion,
    ], workingDirectory: testDirectory.path, trace: true);
93
    checkExitCode(exitCode);
94

95
    printOnFailure('Step 4 - upgrade to the newest $_kBranch');
96
    // This should update the persistent tool state with the sha for HEAD
97
    // This is probably a source of flakes as it mutates system-global state.
98
    exitCode = await processUtils.stream(<String>[
99 100
      flutterBin,
      'upgrade',
101
      '--verbose',
102
      '--working-directory=${testDirectory.path}',
103 104 105 106
      // we intentionally run this in a directory outside the test repo to
      // verify the tool overrides the working directory when invoking git
    ], workingDirectory: parentDirectory.path, trace: true);
    checkExitCode(exitCode);
107

108
    printOnFailure('Step 5 - verify that the version is different');
109 110 111 112
    final RunResult versionResult = await processUtils.run(<String>[
      'git',
      'describe',
      '--match',
113
      '*.*.*',
114 115 116 117
      '--long',
      '--tags',
    ], workingDirectory: testDirectory.path);
    expect(versionResult.stdout, isNot(contains(_kInitialVersion)));
118
    printOnFailure('current version is ${versionResult.stdout.trim()}\ninitial was $_kInitialVersion');
119

120
    printOnFailure('Step 6 - downgrade back to the initial version');
121
    exitCode = await processUtils.stream(<String>[
122 123 124
       flutterBin,
      'downgrade',
      '--no-prompt',
125
      '--working-directory=${testDirectory.path}',
126 127
    ], workingDirectory: parentDirectory.path, trace: true);
    checkExitCode(exitCode);
128

129
    printOnFailure('Step 7 - verify downgraded version matches original version');
130 131 132 133
    final RunResult oldVersionResult = await processUtils.run(<String>[
      'git',
      'describe',
      '--match',
134
      '*.*.*',
135 136 137 138
      '--long',
      '--tags',
    ], workingDirectory: testDirectory.path);
    expect(oldVersionResult.stdout, contains(_kInitialVersion));
139
    printOnFailure('current version is ${oldVersionResult.stdout.trim()}\ninitial was $_kInitialVersion');
140 141
  });
}