Unverified Commit 8d3bc184 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate analyze_size to null safety (#81002)

parent b8833afc
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:archive/archive.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/analyze_size.dart';
......@@ -43,15 +41,15 @@ const String aotSizeOutput = '''
''';
void main() {
MemoryFileSystem fileSystem;
BufferLogger logger;
late MemoryFileSystem fileSystem;
late BufferLogger logger;
setUp(() {
fileSystem = MemoryFileSystem.test();
logger = BufferLogger.test();
});
test('matchesPattern matches only entire strings', () {
testWithoutContext('matchesPattern matches only entire strings', () {
expect(matchesPattern('', pattern: ''), isNotNull);
expect(matchesPattern('', pattern: 'foo'), null);
expect(matchesPattern('foo', pattern: ''), null);
......@@ -62,7 +60,7 @@ void main() {
expect(matchesPattern('foobar', pattern: RegExp(r'.*b')), null);
});
test('builds APK analysis correctly', () async {
testWithoutContext('builds APK analysis correctly', () async {
final SizeAnalyzer sizeAnalyzer = SizeAnalyzer(
fileSystem: fileSystem,
logger: logger,
......@@ -78,7 +76,7 @@ void main() {
..addFile(ArchiveFile('lib/arm64-v8a/libflutter.so', 50, List<int>.filled(50, 0)));
final File apk = fileSystem.file('test.apk')
..writeAsBytesSync(ZipEncoder().encode(archive));
..writeAsBytesSync(ZipEncoder().encode(archive)!);
final File aotSizeJson = fileSystem.file('test.json')
..createSync()
..writeAsStringSync(aotSizeOutput);
......@@ -139,7 +137,7 @@ void main() {
expect(result['precompiler-trace'], <String, Object>{});
});
test('outputs summary to command line correctly', () async {
testWithoutContext('outputs summary to command line correctly', () async {
final SizeAnalyzer sizeAnalyzer = SizeAnalyzer(
fileSystem: fileSystem,
logger: logger,
......@@ -155,7 +153,7 @@ void main() {
..addFile(ArchiveFile('lib/arm64-v8a/libflutter.so', 50, List<int>.filled(50, 0)));
final File apk = fileSystem.file('test.apk')
..writeAsBytesSync(ZipEncoder().encode(archive));
..writeAsBytesSync(ZipEncoder().encode(archive)!);
final File aotSizeJson = fileSystem.file('test.json')
..writeAsStringSync(aotSizeOutput);
final File precompilerTrace = fileSystem.file('trace.json')
......@@ -181,7 +179,7 @@ void main() {
);
});
test('can analyze contents of output directory', () async {
testWithoutContext('can analyze contents of output directory', () async {
final SizeAnalyzer sizeAnalyzer = SizeAnalyzer(
fileSystem: fileSystem,
logger: logger,
......@@ -202,7 +200,7 @@ void main() {
final File precompilerTrace = fileSystem.file('trace.json')
..writeAsStringSync('{}');
final Map<String, Object> result = await sizeAnalyzer.analyzeAotSnapshot(
final Map<String, Object?> result = await sizeAnalyzer.analyzeAotSnapshot(
outputDirectory: outputDirectory,
aotSnapshot: aotSizeJson,
precompilerTrace: precompilerTrace,
......@@ -223,4 +221,36 @@ void main() {
expect(result['type'], 'linux');
expect(result['precompiler-trace'], <String, Object>{});
});
testWithoutContext('handles null AOT snapshot json', () async {
final SizeAnalyzer sizeAnalyzer = SizeAnalyzer(
fileSystem: fileSystem,
logger: logger,
appFilenamePattern: RegExp(r'lib.*app\.so'),
flutterUsage: TestUsage(),
);
final Directory outputDirectory = fileSystem.directory('example/out/foo.app')..createSync(recursive: true);
final File invalidAotSizeJson = fileSystem.file('test.json')..writeAsStringSync('null');
final File precompilerTrace = fileSystem.file('trace.json');
await expectLater(
() => sizeAnalyzer.analyzeAotSnapshot(
outputDirectory: outputDirectory,
aotSnapshot: invalidAotSizeJson,
precompilerTrace: precompilerTrace,
type: 'linux',
),
throwsToolExit());
final File apk = fileSystem.file('test.apk')..writeAsBytesSync(ZipEncoder().encode(Archive())!);
await expectLater(
() => sizeAnalyzer.analyzeZipSizeAndAotSnapshot(
zipFile: apk,
aotSnapshot: invalidAotSizeJson,
precompilerTrace: precompilerTrace,
kind: 'apk',
),
throwsToolExit());
});
}
......@@ -9,6 +9,7 @@ import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/io.dart';
import '../src/common.dart';
import '../src/context.dart';
import 'test_utils.dart';
const String apkDebugMessage = 'A summary of your APK analysis can be found at: ';
......@@ -16,7 +17,7 @@ const String iosDebugMessage = 'A summary of your iOS bundle analysis can be fou
const String runDevToolsMessage = 'flutter pub global activate devtools; flutter pub global run devtools ';
void main() {
testWithoutContext('--analyze-size flag produces expected output on hello_world for Android', () async {
testUsingContext('--analyze-size flag produces expected output on hello_world for Android', () async {
final String workingDirectory = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world');
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await processManager.run(<String>[
......
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