1
2
3
4
5
6
7
8
9
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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 'package:platform/platform.dart';
import 'package:process/process.dart';
import '../src/common.dart';
const String _kInitialVersion = 'v1.9.1+hotfix.6';
const String _kBranch = 'stable';
const FileSystem fileSystem = LocalFileSystem();
const ProcessManager processManager = LocalProcessManager();
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: StdoutLogger(
terminal: AnsiTerminal(
platform: const LocalPlatform(),
stdio: const Stdio(),
),
stdio: const Stdio(),
outputPreferences: OutputPreferences.test(wrapText: true),
timeoutConfiguration: const TimeoutConfiguration(),
));
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
/// 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');
}
});
test('Can upgrade and downgrade a Flutter checkout', () async {
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',
]);
// Step 1. Clone the dev branch of flutter into the test directory.
await processUtils.stream(<String>[
'git',
'clone',
'https://github.com/flutter/flutter.git',
], workingDirectory: parentDirectory.path, trace: true);
// Step 2. Switch to the dev branch.
await processUtils.stream(<String>[
'git',
'checkout',
'--track',
'-b',
_kBranch,
'origin/$_kBranch',
], workingDirectory: testDirectory.path, trace: true);
// Step 3. Revert to a prior version.
await processUtils.stream(<String>[
'git',
'reset',
'--hard',
_kInitialVersion,
], workingDirectory: testDirectory.path, trace: true);
// Step 4. Upgrade to the newest dev. This should update the persistent
// tool state with the sha for v1.14.3
await processUtils.stream(<String>[
flutterBin,
'upgrade',
'--working-directory=${testDirectory.path}'
], workingDirectory: testDirectory.path, trace: true);
// Step 5. Verify that the version is different.
final RunResult versionResult = await processUtils.run(<String>[
'git',
'describe',
'--match',
'v*.*.*',
'--first-parent',
'--long',
'--tags',
], workingDirectory: testDirectory.path);
expect(versionResult.stdout, isNot(contains(_kInitialVersion)));
// Step 6. Downgrade back to initial version.
await processUtils.stream(<String>[
flutterBin,
'downgrade',
'--no-prompt',
'--working-directory=${testDirectory.path}'
], workingDirectory: testDirectory.path, trace: true);
// 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));
});
}