Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Fix tests #581

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/command/bin/flutter_gen_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ void main(List<String> args) {
}

final pubspecPath = safeCast<String>(results['config']);
final pubspecFile = File(pubspecPath!).absolute;
if (pubspecPath == null || pubspecPath.trim().isEmpty) {
throw ArgumentError('Invalid value $pubspecPath', 'config');
}
final pubspecFile = File(pubspecPath).absolute;

final buildPath = safeCast<String>(results['build']);
final buildFile = File(buildPath!).absolute;
if (buildPath == null || buildPath.trim().isEmpty) {
throw ArgumentError('Invalid value $buildPath', 'build');
}
final buildFile = File(buildPath).absolute;

FlutterGenerator(pubspecFile, buildFile: buildFile).build();
}
11 changes: 6 additions & 5 deletions packages/core/lib/settings/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:path/path.dart';
import 'package:yaml/yaml.dart';

class Config {
Config._({required this.pubspec, required this.pubspecFile});
const Config._({required this.pubspec, required this.pubspecFile});

final Pubspec pubspec;
final File pubspecFile;
Expand All @@ -19,9 +19,6 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) {
final pubspecLocaleHint = normalize(
join(basename(pubspecFile.parent.path), basename(pubspecFile.path)),
);
final buildLocaleHint = buildFile != null && buildFile.existsSync()
? join(basename(buildFile.parent.path), basename(buildFile.path))
: '';

stdout.writeln(
'$flutterGenVersion Loading ...',
Expand All @@ -40,11 +37,15 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) {
if (buildFile != null && buildFile.existsSync()) {
final buildContent = buildFile.readAsStringSync();
final rawMap = loadYaml(buildContent) as Map?;
final optionBuildMap = rawMap?['targets']?[r'$default']?['builders']?['flutter_gen']?['options'];
final optionBuildMap = rawMap?['targets']?[r'$default']?['builders']
?['flutter_gen']?['options'];

if (optionBuildMap != null) {
final buildMap = {'flutter_gen': optionBuildMap};
mergedMap = mergeMap([mergedMap, buildMap]);
final buildLocaleHint = normalize(
join(basename(buildFile.parent.path), basename(buildFile.path)),
);
stdout.writeln(
'Reading FlutterGen options from $buildLocaleHint',
);
Expand Down
19 changes: 11 additions & 8 deletions packages/core/test/assets_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,17 @@ void main() {
expect(names.sorted(), tests.values.sorted());
});

test('Assets on pubspec_assets.yaml and override with build_assets.yaml ', () async {
const pubspec = 'test_resources/pubspec_assets.yaml';
const build = 'test_resources/build_assets.yaml';
const fact = 'test_resources/actual_data/build_assets.gen.dart';
const generated = 'test_resources/lib/build_gen/assets.gen.dart';

await expectedAssetsGen(pubspec, generated, fact, build: build);
});
test(
'Assets on pubspec_assets.yaml and override with build_assets.yaml ',
() async {
const pubspec = 'test_resources/pubspec_assets.yaml';
const build = 'test_resources/build_assets.yaml';
const fact = 'test_resources/actual_data/build_assets.gen.dart';
const generated = 'test_resources/lib/build_gen/assets.gen.dart';

await expectedAssetsGen(pubspec, generated, fact, build: build);
},
);
});

group('Test generatePackageNameForConfig', () {
Expand Down
Loading
Loading