Unverified Commit a74f591d authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

Change asset_bundle_package_font_test to memory file system (#21114)

* Change assert_bundle_package_font_test to memory file system

This is to work towards being able to run the tests without `-j1` (#21113). These tests were using the real filesystem and setting/relying on fs.currentDirectory. There was a comment about this being because the memory provider didnt' support POSIX and Windows, however that seems to have changed since (and many other asset tests already do something similar to this).

* Trim trailing whitespace

* Add a workaround for Windows path slash directions

Strictly this is correct, but the real FS can tolerate either path. The in-memory file system is more strict (see https://github.com/google/file.dart/issues/112).

* Extract a helper for writing schema files in tests

* Missed file when saving!

* Remove redundant comment

* Rename writeBasicSchema -> writeEmptySchema

* Use the file we already have to write contents

* Make comments more descriptive

* Remove another dupe of writeSchema to use the shared one

* Rename schema -> pubspec_schema

* Trim whitespace
parent 041ff621
......@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/flutter_manifest.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
......@@ -19,6 +18,7 @@ import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/pubspec_schema.dart';
void main() {
Cache.flutterRoot = getFlutterRoot();
......@@ -186,8 +186,7 @@ someOtherProperty: someOtherValue
manifestFile.writeAsStringSync(manifest);
// write schemaData otherwise pubspec.yaml file can't be loaded
const String schemaData = '{}';
writeSchemaFile(fs, schemaData);
writeEmptySchemaFile(fs);
try {
updateLocalProperties(
......@@ -331,16 +330,6 @@ flutter:
});
}
void writeSchemaFile(FileSystem filesystem, String schemaData) {
final String schemaPath = buildSchemaPath(filesystem);
final File schemaFile = filesystem.file(schemaPath);
final String schemaDir = buildSchemaDir(filesystem);
filesystem.directory(schemaDir).createSync(recursive: true);
filesystem.file(schemaFile).writeAsStringSync(schemaData);
}
Platform fakePlatform(String name) {
return new FakePlatform.fromPlatform(const LocalPlatform())..operatingSystem = name;
}
......
......@@ -6,15 +6,26 @@ import 'dart:async';
import 'dart:convert';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/pubspec_schema.dart';
void main() {
String fixPath(String path) {
// The in-memory file system is strict about slashes on Windows being the
// correct way so until https://github.com/google/file.dart/issues/112 is
// fixed we fix them here.
// TODO(dantup): Remove this function once the above issue is fixed and
// rolls into Flutter.
return path?.replaceAll('/', fs.path.separator);
}
void writePubspecFile(String path, String name, {String fontsSection}) {
if (fontsSection == null) {
fontsSection = '';
......@@ -26,7 +37,7 @@ $fontsSection
''';
}
fs.file(path)
fs.file(fixPath(path))
..createSync(recursive: true)
..writeAsStringSync('''
name: $name
......@@ -84,30 +95,26 @@ $fontsSection
}
void writeFontAsset(String path, String font) {
fs.file('$path$font')
fs.file(fixPath('$path$font'))
..createSync(recursive: true)
..writeAsStringSync(font);
}
// These tests do not use a memory file system because we want to ensure that
// asset bundles work correctly on Windows and Posix systems.
Directory tempDir;
Directory oldCurrentDir;
setUp(() async {
tempDir = fs.systemTempDirectory.createTempSync('flutter_asset_bundle_test.');
oldCurrentDir = fs.currentDirectory;
fs.currentDirectory = tempDir;
});
group('AssetBundle fonts from packages', () {
FileSystem testFileSystem;
tearDown(() {
fs.currentDirectory = oldCurrentDir;
tryToDelete(tempDir);
});
setUp(() async {
testFileSystem = new MemoryFileSystem(
style: platform.isWindows
? FileSystemStyle.windows
: FileSystemStyle.posix,
);
testFileSystem.currentDirectory = testFileSystem.systemTempDirectory.createTempSync('flutter_asset_bundle_test.');
});
group('AssetBundle fonts from packages', () {
testUsingContext('App includes neither font manifest nor fonts when no defines fonts', () async {
establishFlutterRoot();
writeEmptySchemaFile(fs);
writePubspecFile('pubspec.yaml', 'test');
writePackagesFile('test_package:p/p/lib/');
......@@ -117,10 +124,13 @@ $fontsSection
await bundle.build(manifestPath: 'pubspec.yaml');
expect(bundle.entries.length, 3); // LICENSE, AssetManifest, FontManifest
expect(bundle.entries.containsKey('FontManifest.json'), isTrue);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
testUsingContext('App font uses font file from package', () async {
establishFlutterRoot();
writeEmptySchemaFile(fs);
const String fontsSection = '''
- family: foo
......@@ -142,10 +152,13 @@ $fontsSection
<String>['test_package'],
expectedFontManifest,
);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
testUsingContext('App font uses local font file and package font file', () async {
establishFlutterRoot();
writeEmptySchemaFile(fs);
const String fontsSection = '''
- family: foo
......@@ -171,10 +184,13 @@ $fontsSection
<String>['test_package'],
expectedFontManifest,
);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
testUsingContext('App uses package font with own font file', () async {
establishFlutterRoot();
writeEmptySchemaFile(fs);
writePubspecFile('pubspec.yaml', 'test');
writePackagesFile('test_package:p/p/lib/');
......@@ -201,10 +217,13 @@ $fontsSection
<String>['test_package'],
expectedFontManifest,
);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
testUsingContext('App uses package font with font file from another package', () async {
establishFlutterRoot();
writeEmptySchemaFile(fs);
writePubspecFile('pubspec.yaml', 'test');
writePackagesFile('test_package:p/p/lib/\ntest_package2:p2/p/lib/');
......@@ -232,10 +251,13 @@ $fontsSection
<String>['test_package2'],
expectedFontManifest,
);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
testUsingContext('App uses package font with properties and own font file', () async {
establishFlutterRoot();
writeEmptySchemaFile(fs);
writePubspecFile('pubspec.yaml', 'test');
writePackagesFile('test_package:p/p/lib/');
......@@ -264,10 +286,13 @@ $fontsSection
<String>['test_package'],
expectedFontManifest,
);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
testUsingContext('App uses local font and package font with own font file.', () async {
establishFlutterRoot();
writeEmptySchemaFile(fs);
const String fontsSection = '''
- family: foo
......@@ -300,6 +325,8 @@ $fontsSection
<String>['test_package'],
expectedFontManifest,
);
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
});
});
}
......@@ -16,6 +16,7 @@ import 'package:flutter_tools/src/flutter_manifest.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/pubspec_schema.dart';
void main() {
void writePubspecFile(String path, String name, {List<String> assets}) {
......@@ -539,16 +540,7 @@ $assetsSection
return schemaFile.readAsStringSync();
}
void writeSchema(String schema, FileSystem filesystem) {
final String schemaPath = buildSchemaPath(filesystem);
final File schemaFile = filesystem.file(schemaPath);
final Directory schemaDir = filesystem.directory(
buildSchemaDir(filesystem));
schemaDir.createSync(recursive: true);
schemaFile.writeAsStringSync(schema);
}
void testUsingContextAndFs(String description, dynamic testMethod(),) {
final FileSystem windowsFs = new MemoryFileSystem(
......@@ -564,7 +556,7 @@ $assetsSection
testUsingContext('$description - on windows FS', () async {
establishFlutterRoot();
writeSchema(schema, windowsFs);
writeSchemaFile(windowsFs, schema);
await testMethod();
}, overrides: <Type, Generator>{
FileSystem: () => windowsFs,
......@@ -576,7 +568,7 @@ $assetsSection
testUsingContext('$description - on posix FS', () async {
establishFlutterRoot();
writeSchema(schema, posixFs);
writeSchemaFile(posixFs, schema);
await testMethod();
}, overrides: <Type, Generator>{
FileSystem: () => posixFs,
......
......@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/flutter_manifest.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/pubspec_schema.dart';
void main() {
setUpAll(() {
......@@ -515,23 +516,11 @@ flutter:
expect(flutterManifest.isEmpty, false);
}
void writeSchemaFile(FileSystem filesystem, String schemaData) {
final String schemaPath = buildSchemaPath(filesystem);
final File schemaFile = filesystem.file(schemaPath);
final String schemaDir = buildSchemaDir(filesystem);
filesystem.directory(schemaDir).createSync(recursive: true);
filesystem.file(schemaFile).writeAsStringSync(schemaData);
}
void testUsingContextAndFs(String description, FileSystem filesystem,
dynamic testMethod()) {
const String schemaData = '{}';
testUsingContext(description,
() async {
writeSchemaFile( filesystem, schemaData);
writeEmptySchemaFile(filesystem);
testMethod();
},
overrides: <Type, Generator>{
......
......@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/flutter_manifest.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
......@@ -18,6 +17,7 @@ import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/pubspec_schema.dart';
const String xcodebuild = '/usr/bin/xcodebuild';
......@@ -377,16 +377,6 @@ Information about project "Runner":
return properties.isEmpty ? null : properties.first;
}
void writeSchemaFile(FileSystem filesystem, String schemaData) {
final String schemaPath = buildSchemaPath(filesystem);
final File schemaFile = filesystem.file(schemaPath);
final String schemaDir = buildSchemaDir(filesystem);
filesystem.directory(schemaDir).createSync(recursive: true);
filesystem.file(schemaFile).writeAsStringSync(schemaData);
}
Future<void> checkBuildVersion({
String manifestString,
BuildInfo buildInfo,
......@@ -401,8 +391,7 @@ Information about project "Runner":
manifestFile.writeAsStringSync(manifestString);
// write schemaData otherwise pubspec.yaml file can't be loaded
const String schemaData = '{}';
writeSchemaFile(fs, schemaData);
writeEmptySchemaFile(fs);
await updateGeneratedXcodeProperties(
project: await FlutterProject.fromPath('path/to/project'),
......
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/flutter_manifest.dart';
/// Writes a schemaData used for validating pubspec.yaml files when parsing
/// asset information.
void writeSchemaFile(FileSystem filesystem, String schemaData) {
final String schemaPath = buildSchemaPath(filesystem);
final File schemaFile = filesystem.file(schemaPath);
final String schemaDir = buildSchemaDir(filesystem);
filesystem.directory(schemaDir).createSync(recursive: true);
schemaFile.writeAsStringSync(schemaData);
}
/// Writes an empty schemaData that will validate any pubspec.yaml file.
void writeEmptySchemaFile(FileSystem filesystem) {
writeSchemaFile(filesystem, '{}');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment