import 'dart:async';
import 'dart:ffi';
import 'dart:io';

import 'package:sqlite3/open.dart';

/// Host test setup: point package:sqlite3 at the system SQLite so in-memory
/// Drift databases (migration/widget tests) load on Linux CI/dev machines,
/// where only `libsqlite3.so.0` may be present. The encrypted executor
/// overrides its own isolate to SQLCipher separately, so this does not affect
/// the on-disk encryption tests.
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
  if (Platform.isLinux) {
    open.overrideFor(OperatingSystem.linux, () {
      try {
        return DynamicLibrary.open('libsqlite3.so');
      } on ArgumentError {
        return DynamicLibrary.open('libsqlite3.so.0');
      }
    });
  }
  await testMain();
}
