Skip to content

Commit

Permalink
[gen_l10n] Throw error when arb file does not exist (#107583)
Browse files Browse the repository at this point in the history
  • Loading branch information
thkim1011 committed Jul 15, 2022
1 parent c4975d9 commit 2da2285
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/flutter_tools/lib/src/localizations/gen_l10n.dart
Expand Up @@ -942,7 +942,13 @@ class LocalizationsGenerator {
@visibleForTesting
static File templateArbFileFromFileName(String templateArbFileName, Directory inputDirectory) {
final File templateArbFile = inputDirectory.childFile(templateArbFileName);
final String templateArbFileStatModeString = templateArbFile.statSync().modeString();
final FileStat templateArbFileStat = templateArbFile.statSync();
if (templateArbFileStat.type == FileSystemEntityType.notFound) {
throw L10nException(
"The 'template-arb-file', $templateArbFile, does not exist."
);
}
final String templateArbFileStatModeString = templateArbFileStat.modeString();
if (templateArbFileStatModeString[0] == '-' && templateArbFileStatModeString[3] == '-') {
throw L10nException(
"The 'template-arb-file', $templateArbFile, is not readable.\n"
Expand Down
Expand Up @@ -180,6 +180,32 @@ void main() {
);
});

testWithoutContext('throws error when arb file does not exist', () {
// Set up project directory.
fs.currentDirectory
.childDirectory('lib')
.childDirectory('l10n')
.createSync(recursive: true);

// Arb file should be nonexistent in the l10n directory.
expect(
() => LocalizationsGenerator(
fileSystem: fs,
projectPathString: './',
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
),
throwsA(isA<L10nException>().having(
(L10nException e) => e.message,
'message',
contains(', does not exist.'),
)),
);
});

group('className should only take valid Dart class names', () {
setUp(() {
_standardFlutterDirectoryL10nSetup(fs);
Expand Down

0 comments on commit 2da2285

Please sign in to comment.