testCodeBuildHook function

Future<void> testCodeBuildHook({
  1. required FutureOr<void> mainMethod(
    1. List<String> arguments
    ),
  2. required FutureOr<void> check(
    1. BuildInput,
    2. BuildOutput
    ),
  3. bool? linkingEnabled,
  4. Architecture? targetArchitecture,
  5. OS? targetOS,
  6. IOSSdk? targetIOSSdk = IOSSdk.iPhoneOS,
  7. int? targetIOSVersion = 17,
  8. int? targetMacOSVersion = 13,
  9. int? targetAndroidNdkApi = 30,
  10. CCompilerConfig? cCompiler,
  11. LinkModePreference? linkModePreference = LinkModePreference.dynamic,
  12. PackageUserDefines? userDefines,
  13. Map<String, List<EncodedAsset>>? assets,
})

Tests the main function of a hook/build.dart with CodeAssets.

This method will throw an exception on validation errors.

This is intended to be used from tests, e.g.:

test('test my build hook', () async {
  await testCodeBuildHook(
    ...
  );
});

The hook is run in isolation. No user-defines are read from the pubspec, they must be provided via userDefines. No other hooks are run, if the hook requires assets from other build hooks, the must be provided in assets.

Implementation

Future<void> testCodeBuildHook({
  required FutureOr<void> Function(List<String> arguments) mainMethod,
  required FutureOr<void> Function(BuildInput, BuildOutput) check,
  bool? linkingEnabled,
  Architecture? targetArchitecture,
  OS? targetOS,
  IOSSdk? targetIOSSdk = IOSSdk.iPhoneOS,
  int? targetIOSVersion = 17,
  int? targetMacOSVersion = 13,
  int? targetAndroidNdkApi = 30,
  CCompilerConfig? cCompiler,
  LinkModePreference? linkModePreference = LinkModePreference.dynamic,
  // TODO(https://github.com/dart-lang/native/issues/2241): Cleanup how the
  // following parameters are passed in.
  PackageUserDefines? userDefines,
  Map<String, List<EncodedAsset>>? assets,
}) async {
  targetOS ??= OS.current;
  final extension = CodeAssetExtension(
    linkModePreference: linkModePreference!,
    cCompiler: cCompiler,
    targetArchitecture: targetArchitecture ?? Architecture.current,
    targetOS: targetOS,
    iOS: targetOS == OS.iOS
        ? IOSCodeConfig(
            targetSdk: targetIOSSdk!,
            targetVersion: targetIOSVersion!,
          )
        : null,
    macOS: targetOS == OS.macOS
        ? MacOSCodeConfig(targetVersion: targetMacOSVersion!)
        : null,
    android: targetOS == OS.android
        ? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!)
        : null,
  );
  await testBuildHook(
    mainMethod: mainMethod,
    check: check,
    linkingEnabled: linkingEnabled,
    userDefines: userDefines,
    assets: assets,
    extensions: [extension],
  );
}