dont NPE with empty pubspec (#32072)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user