Skip to content

Commit e51c815

Browse files
authored
[native_assets_cli] Fix invalid OS error and test (#2067)
1 parent e863409 commit e51c815

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pkgs/native_assets_cli/lib/src/code_assets/config.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ class CodeConfig {
8383
validValues: Architecture.values.map((a) => a.name),
8484
),
8585
);
86-
final targetOS = OS.fromString(json.code!.string(_targetOSConfigKey));
86+
final targetOS = OS.fromString(
87+
json.code!.string(
88+
_targetOSConfigKey,
89+
validValues: OS.values.map((a) => a.name),
90+
),
91+
);
8792
final cCompiler = switch (json.code?.optionalMap(_compilerKey)) {
8893
final Map<String, Object?> map => CCompilerConfig.fromJson(map),
8994
null => null,

pkgs/native_assets_cli/test/code_assets/config_test.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,20 @@ void main() async {
238238
'package_root': packageRootUri.toFilePath(),
239239
'version': latestVersion.toString(),
240240
};
241-
expect(() => BuildInput(input).config.code, throwsFormatException);
241+
expect(
242+
() => BuildInput(input).config.code.targetArchitecture,
243+
throwsFormatException,
244+
);
242245
});
243246

244-
test('LinkInput.config.code: invalid architecture', () {
247+
test('LinkInput.config.code: invalid os', () {
245248
final input = {
246249
'config': {
247250
'code': {
248251
'link_mode_preference': 'prefer-static',
249252
'android': {'target_ndk_api': 30},
250-
'target_architecture': 'invalid_architecture',
251-
'target_os': 'android',
253+
'target_architecture': 'x64',
254+
'target_os': 'invalid_os',
252255
},
253256
},
254257
'out_dir': outDirUri.toFilePath(),
@@ -258,6 +261,6 @@ void main() async {
258261
'package_root': packageRootUri.toFilePath(),
259262
'version': latestVersion.toString(),
260263
};
261-
expect(() => LinkInput(input).config.code, throwsFormatException);
264+
expect(() => LinkInput(input).config.code.targetOS, throwsFormatException);
262265
});
263266
}

0 commit comments

Comments
 (0)