downgrade_upgrade_integration_test.dart 4.26 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 15
const String _kInitialVersion = 'v1.9.1';
const String _kBranch = 'dev';
16

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

/// 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');
    }
  });

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

50 51
    int exitCode = 0;

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

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

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

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

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

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

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

118
    print('Step 7 - verify downgraded version matches original version');
119 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*.*.*',
      '--first-parent',
      '--long',
      '--tags',
    ], workingDirectory: testDirectory.path);
    expect(oldVersionResult.stdout, contains(_kInitialVersion));
130
    print('current version is ${oldVersionResult.stdout.trim()}\ninitial was $_kInitialVersion');
131 132
  });
}