-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added typing to tryHandlers to catch static errors
- Loading branch information
Showing
6 changed files
with
98 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,5 @@ | ||
import 'package:flutter_dev_utils/flutter_dev_utils.dart'; | ||
import 'package:flutter_dev_utils/src/test/test_exception.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'try_handler/test_try_handler.dart'; | ||
|
||
void main() { | ||
test('test_async_try_handler', () async { | ||
final result = await asyncTryHandler( | ||
tryFunction: () async { | ||
return await Future.delayed( | ||
const Duration(milliseconds: 50), () => true); | ||
}, | ||
); | ||
expectLater(result, true); | ||
}); | ||
|
||
test('catch_correct_known_exception_async', () async { | ||
final result = await asyncTryHandler( | ||
tryFunction: () async { | ||
return await Future.delayed(const Duration(milliseconds: 50), () { | ||
throw TestException(); | ||
}); | ||
}, | ||
catchKnownExceptions: { | ||
TestException(): (e) async => true, | ||
}, | ||
catchUnknownExceptions: (e) async => false, | ||
); | ||
|
||
expectLater(result, true); | ||
}); | ||
test('catch_correct_known_exception_sync', () { | ||
final result = syncTryHandler( | ||
tryFunction: () { | ||
throw TestException(); | ||
}, | ||
catchKnownExceptions: { | ||
TestException(): (e) => true, | ||
}, | ||
catchUnknownExceptions: (e) => false, | ||
); | ||
|
||
expectLater(result, true); | ||
}); | ||
test('test_sync_try_handler', () { | ||
expect('a', 'a'); | ||
}); | ||
testTryHandler(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'package:flutter_dev_utils/flutter_dev_utils.dart'; | ||
import 'package:flutter_dev_utils/src/test/test_exception.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void testTryHandler() { | ||
group('try handler', () { | ||
test('test_sync_try_handler', () { | ||
final result = syncTryHandler( | ||
tryFunction: () { | ||
return true; | ||
}, | ||
); | ||
expect(result, true); | ||
}); | ||
|
||
test('test_async_try_handler', () async { | ||
final result = await asyncTryHandler( | ||
tryFunction: () async { | ||
return await Future.delayed( | ||
const Duration(milliseconds: 50), () => true); | ||
}, | ||
); | ||
expectLater(result, true); | ||
}); | ||
|
||
test('catch_correct_known_exception_sync', () { | ||
final result = syncTryHandler( | ||
tryFunction: () { | ||
throw TestException(); | ||
}, | ||
catchKnownExceptions: { | ||
TestException(): (e) => true, | ||
}, | ||
catchUnknownExceptions: (e) => false, | ||
); | ||
|
||
expect(result, true); | ||
}); | ||
|
||
test('catch_correct_known_exception_async', () async { | ||
final result = await asyncTryHandler( | ||
tryFunction: () async { | ||
return await Future.delayed(const Duration(milliseconds: 50), () { | ||
throw TestException(); | ||
}); | ||
}, | ||
catchKnownExceptions: { | ||
TestException(): (e) async => true, | ||
}, | ||
catchUnknownExceptions: (e) async => false, | ||
); | ||
|
||
expectLater(result, true); | ||
}); | ||
|
||
test('catch_static_return_type_sync', () { | ||
final result = syncTryHandler<bool>(tryFunction: () { | ||
return true; | ||
}); | ||
|
||
expect(result, true); | ||
}); | ||
|
||
test('catch_static_return_type_async', () async { | ||
final result = await asyncTryHandler<bool>(tryFunction: () async { | ||
return true; | ||
}); | ||
|
||
expectLater(result, true); | ||
}); | ||
}); | ||
} |