Fix tests to prepare for --explicit-package-dependencies and a bug. (#162289)

@camsim99 discovered these would fail here:
https://github.com/flutter/flutter/pull/161826#issuecomment-2617059566.

This fixes in preparation for the flag flipping, and also fixes a bug in
resolving `synthetic-package` I missed (it _can't_ be true if
`--explicit-package-dependencies` is set).
This commit is contained in:
Matan Lurey 2025-01-28 18:04:50 -08:00 committed by GitHub
parent f5bf8f7707
commit 8b9b6a39af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 41 deletions

View File

@ -151,7 +151,7 @@ class GenerateLocalizationsCommand extends FlutterCommand {
);
argParser.addFlag(
'synthetic-package',
defaultsTo: true,
defaultsTo: !featureFlags.isExplicitPackageDependenciesEnabled,
help:
'Determines whether or not the generated output files will be '
'generated as a synthetic package or at a specified directory in '
@ -159,12 +159,8 @@ class GenerateLocalizationsCommand extends FlutterCommand {
'\n'
'DEPRECATED: https://flutter.dev/to/flutter-gen-deprecation.\n'
'\n'
'This flag is set to true by default.\n'
'\n'
'When synthetic-package is set to false, it will generate the '
'localizations files in the directory specified by arb-dir by default.\n'
'\n'
'If output-dir is specified, files will be generated there.',
'localizations files in the directory specified by arb-dir by default.\n',
);
argParser.addOption(
'project-dir',

View File

@ -353,7 +353,7 @@ class LocalizationOptions {
outputLocalizationFile = outputLocalizationFile ?? 'app_localizations.dart',
outputClass = outputClass ?? 'AppLocalizations',
useDeferredLoading = useDeferredLoading ?? false,
syntheticPackage = syntheticPackage ?? true,
syntheticPackage = syntheticPackage ?? !featureFlags.isExplicitPackageDependenciesEnabled,
requiredResourceAttributes = requiredResourceAttributes ?? false,
nullableGetter = nullableGetter ?? true,
format = format ?? false,

View File

@ -65,14 +65,13 @@ void main() {
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);
final Directory outputDirectory = fileSystem.directory(
fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'),
);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', '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>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
@ -211,14 +210,13 @@ flutter:
logger.statusText,
contains('Because l10n.yaml exists, the options defined there will be used instead.'),
);
final Directory outputDirectory = fileSystem.directory(
fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'),
);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', '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>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
@ -273,8 +271,8 @@ flutter:
command: <String>[
'Artifact.engineDartBinary',
'format',
'/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart',
'/.dart_tool/flutter_gen/gen_l10n/app_localizations.dart',
'/lib/l10n/app_localizations_en.dart',
'/lib/l10n/app_localizations.dart',
],
),
);
@ -288,15 +286,14 @@ flutter:
await createTestCommandRunner(command).run(<String>['gen-l10n', '--format']);
final Directory outputDirectory = fileSystem.directory(
fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'),
);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
expect(outputDirectory.existsSync(), true);
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
expect(processManager, hasNoRemainingExpectations);
},
overrides: <Type, Generator>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
@ -325,8 +322,8 @@ format: true
command: <String>[
'Artifact.engineDartBinary',
'format',
'/.dart_tool/flutter_gen/gen_l10n/app_localizations_en.dart',
'/.dart_tool/flutter_gen/gen_l10n/app_localizations.dart',
'/lib/l10n/app_localizations_en.dart',
'/lib/l10n/app_localizations.dart',
],
),
);
@ -338,15 +335,14 @@ format: true
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);
final Directory outputDirectory = fileSystem.directory(
fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'),
);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
expect(outputDirectory.existsSync(), true);
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
expect(processManager, hasNoRemainingExpectations);
},
overrides: <Type, Generator>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
@ -381,9 +377,9 @@ untranslated-messages-file: lib/l10n/untranslated.json
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',
'/lib/l10n/app_localizations_en.dart',
'/lib/l10n/app_localizations_es.dart',
'/lib/l10n/app_localizations.dart',
],
),
);
@ -395,9 +391,7 @@ untranslated-messages-file: lib/l10n/untranslated.json
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);
final Directory outputDirectory = fileSystem.directory(
fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'),
);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
expect(outputDirectory.existsSync(), true);
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
expect(outputDirectory.childFile('app_localizations_es.dart').existsSync(), true);
@ -409,6 +403,7 @@ untranslated-messages-file: lib/l10n/untranslated.json
expect(processManager, hasNoRemainingExpectations);
},
overrides: <Type, Generator>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
@ -484,9 +479,7 @@ format: true
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);
final Directory outputDirectory = fileSystem.directory(
fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'),
);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
expect(outputDirectory.existsSync(), isTrue);
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), isTrue);
expect(
@ -495,6 +488,7 @@ format: true
);
},
overrides: <Type, Generator>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
@ -630,14 +624,13 @@ format: true
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);
final Directory outputDirectory = fileSystem.directory(
fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'),
);
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', '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>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},

View File

@ -13,7 +13,7 @@ import 'package:flutter_tools/src/localizations/localizations_utils.dart';
import 'package:yaml/yaml.dart';
import '../src/common.dart';
import '../src/fake_process_manager.dart';
import '../src/context.dart';
const String defaultTemplateArbFileName = 'app_en.arb';
const String defaultOutputFileString = 'output-localization-file.dart';
@ -834,7 +834,7 @@ class FooEn extends Foo {
''');
});
testWithoutContext('throws exception on missing flutter: generate: true flag', () async {
testUsingContext('throws exception on missing flutter: generate: true flag', () async {
_standardFlutterDirectoryL10nSetup(fs);
// Missing flutter: generate: true should throw exception.
@ -875,7 +875,7 @@ flutter:
);
});
testWithoutContext('uses the same line terminator as pubspec.yaml', () async {
testUsingContext('uses the same line terminator as pubspec.yaml', () async {
_standardFlutterDirectoryL10nSetup(fs);
fs.file('pubspec.yaml')

View File

@ -1315,9 +1315,8 @@ flutter:
''');
expect(await residentWebRunner.run(), 0);
final File generatedLocalizationsFile = globals.fs
.directory('.dart_tool')
.childDirectory('flutter_gen')
.childDirectory('gen_l10n')
.directory('lib')
.childDirectory('l10n')
.childFile('app_localizations.dart');
expect(generatedLocalizationsFile.existsSync(), isTrue);
// Completing this future ensures that the daemon can exit correctly.