From 0f5cd7855d905d615dd64d26cafac3c5027a4051 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Wed, 10 Jan 2024 10:50:07 -0800 Subject: [PATCH] [flutter_tools] fix flutter create -t skeleton (#141233) Fixes https://github.com/flutter/flutter/issues/139138 This had been broken since https://github.com/flutter/flutter/pull/130090 merged, however, the test happened run with flutter_tools/pubspec.yaml in the current working directory. --- .../lib/src/localizations/gen_l10n.dart | 2 +- .../generate_localizations_test.dart | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart index 1cc931a789..4cb6e2b003 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart @@ -48,7 +48,7 @@ Future generateLocalizations({ precacheLanguageAndRegionTags(); // Use \r\n if project's pubspec file contains \r\n. - final bool useCRLF = fileSystem.file('pubspec.yaml').readAsStringSync().contains('\r\n'); + final bool useCRLF = projectDir.childFile('pubspec.yaml').readAsStringSync().contains('\r\n'); LocalizationsGenerator generator; try { diff --git a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart index 74e9964c6e..ea06e8b132 100644 --- a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart @@ -687,7 +687,41 @@ void main() { }); group('generateLocalizations', () { - // Regression test for https://github.com/flutter/flutter/issues/119593 + testWithoutContext('works even if CWD does not have a pubspec.yaml', () async { + final Directory projectDir = fs.currentDirectory.childDirectory('project')..createSync(recursive: true); + final Directory l10nDirectory = projectDir.childDirectory('lib').childDirectory('l10n') + ..createSync(recursive: true); + l10nDirectory.childFile(defaultTemplateArbFileName) + .writeAsStringSync(singleMessageArbFileString); + l10nDirectory.childFile(esArbFileName) + .writeAsStringSync(singleEsMessageArbFileString); + projectDir.childFile('pubspec.yaml') + ..createSync(recursive: true) + ..writeAsStringSync(''' +flutter: + generate: true +'''); + + final Logger logger = BufferLogger.test(); + logger.printError('An error output from a different tool in flutter_tools'); + + // Should run without error. + await generateLocalizations( + fileSystem: fs, + options: LocalizationOptions( + arbDir: Uri.directory(defaultL10nPathString).path, + outputDir: Uri.directory(defaultL10nPathString, windows: false).path, + templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false).path, + syntheticPackage: false, + ), + logger: logger, + projectDir: projectDir, + dependenciesDir: fs.currentDirectory, + artifacts: artifacts, + processManager: processManager, + ); + }); + testWithoutContext('other logs from flutter_tools does not affect gen-l10n', () async { _standardFlutterDirectoryL10nSetup(fs);