Unverified Commit f3d182f4 authored by Dillon Nys's avatar Dillon Nys Committed by GitHub

[flutter_tools] Fix tool crash for map cast (#107648)

parent 9e2ef76b
...@@ -61,9 +61,9 @@ class GenerateLocalizationsTarget extends Target { ...@@ -61,9 +61,9 @@ class GenerateLocalizationsTarget extends Target {
fileSystem: environment.fileSystem, fileSystem: environment.fileSystem,
); );
final Map<String, Object> dependencies = json.decode( final Map<String, Object?> dependencies = json.decode(
environment.buildDir.childFile(_kDependenciesFileName).readAsStringSync() environment.buildDir.childFile(_kDependenciesFileName).readAsStringSync()
) as Map<String, Object>; ) as Map<String, Object?>;
final List<Object?>? inputs = dependencies['inputs'] as List<Object?>?; final List<Object?>? inputs = dependencies['inputs'] as List<Object?>?;
final List<Object?>? outputs = dependencies['outputs'] as List<Object?>?; final List<Object?>? outputs = dependencies['outputs'] as List<Object?>?;
final Depfile depfile = Depfile( final Depfile depfile = Depfile(
......
...@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/commands/packages.dart'; ...@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/commands/packages.dart';
import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:test/fake.dart'; import 'package:test/fake.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -112,6 +113,52 @@ void main() { ...@@ -112,6 +113,52 @@ void main() {
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
}); });
testUsingContext('pub get triggers localizations generation when generate: true', () async {
final File pubspecFile = fileSystem.currentDirectory.childFile('pubspec.yaml')
..createSync();
pubspecFile.writeAsStringSync(
'''
flutter:
generate: true
'''
);
fileSystem.currentDirectory.childFile('l10n.yaml')
..createSync()
..writeAsStringSync(
'''
arb-dir: lib/l10n
'''
);
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
..createSync(recursive: true);
arbFile.writeAsStringSync(
'''
{
"helloWorld": "Hello, World!",
"@helloWorld": {
"description": "Sample description"
}
}
'''
);
final PackagesGetCommand command = PackagesGetCommand('get', false);
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
await commandRunner.run(<String>['get']);
final FlutterCommandResult result = await command.runCommand();
expect(result.exitStatus, ExitStatus.success);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'));
expect(outputDirectory.existsSync(), true);
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
}, overrides: <Type, Generator>{
Pub: () => pub,
ProcessManager: () => FakeProcessManager.any(),
FileSystem: () => fileSystem,
});
} }
class FakePub extends Fake implements Pub { class FakePub extends Fake implements Pub {
......
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