Use platform specific line separator in gen-l10n (#130090)

Currently files are not generated with `\r\n` in windows. This PR should
fix the issue.

Fixes https://github.com/flutter/flutter/issues/109761.
This commit is contained in:
Tae Hyung Kim
2023-07-12 12:50:53 -07:00
committed by GitHub
parent 42924e275b
commit d75735eea6
3 changed files with 64 additions and 15 deletions

View File

@@ -78,6 +78,11 @@ void main() {
"description": "Sample description"
}
}''');
fileSystem
.file('pubspec.yaml')
.writeAsStringSync('''
flutter:
generate: true''');
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
fileSystem: fileSystem,
@@ -109,7 +114,11 @@ void main() {
}
}''');
fileSystem.file('header.txt').writeAsStringSync('a header file');
fileSystem
.file('pubspec.yaml')
.writeAsStringSync('''
flutter:
generate: true''');
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
fileSystem: fileSystem,
logger: logger,
@@ -442,7 +451,7 @@ format: true
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('throw when generate: false and uses synthetic package when run via commandline options', () async {
testUsingContext('throw when generate: false and uses synthetic package when run via commandline options', () async {
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
..createSync(recursive: true);
arbFile.writeAsStringSync('''
@@ -475,7 +484,6 @@ format: true
() async => createTestCommandRunner(command).run(<String>['gen-l10n', '--synthetic-package']),
throwsToolExit(message: 'Attempted to generate localizations code without having the flutter: generate flag turned on.')
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),

View File

@@ -59,6 +59,13 @@ void _standardFlutterDirectoryL10nSetup(FileSystem fs) {
.writeAsStringSync(singleMessageArbFileString);
l10nDirectory.childFile(esArbFileName)
.writeAsStringSync(singleEsMessageArbFileString);
fs.file('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync('''
flutter:
generate: true
''');
}
void main() {
@@ -763,7 +770,7 @@ class FooEn extends Foo {
_standardFlutterDirectoryL10nSetup(fs);
// Missing flutter: generate: true should throw exception.
fs.file(fs.path.join(syntheticPackagePath, 'pubspec.yaml'))
fs.file('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync('''
flutter:
@@ -799,6 +806,34 @@ flutter:
);
});
testWithoutContext('uses the same line terminator as pubspec.yaml', () async {
_standardFlutterDirectoryL10nSetup(fs);
fs.file('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync('''
flutter:\r
generate: true\r
''');
final LocalizationOptions options = LocalizationOptions(
arbDir: fs.path.join('lib', 'l10n'),
outputClass: defaultClassNameString,
outputLocalizationFile: defaultOutputFileString,
);
await generateLocalizations(
fileSystem: fs,
options: options,
logger: BufferLogger.test(),
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
);
final String content = getGeneratedFileContent(locale: 'en');
expect(content, contains('\r\n'));
});
testWithoutContext('blank lines generated nicely', () async {
_standardFlutterDirectoryL10nSetup(fs);