dont NPE with empty pubspec (#32072)

This commit is contained in:
Jonah Williams 2019-05-06 08:01:45 -07:00 committed by GitHub
parent 526113db32
commit 99e7b0a0ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -181,6 +181,10 @@ class FlutterProject {
return null;
}
final YamlMap pubspec = loadYaml(pubspecFile.readAsStringSync());
// If the pubspec file is empty, this will be null.
if (pubspec == null) {
return null;
}
return pubspec['builders'];
}

View file

@ -20,6 +20,7 @@ import 'package:mockito/mockito.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/testbed.dart';
void main() {
group('Project', () {
@ -342,6 +343,37 @@ void main() {
});
});
});
group('Regression test for invalid pubspec', () {
Testbed testbed;
setUp(() {
testbed = Testbed();
});
test('Handles asking for builders from an invalid pubspec', () => testbed.run(() {
fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
# Hello, World
''');
final FlutterProject flutterProject = FlutterProject.current();
expect(flutterProject.builders, null);
}));
test('Handles asking for builders from a trivial pubspec', () => testbed.run(() {
fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
# Hello, World
name: foo_bar
''');
final FlutterProject flutterProject = FlutterProject.current();
expect(flutterProject.builders, null);
}));
});
}
Future<FlutterProject> someProject() async {