blob: b3cedf944bcfa94c22909f395010ae5974bc7bb1 [file] [log] [blame]
Sarah Zakarias49ba9742017-09-26 14:48:52 +02001// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ralph Bergmannc65e9d12018-05-30 16:51:25 +02005import 'dart:async';
6
fmatosqg197d4312018-05-21 10:52:33 +10007import 'package:file/file.dart';
8import 'package:file/memory.dart';
9import 'package:flutter_tools/src/base/file_system.dart';
Sarah Zakarias49ba9742017-09-26 14:48:52 +020010import 'package:flutter_tools/src/cache.dart';
11import 'package:flutter_tools/src/flutter_manifest.dart';
Sarah Zakarias49ba9742017-09-26 14:48:52 +020012
13import 'src/common.dart';
14import 'src/context.dart';
Danny Tuppenya74f5912018-09-04 17:12:24 +010015import 'src/pubspec_schema.dart';
Sarah Zakarias49ba9742017-09-26 14:48:52 +020016
17void main() {
18 setUpAll(() {
19 Cache.flutterRoot = getFlutterRoot();
20 });
21
22 group('FlutterManifest', () {
Sarah Zakarias3cbbbf02017-09-26 23:14:20 +020023 testUsingContext('is empty when the pubspec.yaml file is empty', () async {
Jonah Williams4ff46712019-04-29 08:21:32 -070024 final FlutterManifest flutterManifest = FlutterManifest.createFromString('');
Sarah Zakarias3cbbbf02017-09-26 23:14:20 +020025 expect(flutterManifest.isEmpty, true);
26 expect(flutterManifest.appName, '');
27 expect(flutterManifest.usesMaterialDesign, false);
28 expect(flutterManifest.fontsDescriptor, isEmpty);
29 expect(flutterManifest.fonts, isEmpty);
30 expect(flutterManifest.assets, isEmpty);
31 });
32
Sarah Zakarias49ba9742017-09-26 14:48:52 +020033 test('has no fonts or assets when the "flutter" section is empty', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +010034 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +020035name: test
36dependencies:
37 flutter:
38 sdk: flutter
39''';
Jonah Williams4ff46712019-04-29 08:21:32 -070040 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Sarah Zakarias49ba9742017-09-26 14:48:52 +020041 expect(flutterManifest, isNotNull);
Sarah Zakarias3cbbbf02017-09-26 23:14:20 +020042 expect(flutterManifest.isEmpty, false);
Sarah Zakarias49ba9742017-09-26 14:48:52 +020043 expect(flutterManifest.appName, 'test');
44 expect(flutterManifest.usesMaterialDesign, false);
45 expect(flutterManifest.fontsDescriptor, isEmpty);
46 expect(flutterManifest.fonts, isEmpty);
47 expect(flutterManifest.assets, isEmpty);
48 });
49
50 test('knows if material design is used', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +010051 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +020052name: test
53dependencies:
54 flutter:
55 sdk: flutter
56flutter:
57 uses-material-design: true
58''';
Jonah Williams4ff46712019-04-29 08:21:32 -070059 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Sarah Zakarias49ba9742017-09-26 14:48:52 +020060 expect(flutterManifest.usesMaterialDesign, true);
61 });
62
63 test('has two assets', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +010064 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +020065name: test
66dependencies:
67 flutter:
68 sdk: flutter
69flutter:
70 uses-material-design: true
71 assets:
72 - a/foo
73 - a/bar
74''';
Jonah Williams4ff46712019-04-29 08:21:32 -070075 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Michael Goderbauer84580b52018-01-24 13:16:23 -080076 expect(flutterManifest.assets.length, 2);
77 expect(flutterManifest.assets[0], Uri.parse('a/foo'));
78 expect(flutterManifest.assets[1], Uri.parse('a/bar'));
Sarah Zakarias49ba9742017-09-26 14:48:52 +020079 });
80
81 test('has one font family with one asset', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +010082 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +020083name: test
84dependencies:
85 flutter:
86 sdk: flutter
87flutter:
88 uses-material-design: true
89 fonts:
90 - family: foo
91 fonts:
92 - asset: a/bar
93''';
Jonah Williams4ff46712019-04-29 08:21:32 -070094 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Jason Simmons3581b3a2018-10-01 14:14:48 -070095 final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
96 expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +020097 final List<Font> fonts = flutterManifest.fonts;
98 expect(fonts.length, 1);
99 final Font font = fonts[0];
Jason Simmons3581b3a2018-10-01 14:14:48 -0700100 final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}]}; // ignore: always_specify_types
101 expect(font.descriptor, fooFontDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200102 expect(font.familyName, 'foo');
103 final List<FontAsset> assets = font.fontAssets;
104 expect(assets.length, 1);
105 final FontAsset fontAsset = assets[0];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800106 expect(fontAsset.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200107 expect(fontAsset.weight, isNull);
108 expect(fontAsset.style, isNull);
109 });
110
111 test('has one font family with a simple asset and one with weight', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +0100112 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200113name: test
114dependencies:
115 flutter:
116 sdk: flutter
117flutter:
118 uses-material-design: true
119 fonts:
120 - family: foo
121 fonts:
122 - asset: a/bar
123 - asset: a/bar
124 weight: 400
125''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700126 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Jason Simmons3581b3a2018-10-01 14:14:48 -0700127 final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
128 expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200129 final List<Font> fonts = flutterManifest.fonts;
130 expect(fonts.length, 1);
131 final Font font = fonts[0];
Jason Simmons3581b3a2018-10-01 14:14:48 -0700132 final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}]}; // ignore: always_specify_types
133 expect(font.descriptor, fooFontDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200134 expect(font.familyName, 'foo');
135 final List<FontAsset> assets = font.fontAssets;
136 expect(assets.length, 2);
137 final FontAsset fontAsset0 = assets[0];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800138 expect(fontAsset0.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200139 expect(fontAsset0.weight, isNull);
140 expect(fontAsset0.style, isNull);
141 final FontAsset fontAsset1 = assets[1];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800142 expect(fontAsset1.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200143 expect(fontAsset1.weight, 400);
144 expect(fontAsset1.style, isNull);
145 });
146
147 test('has one font family with a simple asset and one with weight and style', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +0100148 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200149name: test
150dependencies:
151 flutter:
152 sdk: flutter
153flutter:
154 uses-material-design: true
155 fonts:
156 - family: foo
157 fonts:
158 - asset: a/bar
159 - asset: a/bar
160 weight: 400
161 style: italic
162''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700163 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Jason Simmons3581b3a2018-10-01 14:14:48 -0700164 final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200165
Jason Simmons3581b3a2018-10-01 14:14:48 -0700166 expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200167 final List<Font> fonts = flutterManifest.fonts;
168 expect(fonts.length, 1);
169 final Font font = fonts[0];
Jason Simmons3581b3a2018-10-01 14:14:48 -0700170 final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
171 expect(font.descriptor, fooFontDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200172 expect(font.familyName, 'foo');
173 final List<FontAsset> assets = font.fontAssets;
174 expect(assets.length, 2);
175 final FontAsset fontAsset0 = assets[0];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800176 expect(fontAsset0.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200177 expect(fontAsset0.weight, isNull);
178 expect(fontAsset0.style, isNull);
179 final FontAsset fontAsset1 = assets[1];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800180 expect(fontAsset1.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200181 expect(fontAsset1.weight, 400);
182 expect(fontAsset1.style, 'italic');
183 });
184
185 test('has two font families, each with one simple asset and one with weight and style', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +0100186 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200187name: test
188dependencies:
189 flutter:
190 sdk: flutter
191flutter:
192 uses-material-design: true
193 fonts:
194 - family: foo
195 fonts:
196 - asset: a/bar
197 - asset: a/bar
198 weight: 400
199 style: italic
200 - family: bar
201 fonts:
202 - asset: a/baz
203 - weight: 400
204 asset: a/baz
205 style: italic
206''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700207 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Jason Simmons3581b3a2018-10-01 14:14:48 -0700208 final dynamic expectedFontsDescriptor = <dynamic>[
209 {'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}, // ignore: always_specify_types
210 {'fonts': [{'asset': 'a/baz'}, {'style': 'italic', 'weight': 400, 'asset': 'a/baz'}], 'family': 'bar'}, // ignore: always_specify_types
211 ];
212 expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200213 final List<Font> fonts = flutterManifest.fonts;
214 expect(fonts.length, 2);
215
216 final Font fooFont = fonts[0];
Jason Simmons3581b3a2018-10-01 14:14:48 -0700217 final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
218 expect(fooFont.descriptor, fooFontDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200219 expect(fooFont.familyName, 'foo');
220 final List<FontAsset> fooAassets = fooFont.fontAssets;
221 expect(fooAassets.length, 2);
222 final FontAsset fooFontAsset0 = fooAassets[0];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800223 expect(fooFontAsset0.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200224 expect(fooFontAsset0.weight, isNull);
225 expect(fooFontAsset0.style, isNull);
226 final FontAsset fooFontAsset1 = fooAassets[1];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800227 expect(fooFontAsset1.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200228 expect(fooFontAsset1.weight, 400);
229 expect(fooFontAsset1.style, 'italic');
230
231 final Font barFont = fonts[1];
Jason Simmons3581b3a2018-10-01 14:14:48 -0700232 const String fontDescriptor = '{family: bar, fonts: [{asset: a/baz}, {weight: 400, style: italic, asset: a/baz}]}'; // ignore: always_specify_types
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200233 expect(barFont.descriptor.toString(), fontDescriptor);
234 expect(barFont.familyName, 'bar');
235 final List<FontAsset> barAssets = barFont.fontAssets;
236 expect(barAssets.length, 2);
237 final FontAsset barFontAsset0 = barAssets[0];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800238 expect(barFontAsset0.assetUri.path, 'a/baz');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200239 expect(barFontAsset0.weight, isNull);
240 expect(barFontAsset0.style, isNull);
241 final FontAsset barFontAsset1 = barAssets[1];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800242 expect(barFontAsset1.assetUri.path, 'a/baz');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200243 expect(barFontAsset1.weight, 400);
244 expect(barFontAsset1.style, 'italic');
245 });
246
Josh Sorefc5a59452018-03-07 00:36:03 -0500247 testUsingContext('has only one of two font families when one declaration is missing the "family" option', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +0100248 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200249name: test
250dependencies:
251 flutter:
252 sdk: flutter
253flutter:
254 uses-material-design: true
255 fonts:
256 - family: foo
257 fonts:
258 - asset: a/bar
259 - asset: a/bar
260 weight: 400
261 style: italic
262 - fonts:
263 - asset: a/baz
264 - asset: a/baz
265 weight: 400
266 style: italic
267''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700268 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200269
Jason Simmons3581b3a2018-10-01 14:14:48 -0700270 final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
271 expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200272 final List<Font> fonts = flutterManifest.fonts;
273 expect(fonts.length, 1);
274 final Font fooFont = fonts[0];
Jason Simmons3581b3a2018-10-01 14:14:48 -0700275 final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
276 expect(fooFont.descriptor, fooFontDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200277 expect(fooFont.familyName, 'foo');
278 final List<FontAsset> fooAassets = fooFont.fontAssets;
279 expect(fooAassets.length, 2);
280 final FontAsset fooFontAsset0 = fooAassets[0];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800281 expect(fooFontAsset0.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200282 expect(fooFontAsset0.weight, isNull);
283 expect(fooFontAsset0.style, isNull);
284 final FontAsset fooFontAsset1 = fooAassets[1];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800285 expect(fooFontAsset1.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200286 expect(fooFontAsset1.weight, 400);
287 expect(fooFontAsset1.style, 'italic');
288 });
289
Josh Sorefc5a59452018-03-07 00:36:03 -0500290 testUsingContext('has only one of two font families when one declaration is missing the "fonts" option', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +0100291 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200292name: test
293dependencies:
294 flutter:
295 sdk: flutter
296flutter:
297 uses-material-design: true
298 fonts:
299 - family: foo
300 fonts:
301 - asset: a/bar
302 - asset: a/bar
303 weight: 400
304 style: italic
305 - family: bar
306''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700307 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Jason Simmons3581b3a2018-10-01 14:14:48 -0700308 final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types
309 expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200310 final List<Font> fonts = flutterManifest.fonts;
311 expect(fonts.length, 1);
312 final Font fooFont = fonts[0];
Jason Simmons3581b3a2018-10-01 14:14:48 -0700313 final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types
314 expect(fooFont.descriptor, fooFontDescriptor);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200315 expect(fooFont.familyName, 'foo');
316 final List<FontAsset> fooAassets = fooFont.fontAssets;
317 expect(fooAassets.length, 2);
318 final FontAsset fooFontAsset0 = fooAassets[0];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800319 expect(fooFontAsset0.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200320 expect(fooFontAsset0.weight, isNull);
321 expect(fooFontAsset0.style, isNull);
322 final FontAsset fooFontAsset1 = fooAassets[1];
Michael Goderbauer84580b52018-01-24 13:16:23 -0800323 expect(fooFontAsset1.assetUri.path, 'a/bar');
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200324 expect(fooFontAsset1.weight, 400);
325 expect(fooFontAsset1.style, 'italic');
326 });
327
328 testUsingContext('has no font family when declaration is missing the "asset" option', () async {
Alexandre Ardhuin841d5d72018-02-01 07:51:26 +0100329 const String manifest = '''
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200330name: test
331dependencies:
332 flutter:
333 sdk: flutter
334flutter:
335 uses-material-design: true
336 fonts:
337 - family: foo
338 fonts:
339 - weight: 400
340''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700341 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200342
Jason Simmons3581b3a2018-10-01 14:14:48 -0700343 expect(flutterManifest.fontsDescriptor, <dynamic>[]);
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200344 final List<Font> fonts = flutterManifest.fonts;
345 expect(fonts.length, 0);
346 });
Victor Choueiri7edd5c82018-03-19 23:55:54 +0200347
348 test('allows a blank flutter section', () async {
349 const String manifest = '''
350name: test
351dependencies:
352 flutter:
353 sdk: flutter
354flutter:
355''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700356 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Victor Choueiri7edd5c82018-03-19 23:55:54 +0200357 expect(flutterManifest.isEmpty, false);
Greg Spencer0ff9e8a2018-10-10 11:01:40 -0700358 expect(flutterManifest.isModule, false);
Mikkel Nygaard Ravn651c5ab2018-08-02 19:16:32 +0200359 expect(flutterManifest.isPlugin, false);
360 expect(flutterManifest.androidPackage, null);
361 });
362
Greg Spencer0ff9e8a2018-10-10 11:01:40 -0700363 test('allows a module declaration', () async {
Mikkel Nygaard Ravn651c5ab2018-08-02 19:16:32 +0200364 const String manifest = '''
365name: test
366flutter:
Greg Spencer0ff9e8a2018-10-10 11:01:40 -0700367 module:
Mikkel Nygaard Ravn651c5ab2018-08-02 19:16:32 +0200368 androidPackage: com.example
369''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700370 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Greg Spencer0ff9e8a2018-10-10 11:01:40 -0700371 expect(flutterManifest.isModule, true);
Mikkel Nygaard Ravn651c5ab2018-08-02 19:16:32 +0200372 expect(flutterManifest.androidPackage, 'com.example');
373 });
374
375 test('allows a plugin declaration', () async {
376 const String manifest = '''
377name: test
378flutter:
379 plugin:
380 androidPackage: com.example
381''';
Jonah Williams4ff46712019-04-29 08:21:32 -0700382 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Mikkel Nygaard Ravn651c5ab2018-08-02 19:16:32 +0200383 expect(flutterManifest.isPlugin, true);
384 expect(flutterManifest.androidPackage, 'com.example');
Victor Choueiri7edd5c82018-03-19 23:55:54 +0200385 });
Ralph Bergmannc65e9d12018-05-30 16:51:25 +0200386
387 Future<void> checkManifestVersion({
388 String manifest,
389 String expectedAppVersion,
390 String expectedBuildName,
KyleWong4b4a94002019-02-13 23:48:03 +0800391 String expectedBuildNumber,
Ralph Bergmannc65e9d12018-05-30 16:51:25 +0200392 }) async {
Jonah Williams4ff46712019-04-29 08:21:32 -0700393 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
Ralph Bergmannc65e9d12018-05-30 16:51:25 +0200394 expect(flutterManifest.appVersion, expectedAppVersion);
395 expect(flutterManifest.buildName, expectedBuildName);
396 expect(flutterManifest.buildNumber, expectedBuildNumber);
397 }
398
KyleWong4b4a94002019-02-13 23:48:03 +0800399 test('parses major.minor.patch+build version clause 1', () async {
Ralph Bergmannc65e9d12018-05-30 16:51:25 +0200400 const String manifest = '''
401name: test
402version: 1.0.0+2
403dependencies:
404 flutter:
405 sdk: flutter
406flutter:
407''';
408 await checkManifestVersion(
409 manifest: manifest,
410 expectedAppVersion: '1.0.0+2',
411 expectedBuildName: '1.0.0',
KyleWong4b4a94002019-02-13 23:48:03 +0800412 expectedBuildNumber: '2',
413 );
414 });
415
416 test('parses major.minor.patch+build version clause 2', () async {
417 const String manifest = '''
418name: test
419version: 1.0.0-beta+exp.sha.5114f85
420dependencies:
421 flutter:
422 sdk: flutter
423flutter:
424''';
425 await checkManifestVersion(
426 manifest: manifest,
427 expectedAppVersion: '1.0.0-beta+exp.sha.5114f85',
428 expectedBuildName: '1.0.0-beta',
429 expectedBuildNumber: 'exp.sha.5114f85',
Ralph Bergmannc65e9d12018-05-30 16:51:25 +0200430 );
431 });
432
433 test('parses major.minor+build version clause', () async {
434 const String manifest = '''
435name: test
436version: 1.0+2
437dependencies:
438 flutter:
439 sdk: flutter
440flutter:
441''';
442 await checkManifestVersion(
443 manifest: manifest,
444 expectedAppVersion: '1.0+2',
445 expectedBuildName: '1.0',
KyleWong4b4a94002019-02-13 23:48:03 +0800446 expectedBuildNumber: '2',
Ralph Bergmannc65e9d12018-05-30 16:51:25 +0200447 );
448 });
449
450 test('parses empty version clause', () async {
451 const String manifest = '''
452name: test
453version:
454dependencies:
455 flutter:
456 sdk: flutter
457flutter:
458''';
459 await checkManifestVersion(
460 manifest: manifest,
461 expectedAppVersion: null,
462 expectedBuildName: null,
463 expectedBuildNumber: null,
464 );
465 });
466 test('parses no version clause', () async {
467 const String manifest = '''
468name: test
469dependencies:
470 flutter:
471 sdk: flutter
472flutter:
473''';
474 await checkManifestVersion(
475 manifest: manifest,
476 expectedAppVersion: null,
477 expectedBuildName: null,
478 expectedBuildNumber: null,
479 );
480 });
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200481 });
fmatosqg197d4312018-05-21 10:52:33 +1000482
483 group('FlutterManifest with MemoryFileSystem', () {
Alexandre Ardhuin774ca2f2018-09-11 07:14:04 +0200484 Future<void> assertSchemaIsReadable() async {
fmatosqg197d4312018-05-21 10:52:33 +1000485 const String manifest = '''
486name: test
487dependencies:
488 flutter:
489 sdk: flutter
490flutter:
491''';
492
Jonah Williams4ff46712019-04-29 08:21:32 -0700493 final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
fmatosqg197d4312018-05-21 10:52:33 +1000494 expect(flutterManifest.isEmpty, false);
495 }
496
Alexandre Ardhuin5169ab52019-02-21 09:27:07 +0100497 void testUsingContextAndFs(
498 String description,
499 FileSystem filesystem,
500 dynamic testMethod(),
501 ) {
Alexandre Ardhuin440ce8f2019-03-07 21:09:28 +0100502 testUsingContext(
503 description,
504 () async {
505 writeEmptySchemaFile(filesystem);
506 testMethod();
507 },
508 overrides: <Type, Generator>{
509 FileSystem: () => filesystem,
510 },
fmatosqg197d4312018-05-21 10:52:33 +1000511 );
512 }
513
Alexandre Ardhuin774ca2f2018-09-11 07:14:04 +0200514 testUsingContext('Validate manifest on original fs', () {
fmatosqg197d4312018-05-21 10:52:33 +1000515 assertSchemaIsReadable();
516 });
517
Alexandre Ardhuin440ce8f2019-03-07 21:09:28 +0100518 testUsingContextAndFs(
519 'Validate manifest on Posix FS',
520 MemoryFileSystem(style: FileSystemStyle.posix),
521 () {
522 assertSchemaIsReadable();
523 },
fmatosqg197d4312018-05-21 10:52:33 +1000524 );
525
Alexandre Ardhuin440ce8f2019-03-07 21:09:28 +0100526 testUsingContextAndFs(
527 'Validate manifest on Windows FS',
528 MemoryFileSystem(style: FileSystemStyle.windows),
529 () {
530 assertSchemaIsReadable();
531 },
fmatosqg197d4312018-05-21 10:52:33 +1000532 );
533
534 });
535
Sarah Zakarias49ba9742017-09-26 14:48:52 +0200536}
fmatosqg197d4312018-05-21 10:52:33 +1000537