[ffigen] Generate a nice error if files generated by test/setup.dart are not present
diff --git a/pkgs/ffigen/test/native_objc_test/native_objc_test.dart b/pkgs/ffigen/test/native_objc_test/native_objc_test.dart index a4f2a57..8b23c2d 100644 --- a/pkgs/ffigen/test/native_objc_test/native_objc_test.dart +++ b/pkgs/ffigen/test/native_objc_test/native_objc_test.dart
@@ -20,8 +20,9 @@ group('native_objc_test', () { setUpAll(() { logWarnings(); - lib = NativeObjCLibrary(DynamicLibrary.open( - File('test/native_objc_test/native_objc_test.dylib').absolute.path)); + final dylib = File('test/native_objc_test/native_objc_test.dylib'); + verifySetupFile(dylib); + lib = NativeObjCLibrary(DynamicLibrary.open(dylib.absolute.path)); }); test('generate_bindings', () {
diff --git a/pkgs/ffigen/test/native_test/native_test.dart b/pkgs/ffigen/test/native_test/native_test.dart index 08e1475..d98b686 100644 --- a/pkgs/ffigen/test/native_test/native_test.dart +++ b/pkgs/ffigen/test/native_test/native_test.dart
@@ -24,8 +24,9 @@ } else if (Platform.isWindows) { dylibName = r'test\native_test\native_test.dll'; } - bindings = - NativeLibrary(DynamicLibrary.open(File(dylibName).absolute.path)); + final dylib = File(dylibName); + verifySetupFile(dylib); + bindings = NativeLibrary(DynamicLibrary.open(dylib.absolute.path)); }); test('generate_bindings', () {
diff --git a/pkgs/ffigen/test/test_utils.dart b/pkgs/ffigen/test/test_utils.dart index 624e626..196da1e 100644 --- a/pkgs/ffigen/test/test_utils.dart +++ b/pkgs/ffigen/test/test_utils.dart
@@ -31,6 +31,15 @@ } } +/// Check whether a file generated by test/setup.dart exists and throw a helpful +/// exception if it does not. +void verifySetupFile(File file) { + if (!file.existsSync()) { + throw NotFoundException("The file ${file.path} does not exist.\n\n" + "You may need to run: dart run test/setup.dart\n"); + } +} + /// Generates actual file using library and tests using [expect] with expected /// /// This will not delete the actual debug file incase [expect] throws an error.