downgrade_upgrade_integration_test.dart 4.26 KB
Newer Older
1 2 3 4
// 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.

5 6
// @dart = 2.8

7 8 9 10 11 12 13
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';
14
import 'test_utils.dart';
15

16 17
const String _kInitialVersion = 'v1.9.1';
const String _kBranch = 'dev';
18

19
final Stdio stdio = Stdio();
20 21
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: StdoutLogger(
  terminal: AnsiTerminal(
22
    platform: platform,
23
    stdio: stdio,
24
  ),
25
  stdio: stdio,
26 27
  outputPreferences: OutputPreferences.test(wrapText: true),
));
28
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

/// A test for flutter upgrade & downgrade that checks out a parallel flutter repo.
void main() {
  Directory parentDirectory;

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

  tearDown(() {
    try {
      parentDirectory.deleteSync(recursive: true);
    } on FileSystemException {
      print('Failed to delete test directory');
    }
  });

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

52 53
    int exitCode = 0;

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

59
    print('Step 1 - clone the $_kBranch of flutter into the test directory');
60
    exitCode = await processUtils.stream(<String>[
61 62 63 64
      'git',
      'clone',
      'https://github.com/flutter/flutter.git',
    ], workingDirectory: parentDirectory.path, trace: true);
65
    expect(exitCode, 0);
66

67
    print('Step 2 - switch to the $_kBranch');
68
    exitCode = await processUtils.stream(<String>[
69 70 71 72 73 74 75
      'git',
      'checkout',
      '--track',
      '-b',
      _kBranch,
      'origin/$_kBranch',
    ], workingDirectory: testDirectory.path, trace: true);
76
    expect(exitCode, 0);
77

78
    print('Step 3 - revert back to $_kInitialVersion');
79
    exitCode = await processUtils.stream(<String>[
80 81 82 83 84
      'git',
      'reset',
      '--hard',
      _kInitialVersion,
    ], workingDirectory: testDirectory.path, trace: true);
85
    expect(exitCode, 0);
86

87 88
    print('Step 4 - upgrade to the newest $_kBranch');
    // This should update the persistent tool state with the sha for HEAD
89
    exitCode = await processUtils.stream(<String>[
90 91
      flutterBin,
      'upgrade',
92
      '--verbose',
93 94
      '--working-directory=${testDirectory.path}'
    ], workingDirectory: testDirectory.path, trace: true);
95
    expect(exitCode, 0);
96

97
    print('Step 5 - verify that the version is different');
98 99 100 101 102 103 104 105 106
    final RunResult versionResult = await processUtils.run(<String>[
      'git',
      'describe',
      '--match',
      'v*.*.*',
      '--long',
      '--tags',
    ], workingDirectory: testDirectory.path);
    expect(versionResult.stdout, isNot(contains(_kInitialVersion)));
107
    print('current version is ${versionResult.stdout.trim()}\ninitial was $_kInitialVersion');
108

109
    print('Step 6 - downgrade back to the initial version');
110
    // Step 6. Downgrade back to initial version.
111
    exitCode = await processUtils.stream(<String>[
112 113 114 115 116
       flutterBin,
      'downgrade',
      '--no-prompt',
      '--working-directory=${testDirectory.path}'
    ], workingDirectory: testDirectory.path, trace: true);
117
    expect(exitCode, 0);
118

119
    print('Step 7 - verify downgraded version matches original version');
120 121 122 123 124 125 126 127 128 129
    // Step 7. Verify downgraded version matches original version.
    final RunResult oldVersionResult = await processUtils.run(<String>[
      'git',
      'describe',
      '--match',
      'v*.*.*',
      '--long',
      '--tags',
    ], workingDirectory: testDirectory.path);
    expect(oldVersionResult.stdout, contains(_kInitialVersion));
130
    print('current version is ${oldVersionResult.stdout.trim()}\ninitial was $_kInitialVersion');
131 132
  });
}