Unverified Commit 99e7b0a0 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

dont NPE with empty pubspec (#32072)

parent 526113db
......@@ -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'];
}
......
......@@ -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 {
......
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