Skip to content

Commit c4ed388

Browse files
authored
✅ Fix tests (#581)
1 parent aadf5f9 commit c4ed388

File tree

4 files changed

+87
-151
lines changed

4 files changed

+87
-151
lines changed

packages/command/bin/flutter_gen_command.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ void main(List<String> args) {
5252
}
5353

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

5760
final buildPath = safeCast<String>(results['build']);
58-
final buildFile = File(buildPath!).absolute;
61+
if (buildPath == null || buildPath.trim().isEmpty) {
62+
throw ArgumentError('Invalid value $buildPath', 'build');
63+
}
64+
final buildFile = File(buildPath).absolute;
5965

6066
FlutterGenerator(pubspecFile, buildFile: buildFile).build();
6167
}

packages/core/lib/settings/config.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:path/path.dart';
99
import 'package:yaml/yaml.dart';
1010

1111
class Config {
12-
Config._({required this.pubspec, required this.pubspecFile});
12+
const Config._({required this.pubspec, required this.pubspecFile});
1313

1414
final Pubspec pubspec;
1515
final File pubspecFile;
@@ -19,9 +19,6 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) {
1919
final pubspecLocaleHint = normalize(
2020
join(basename(pubspecFile.parent.path), basename(pubspecFile.path)),
2121
);
22-
final buildLocaleHint = buildFile != null && buildFile.existsSync()
23-
? join(basename(buildFile.parent.path), basename(buildFile.path))
24-
: '';
2522

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

4543
if (optionBuildMap != null) {
4644
final buildMap = {'flutter_gen': optionBuildMap};
4745
mergedMap = mergeMap([mergedMap, buildMap]);
46+
final buildLocaleHint = normalize(
47+
join(basename(buildFile.parent.path), basename(buildFile.path)),
48+
);
4849
stdout.writeln(
4950
'Reading FlutterGen options from $buildLocaleHint',
5051
);

packages/core/test/assets_gen_test.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,17 @@ void main() {
214214
expect(names.sorted(), tests.values.sorted());
215215
});
216216

217-
test('Assets on pubspec_assets.yaml and override with build_assets.yaml ', () async {
218-
const pubspec = 'test_resources/pubspec_assets.yaml';
219-
const build = 'test_resources/build_assets.yaml';
220-
const fact = 'test_resources/actual_data/build_assets.gen.dart';
221-
const generated = 'test_resources/lib/build_gen/assets.gen.dart';
222-
223-
await expectedAssetsGen(pubspec, generated, fact, build: build);
224-
});
217+
test(
218+
'Assets on pubspec_assets.yaml and override with build_assets.yaml ',
219+
() async {
220+
const pubspec = 'test_resources/pubspec_assets.yaml';
221+
const build = 'test_resources/build_assets.yaml';
222+
const fact = 'test_resources/actual_data/build_assets.gen.dart';
223+
const generated = 'test_resources/lib/build_gen/assets.gen.dart';
224+
225+
await expectedAssetsGen(pubspec, generated, fact, build: build);
226+
},
227+
);
225228
});
226229

227230
group('Test generatePackageNameForConfig', () {

0 commit comments

Comments
 (0)