🔥 Do not format the messages file for gen-l10n (#119596)

* 🔥 Do not format the messages file

* ✅ Add test

* ✅ Add the link to the test

* ✅ Respect the path separator from the file system

* ✅ Add the untranslated messages file existence test
This commit is contained in:
Alex Li
2023-02-02 07:45:38 +08:00
committed by GitHub
parent cd118dada9
commit 4ae2d3b6df
3 changed files with 76 additions and 11 deletions

View File

@@ -265,4 +265,58 @@ format: true
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
// Regression test for https://github.com/flutter/flutter/issues/119594
testUsingContext('dart format is working when the untranslated messages file is produced', () async {
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
..createSync(recursive: true);
arbFile.writeAsStringSync('''
{
"helloWorld": "Hello, World!",
"untranslated": "Test untranslated message."
}''');
fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_es.arb'))
..createSync(recursive: true)
..writeAsStringSync('''
{
"helloWorld": "Hello, World!"
}''');
final File configFile = fileSystem.file('l10n.yaml')..createSync();
configFile.writeAsStringSync('''
format: true
untranslated-messages-file: lib/l10n/untranslated.json
''');
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec);
processManager.addCommand(
const FakeCommand(
command: <String>[
'Artifact.engineDartBinary',
'format',
'/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart',
'/.dart_tool/flutter_gen/gen_l10n/app_localizations_es.dart',
'/.dart_tool/flutter_gen/gen_l10n/app_localizations.dart',
]
)
);
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
fileSystem: fileSystem,
logger: logger,
artifacts: artifacts,
processManager: processManager,
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);
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_es.dart').existsSync(), true);
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
final File untranslatedMessagesFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'untranslated.json'));
expect(untranslatedMessagesFile.existsSync(), true);
expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
}