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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// 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:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/commands/update_packages.dart';
import '../src/common.dart';
// An example pubspec.yaml from flutter, not necessary for it to be up to date.
const String kFlutterPubspecYaml = r'''
name: flutter
author: Flutter Authors <flutter-dev@googlegroups.com>
description: A framework for writing Flutter applications
homepage: http://flutter.dev
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.2.2 <3.0.0"
dependencies:
# To update these, use "flutter update-packages --force-upgrade".
collection: 1.14.11
meta: 1.1.8
typed_data: 1.1.6
vector_math: 2.0.8
sky_engine:
sdk: flutter
gallery:
git:
url: https://github.com/flutter/gallery.git
ref: d00362e6bdd0f9b30bba337c358b9e4a6e4ca950
dev_dependencies:
flutter_test:
sdk: flutter
flutter_goldens:
sdk: flutter
mockito: 4.1.1
archive: 2.0.11 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: 1437
''';
const String kInvalidGitPubspec = '''
name: flutter
author: Flutter Authors <flutter-dev@googlegroups.com>
description: A framework for writing Flutter applications
homepage: http://flutter.dev
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.2.2 <3.0.0"
dependencies:
# To update these, use "flutter update-packages --force-upgrade".
collection: 1.14.11
meta: 1.1.8
typed_data: 1.1.6
vector_math: 2.0.8
sky_engine:
sdk: flutter
gallery:
git:
''';
void main() {
testWithoutContext('createTemporaryFlutterSdk creates an unpinned flutter SDK', () {
final FileSystem fileSystem = MemoryFileSystem.test();
// Setup simplified Flutter SDK.
final Directory flutterSdk = fileSystem.directory('flutter')
..createSync();
// Create version file
flutterSdk.childFile('version').writeAsStringSync('1.2.3');
// Create a pubspec file
final Directory flutter = flutterSdk
.childDirectory('packages')
.childDirectory('flutter')
..createSync(recursive: true);
flutter
.childFile('pubspec.yaml')
.writeAsStringSync(kFlutterPubspecYaml);
// Create already parsed pubspecs.
final PubspecYaml flutterPubspec = PubspecYaml(flutter);
final PubspecDependency gitDependency = flutterPubspec.dependencies.whereType<PubspecDependency>().firstWhere((PubspecDependency dep) => dep.kind == DependencyKind.git);
expect(
gitDependency.lockLine,
'''
git:
url: https://github.com/flutter/gallery.git
ref: d00362e6bdd0f9b30bba337c358b9e4a6e4ca950
''',
);
final Directory result = createTemporaryFlutterSdk(
fileSystem,
flutterSdk,
<PubspecYaml>[flutterPubspec],
);
expect(result, exists);
// The version file exists.
expect(result.childFile('version'), exists);
expect(result.childFile('version').readAsStringSync(), '1.2.3');
// The sky_engine package exists
expect(fileSystem.directory('${result.path}/bin/cache/pkg/sky_engine'), exists);
// The flutter pubspec exists
final File pubspecFile = fileSystem.file('${result.path}/packages/flutter/pubspec.yaml');
expect(pubspecFile, exists);
// The flutter pubspec contains `any` dependencies.
final PubspecYaml outputPubspec = PubspecYaml(pubspecFile.parent);
expect(outputPubspec.name, 'flutter');
expect(outputPubspec.dependencies.first.name, 'collection');
expect(outputPubspec.dependencies.first.version, 'any');
});
testWithoutContext('Throws a StateError on a malformed git: reference', () {
final FileSystem fileSystem = MemoryFileSystem.test();
// Setup simplified Flutter SDK.
final Directory flutterSdk = fileSystem.directory('flutter')
..createSync();
// Create version file
flutterSdk.childFile('version').writeAsStringSync('1.2.3');
// Create a pubspec file
final Directory flutter = flutterSdk
.childDirectory('packages')
.childDirectory('flutter')
..createSync(recursive: true);
flutter
.childFile('pubspec.yaml')
.writeAsStringSync(kInvalidGitPubspec);
expect(
() => PubspecYaml(flutter),
throwsStateError,
);
});
}