mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
dont NPE with empty pubspec (#32072)
This commit is contained in:
parent
526113db32
commit
99e7b0a0ff
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue