From bf743e9122d4078b779248c52feadee5077f781c Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Fri, 9 Feb 2024 13:39:29 +0100 Subject: [PATCH 1/9] Fixed issue with clipping --- CHANGELOG.md | 4 ++++ .../widget/touch_feedback/touch_feedback.dart | 18 ++++++++---------- pubspec.yaml | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf744f7..abec558 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [2.1.4+1] - 2024-02-09 +### Fixed +- Issue where android clips outside of the TouchFeedback widget (breaking shadows etc) + ## [2.1.4] - 2024-02-09 ### Added - Improved TouchFeedBack android implementation by using a custom inkwell that draws on top of its child and can be nested. See the example for more information. diff --git a/lib/src/widget/touch_feedback/touch_feedback.dart b/lib/src/widget/touch_feedback/touch_feedback.dart index 7ae515b..922491e 100644 --- a/lib/src/widget/touch_feedback/touch_feedback.dart +++ b/lib/src/widget/touch_feedback/touch_feedback.dart @@ -41,16 +41,14 @@ class _TouchFeedBackState extends State { @override Widget build(BuildContext context) { if ((!widget.forceIOS && context.isAndroidTheme) || widget.forceAndroid) { - return ClipRRect( - borderRadius: widget.borderRadius ?? BorderRadius.zero, - child: TouchFeedBackAndroid( - onClick: widget.onClick, - semanticsLabel: widget.semanticsLabel, - borderRadius: widget.borderRadius, - shapeBorder: widget.shapeBorder, - androidSplashColor: widget.androidSplashColor, - child: widget.child, - ), + return TouchFeedBackAndroid( + onClick: widget.onClick, + semanticsLabel: widget.semanticsLabel, + borderRadius: widget.borderRadius, + elevation: widget.elevation, + shapeBorder: widget.shapeBorder, + androidSplashColor: widget.androidSplashColor, + child: widget.child, ); } return TouchFeedBackIOS( diff --git a/pubspec.yaml b/pubspec.yaml index be21773..1ef09ee 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: icapps architecture components for flutter projects. Contains commo homepage: https://github.com/icapps/flutter-icapps-architecture repository: https://github.com/icapps/flutter-icapps-architecture issue_tracker: https://github.com/icapps/flutter-icapps-architecture/issues -version: 2.1.4 +version: 2.1.4+1 environment: sdk: '>=3.0.0 <4.0.0' From f156db389abc4680735b4a4087fcf0ec9f2a7e8c Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Fri, 9 Feb 2024 13:48:44 +0100 Subject: [PATCH 2/9] Attempt to fix issue with radius --- CHANGELOG.md | 5 ++- .../widget/touch_feedback/better_inkwell.dart | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abec558..25439c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog +## [2.1.4+2] - 2024-02-09 ## [2.1.4+1] - 2024-02-09 -### Fixed -- Issue where android clips outside of the TouchFeedback widget (breaking shadows etc) +### Changed +- Issue where android clips outside of the TouchFeedback widget (breaking shadows etc) ## [2.1.4] - 2024-02-09 ### Added diff --git a/lib/src/widget/touch_feedback/better_inkwell.dart b/lib/src/widget/touch_feedback/better_inkwell.dart index 7653a88..e9292b2 100644 --- a/lib/src/widget/touch_feedback/better_inkwell.dart +++ b/lib/src/widget/touch_feedback/better_inkwell.dart @@ -5,12 +5,14 @@ class BetterInkwell extends StatefulWidget { final Color colorPress; final Widget child; final VoidCallback? onTap; + final BorderRadius? borderRadius; final HitTestBehavior? behavior; const BetterInkwell({ required this.child, this.onTap, this.behavior, + this.borderRadius, this.colorHover = const Color(0x0A000000), this.colorPress = const Color(0x1E000000), super.key, @@ -20,8 +22,7 @@ class BetterInkwell extends StatefulWidget { State createState() => _BetterInkwellState(); } -class _BetterInkwellState extends State - with SingleTickerProviderStateMixin { +class _BetterInkwellState extends State with SingleTickerProviderStateMixin { var _isTouched = false; var _touchPosition = Offset.zero; static const durationSeconds = 10; @@ -65,8 +66,7 @@ class _BetterInkwellState extends State do { ancestor?.ignoreTouch = true; if (!mounted) return; - ancestor = - ancestor?.context.findAncestorStateOfType<_BetterInkwellState>(); + ancestor = ancestor?.context.findAncestorStateOfType<_BetterInkwellState>(); } while (ancestor != null); } @@ -98,14 +98,17 @@ class _BetterInkwellState extends State child!, Positioned.fill( child: IgnorePointer( - child: AnimatedOpacity( - duration: const Duration(milliseconds: 200), - opacity: _isTouched ? 1 : 0, - child: CustomPaint( - painter: _RipplePainter( - center: _touchPosition, - radius: _animationController!.value * speed, - color: widget.colorPress, + child: ClipRRect( + borderRadius: widget.borderRadius ?? BorderRadius.zero, + child: AnimatedOpacity( + duration: const Duration(milliseconds: 200), + opacity: _isTouched ? 1 : 0, + child: CustomPaint( + painter: _RipplePainter( + center: _touchPosition, + radius: _animationController!.value * speed, + color: widget.colorPress, + ), ), ), ), @@ -117,7 +120,10 @@ class _BetterInkwellState extends State duration: const Duration(milliseconds: 200), opacity: _isTouched ? 1 : 0, child: Container( - color: widget.colorHover, + decoration: BoxDecoration( + borderRadius: widget.borderRadius, + color: widget.colorHover, + ), ), ), ), @@ -153,8 +159,5 @@ class _RipplePainter extends CustomPainter { } @override - bool shouldRepaint(covariant CustomPainter oldDelegate) => - oldDelegate is! _RipplePainter || - oldDelegate.center != center || - oldDelegate.radius != radius; + bool shouldRepaint(covariant CustomPainter oldDelegate) => oldDelegate is! _RipplePainter || oldDelegate.center != center || oldDelegate.radius != radius; } From 1aec228478689047e962b29b0e9ec6df1f0f61a6 Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Fri, 9 Feb 2024 13:51:47 +0100 Subject: [PATCH 3/9] apply borderRadius --- lib/src/widget/touch_feedback/touch_feedback.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/widget/touch_feedback/touch_feedback.dart b/lib/src/widget/touch_feedback/touch_feedback.dart index 922491e..57f4f8d 100644 --- a/lib/src/widget/touch_feedback/touch_feedback.dart +++ b/lib/src/widget/touch_feedback/touch_feedback.dart @@ -100,6 +100,7 @@ class TouchFeedBackAndroid extends StatelessWidget { shadowColor: shadowColor, borderRadius: borderRadius, child: BetterInkwell( + borderRadius: borderRadius, onTap: onClick, child: child, ), From 7959c890b868a8e5a452e8ee21136754d3a2fefe Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Fri, 9 Feb 2024 13:58:32 +0100 Subject: [PATCH 4/9] Attempt to fix alignment --- .../widget/touch_feedback/better_inkwell.dart | 4 ++- .../widget/touch_feedback/touch_feedback.dart | 25 +++---------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/lib/src/widget/touch_feedback/better_inkwell.dart b/lib/src/widget/touch_feedback/better_inkwell.dart index e9292b2..e6d077f 100644 --- a/lib/src/widget/touch_feedback/better_inkwell.dart +++ b/lib/src/widget/touch_feedback/better_inkwell.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; class BetterInkwell extends StatefulWidget { + final Color color; final Color colorHover; final Color colorPress; final Widget child; @@ -15,6 +16,7 @@ class BetterInkwell extends StatefulWidget { this.borderRadius, this.colorHover = const Color(0x0A000000), this.colorPress = const Color(0x1E000000), + this.color = Colors.transparent, super.key, }); @@ -131,7 +133,7 @@ class _BetterInkwellState extends State with SingleTickerProvider ], ), child: Container( - color: Colors.transparent, + color: widget.color, child: widget.child, ), ), diff --git a/lib/src/widget/touch_feedback/touch_feedback.dart b/lib/src/widget/touch_feedback/touch_feedback.dart index 57f4f8d..e0ec240 100644 --- a/lib/src/widget/touch_feedback/touch_feedback.dart +++ b/lib/src/widget/touch_feedback/touch_feedback.dart @@ -45,9 +45,6 @@ class _TouchFeedBackState extends State { onClick: widget.onClick, semanticsLabel: widget.semanticsLabel, borderRadius: widget.borderRadius, - elevation: widget.elevation, - shapeBorder: widget.shapeBorder, - androidSplashColor: widget.androidSplashColor, child: widget.child, ); } @@ -69,22 +66,14 @@ class TouchFeedBackAndroid extends StatelessWidget { final VoidCallback? onClick; final String? semanticsLabel; final Color color; - final double elevation; final BorderRadius? borderRadius; - final Color? shadowColor; - final ShapeBorder? shapeBorder; - final Color? androidSplashColor; const TouchFeedBackAndroid({ required this.child, required this.onClick, this.semanticsLabel, this.color = Colors.transparent, - this.elevation = 0, this.borderRadius, - this.shadowColor, - this.shapeBorder, - this.androidSplashColor, super.key, }); @@ -93,17 +82,11 @@ class TouchFeedBackAndroid extends StatelessWidget { return Semantics( label: semanticsLabel, button: true, - child: Material( - color: color, - shape: shapeBorder, - elevation: elevation, - shadowColor: shadowColor, + child: BetterInkwell( borderRadius: borderRadius, - child: BetterInkwell( - borderRadius: borderRadius, - onTap: onClick, - child: child, - ), + onTap: onClick, + color: color, + child: child, ), ); } From 21fd61f925c16d116ccedb91d5ea25bd475176a1 Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Fri, 9 Feb 2024 14:07:15 +0100 Subject: [PATCH 5/9] Published --- lib/src/widget/touch_feedback/better_inkwell.dart | 11 ++++++++--- pubspec.yaml | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/widget/touch_feedback/better_inkwell.dart b/lib/src/widget/touch_feedback/better_inkwell.dart index e6d077f..38cf61e 100644 --- a/lib/src/widget/touch_feedback/better_inkwell.dart +++ b/lib/src/widget/touch_feedback/better_inkwell.dart @@ -24,7 +24,8 @@ class BetterInkwell extends StatefulWidget { State createState() => _BetterInkwellState(); } -class _BetterInkwellState extends State with SingleTickerProviderStateMixin { +class _BetterInkwellState extends State + with SingleTickerProviderStateMixin { var _isTouched = false; var _touchPosition = Offset.zero; static const durationSeconds = 10; @@ -68,7 +69,8 @@ class _BetterInkwellState extends State with SingleTickerProvider do { ancestor?.ignoreTouch = true; if (!mounted) return; - ancestor = ancestor?.context.findAncestorStateOfType<_BetterInkwellState>(); + ancestor = + ancestor?.context.findAncestorStateOfType<_BetterInkwellState>(); } while (ancestor != null); } @@ -161,5 +163,8 @@ class _RipplePainter extends CustomPainter { } @override - bool shouldRepaint(covariant CustomPainter oldDelegate) => oldDelegate is! _RipplePainter || oldDelegate.center != center || oldDelegate.radius != radius; + bool shouldRepaint(covariant CustomPainter oldDelegate) => + oldDelegate is! _RipplePainter || + oldDelegate.center != center || + oldDelegate.radius != radius; } diff --git a/pubspec.yaml b/pubspec.yaml index 1ef09ee..1c8c9a9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: icapps architecture components for flutter projects. Contains commo homepage: https://github.com/icapps/flutter-icapps-architecture repository: https://github.com/icapps/flutter-icapps-architecture issue_tracker: https://github.com/icapps/flutter-icapps-architecture/issues -version: 2.1.4+1 +version: 2.1.4+2 environment: sdk: '>=3.0.0 <4.0.0' From fba4b54881ec589e3e52cbe3963d74aa724cd1bf Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Mon, 12 Feb 2024 15:21:29 +0100 Subject: [PATCH 6/9] Updated logger + fixed missing material --- CHANGELOG.md | 5 +++++ lib/src/util/logging/impl/LoggerPrinter.dart | 12 +++++------ lib/src/util/logging/logging.dart | 12 +++++------ .../widget/touch_feedback/touch_feedback.dart | 20 +++++++++++++++++-- pubspec.yaml | 4 ++-- test/util/logging/logging_test.dart | 12 +++++------ 6 files changed, 43 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25439c7..e5407df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## [2.1.5] - 2024-02-12 +### Changed +- Fixed missing material in the TouchFeedback widget +- Updated logger to v2.0.0 + ## [2.1.4+2] - 2024-02-09 ## [2.1.4+1] - 2024-02-09 ### Changed diff --git a/lib/src/util/logging/impl/LoggerPrinter.dart b/lib/src/util/logging/impl/LoggerPrinter.dart index 42ce2ee..377d05f 100644 --- a/lib/src/util/logging/impl/LoggerPrinter.dart +++ b/lib/src/util/logging/impl/LoggerPrinter.dart @@ -8,21 +8,21 @@ import 'package:logger/logger.dart'; @immutable class OurPrettyPrinter extends LogPrinter { static final levelColors = { - Level.verbose: AnsiColor.fg(AnsiColor.grey(0.5)), + Level.trace: AnsiColor.fg(AnsiColor.grey(0.5)), Level.debug: AnsiColor.none(), Level.info: AnsiColor.fg(12), Level.warning: AnsiColor.fg(208), Level.error: AnsiColor.fg(196), - Level.wtf: AnsiColor.fg(199), + Level.fatal: AnsiColor.fg(199), }; static final levelEmojis = { - Level.verbose: '', + Level.trace: '', Level.debug: '🐛 ', Level.info: '💡 ', Level.warning: '⚠️ ', Level.error: '⛔ ', - Level.wtf: '👾 ', + Level.fatal: '👾 ', }; /// Matches a stacktrace line as generated on Android/iOS devices. @@ -145,8 +145,8 @@ class OurPrettyPrinter extends LogPrinter { AnsiColor _getErrorColor(Level level) { if (colors) { - if (level == Level.wtf) { - return levelColors[Level.wtf]!.toBg(); + if (level == Level.fatal) { + return levelColors[Level.fatal]!.toBg(); } else { return levelColors[Level.error]!.toBg(); } diff --git a/lib/src/util/logging/logging.dart b/lib/src/util/logging/logging.dart index 01eab02..c3d459f 100644 --- a/lib/src/util/logging/logging.dart +++ b/lib/src/util/logging/logging.dart @@ -17,7 +17,7 @@ class LoggingConfiguration { this.printTime = true, this.onLog, this.isEnabled = true, - this.loggingLevel = Level.verbose, + this.loggingLevel = Level.trace, }); } @@ -132,23 +132,23 @@ class LoggerLogImpl extends Log { @override void debug(String message, {dynamic error, StackTrace? trace}) => - logger.d(message, error, trace); + logger.d(message, error: error, stackTrace: trace); @override void error(String message, {error, StackTrace? trace}) => - logger.e(message, error, trace); + logger.e(message, error: error, stackTrace: trace); @override void info(String message, {dynamic error, StackTrace? trace}) => - logger.i(message, error, trace); + logger.i(message, error: error, stackTrace: trace); @override void verbose(String message, {dynamic error, StackTrace? trace}) => - logger.v(message, error, trace); + logger.t(message, error: error, stackTrace: trace); @override void warning(String message, {dynamic error, StackTrace? trace}) => - logger.w(message, error, trace); + logger.w(message, error: error, stackTrace: trace); @override void logNetworkError(NetworkError error) { diff --git a/lib/src/widget/touch_feedback/touch_feedback.dart b/lib/src/widget/touch_feedback/touch_feedback.dart index e0ec240..7a7c19f 100644 --- a/lib/src/widget/touch_feedback/touch_feedback.dart +++ b/lib/src/widget/touch_feedback/touch_feedback.dart @@ -45,6 +45,10 @@ class _TouchFeedBackState extends State { onClick: widget.onClick, semanticsLabel: widget.semanticsLabel, borderRadius: widget.borderRadius, + color: widget.color, + elevation: widget.elevation, + shadowColor: widget.shadowColor, + shapeBorder: widget.shapeBorder, child: widget.child, ); } @@ -67,6 +71,9 @@ class TouchFeedBackAndroid extends StatelessWidget { final String? semanticsLabel; final Color color; final BorderRadius? borderRadius; + final double elevation; + final Color? shadowColor; + final ShapeBorder? shapeBorder; const TouchFeedBackAndroid({ required this.child, @@ -74,6 +81,9 @@ class TouchFeedBackAndroid extends StatelessWidget { this.semanticsLabel, this.color = Colors.transparent, this.borderRadius, + this.elevation = 0, + this.shadowColor, + this.shapeBorder, super.key, }); @@ -85,8 +95,14 @@ class TouchFeedBackAndroid extends StatelessWidget { child: BetterInkwell( borderRadius: borderRadius, onTap: onClick, - color: color, - child: child, + child: Material( + color: color, + shape: shapeBorder, + elevation: elevation, + shadowColor: shadowColor, + borderRadius: borderRadius, + child: child, + ), ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index 1c8c9a9..225f686 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: icapps architecture components for flutter projects. Contains commo homepage: https://github.com/icapps/flutter-icapps-architecture repository: https://github.com/icapps/flutter-icapps-architecture issue_tracker: https://github.com/icapps/flutter-icapps-architecture/issues -version: 2.1.4+2 +version: 2.1.5 environment: sdk: '>=3.0.0 <4.0.0' @@ -15,7 +15,7 @@ dependencies: dio: ^5.2.1+1 flutter: sdk: flutter - logger: ^1.4.0 + logger: ^2.0.0 provider: ^6.0.5 shared_preferences: ^2.2.0 tuple: ^2.0.2 diff --git a/test/util/logging/logging_test.dart b/test/util/logging/logging_test.dart index 23495ff..03c2bec 100644 --- a/test/util/logging/logging_test.dart +++ b/test/util/logging/logging_test.dart @@ -144,9 +144,9 @@ void testWithLogger() { test( 'Test logger level verbose', () => _testLogLevel( - logLevel: Level.verbose, + logLevel: Level.trace, expectLogs: (messages) { - expect(messages[0], ' Verbose message'); + expect(messages[0], ' Trace message'); expect(messages[1], ' 🐛 Debug message'); expect(messages[2], ' 💡 Info message'); expect(messages[3], ' ⚠️ Warning message'); @@ -300,7 +300,7 @@ void testWithLogger() { colors: true, printEmojis: true, printTime: false) - .log(LogEvent(Level.wtf, ['Some', 'body'], null, null)); + .log(LogEvent(Level.fatal, ['Some', 'body'])); expect(lines[0], '\x1B[38;5;199m 👾 [\x1B[0m'); expect(lines[1], '\x1B[38;5;199m 👾 "Some",\x1B[0m'); @@ -316,13 +316,13 @@ void testWithLogger() { colors: true, printEmojis: true, printTime: false) - .log(LogEvent(Level.error, 'Error', ArgumentError(), null)); + .log(LogEvent(Level.error, 'Error', error: ArgumentError())); expect( lines[1], '\x1B[39m\x1B[48;5;196mInvalid argument(s)\x1B[0m\x1B[49m'); expect(lines[0], '\x1B[38;5;196m ⛔ Error\x1B[0m'); }); - test('Test logger methods default error color wtf', () { + test('Test logger methods default error color fatal', () { final lines = OurPrettyPrinter( methodCount: 0, errorMethodCount: 1, @@ -331,7 +331,7 @@ void testWithLogger() { colors: true, printEmojis: true, printTime: false) - .log(LogEvent(Level.wtf, 'WTF', ArgumentError(), null)); + .log(LogEvent(Level.fatal, 'Fatal', error: ArgumentError())); expect( lines[1], '\x1B[39m\x1B[48;5;199mInvalid argument(s)\x1B[0m\x1B[49m'); From 32af7335730484565073226a2d8c69f34b85d40e Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Mon, 12 Feb 2024 15:45:42 +0100 Subject: [PATCH 7/9] Updated dependencies + tests --- CHANGELOG.md | 2 +- example/lib/viewmodel/logger_viewmodel.dart | 2 +- lib/src/util/logging/logging.dart | 87 +++----- pubspec.yaml | 18 +- .../change_notifier_ex_test.mocks.dart | 11 +- .../connectivity/connectivity_test.mocks.dart | 5 +- .../environment/os_config_test.mocks.dart | 66 +++++- test/util/logging/logging_test.dart | 199 +++++------------- test/util/logging/logging_test.mocks.dart | 64 +++--- .../preferences_storage_test.mocks.dart | 20 +- 10 files changed, 230 insertions(+), 244 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5407df..a904f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [2.1.5] - 2024-02-12 ### Changed - Fixed missing material in the TouchFeedback widget -- Updated logger to v2.0.0 +- Updated dependencies (logger to v2, connectivity_plus to v5) ## [2.1.4+2] - 2024-02-09 ## [2.1.4+1] - 2024-02-09 diff --git a/example/lib/viewmodel/logger_viewmodel.dart b/example/lib/viewmodel/logger_viewmodel.dart index d086722..8df4605 100644 --- a/example/lib/viewmodel/logger_viewmodel.dart +++ b/example/lib/viewmodel/logger_viewmodel.dart @@ -14,7 +14,7 @@ class LoggerViewModel with ChangeNotifierEx { LoggingConfiguration( isEnabled: true, shouldLogNetworkInfo: true, - loggingLevel: Level.verbose, + loggingLevel: Level.trace, onLog: _onLog, ), ); diff --git a/lib/src/util/logging/logging.dart b/lib/src/util/logging/logging.dart index c3d459f..207a3f9 100644 --- a/lib/src/util/logging/logging.dart +++ b/lib/src/util/logging/logging.dart @@ -22,30 +22,25 @@ class LoggingConfiguration { } abstract class Log { - void verbose(String message, {dynamic error, StackTrace? trace}); + void trace(String message, {dynamic error, StackTrace? stackTrace}); - void debug(String message, {dynamic error, StackTrace? trace}); + void debug(String message, {dynamic error, StackTrace? stackTrace}); - void info(String message, {dynamic error, StackTrace? trace}); + void info(String message, {dynamic error, StackTrace? stackTrace}); - void warning(String message, {dynamic error, StackTrace? trace}); + void warning(String message, {dynamic error, StackTrace? stackTrace}); - void error(String message, {dynamic error, StackTrace? trace}); + void error(String message, {dynamic error, StackTrace? stackTrace}); - void v(String message, {dynamic error, StackTrace? trace}) => - verbose(message, error: error, trace: trace); + void t(String message, {dynamic error, StackTrace? stackTrace}) => trace(message, error: error, stackTrace: stackTrace); - void d(String message, {dynamic error, StackTrace? trace}) => - debug(message, error: error, trace: trace); + void d(String message, {dynamic error, StackTrace? stackTrace}) => debug(message, error: error, stackTrace: stackTrace); - void i(String message, {dynamic error, StackTrace? trace}) => - info(message, error: error, trace: trace); + void i(String message, {dynamic error, StackTrace? stackTrace}) => info(message, error: error, stackTrace: stackTrace); - void w(String message, {dynamic error, StackTrace? trace}) => - warning(message, error: error, trace: trace); + void w(String message, {dynamic error, StackTrace? stackTrace}) => warning(message, error: error, stackTrace: stackTrace); - void e(String message, {dynamic error, StackTrace? trace}) => - this.error(message, error: error, trace: trace); + void e(String message, {dynamic error, StackTrace? stackTrace}) => this.error(message, error: error, stackTrace: stackTrace); void logNetworkError(NetworkError error); @@ -131,24 +126,19 @@ class LoggerLogImpl extends Log { LoggerLogImpl(this.logger, {required this.logNetworkInfo}); @override - void debug(String message, {dynamic error, StackTrace? trace}) => - logger.d(message, error: error, stackTrace: trace); + void debug(String message, {dynamic error, StackTrace? stackTrace}) => logger.d(message, error: error, stackTrace: stackTrace); @override - void error(String message, {error, StackTrace? trace}) => - logger.e(message, error: error, stackTrace: trace); + void error(String message, {error, StackTrace? stackTrace}) => logger.e(message, error: error, stackTrace: stackTrace); @override - void info(String message, {dynamic error, StackTrace? trace}) => - logger.i(message, error: error, stackTrace: trace); + void info(String message, {dynamic error, StackTrace? stackTrace}) => logger.i(message, error: error, stackTrace: stackTrace); @override - void verbose(String message, {dynamic error, StackTrace? trace}) => - logger.t(message, error: error, stackTrace: trace); + void trace(String message, {dynamic error, StackTrace? stackTrace}) => logger.t(message, error: error, stackTrace: stackTrace); @override - void warning(String message, {dynamic error, StackTrace? trace}) => - logger.w(message, error: error, stackTrace: trace); + void warning(String message, {dynamic error, StackTrace? stackTrace}) => logger.w(message, error: error, stackTrace: stackTrace); @override void logNetworkError(NetworkError error) { @@ -167,8 +157,7 @@ class LoggerLogImpl extends Log { ..writeln('response.data | ${response.data}') ..writeln('response.headers | ${response.headers}'); } - message.writeln( - '<--------------- ${request.method} - url: ${request.uri} - status code: ${response?.statusCode ?? 'N/A'}'); + message.writeln('<--------------- ${request.method} - url: ${request.uri} - status code: ${response?.statusCode ?? 'N/A'}'); this.error(message.toString()); } @@ -181,42 +170,41 @@ class LoggerLogImpl extends Log { @override void logNetworkResponse(Response response) { if (!logNetworkInfo) return; - debug( - '<--------------- ${response.requestOptions.method} - url: ${response.requestOptions.uri} - status code: ${response.statusCode ?? 'N/A'}'); + debug('<--------------- ${response.requestOptions.method} - url: ${response.requestOptions.uri} - status code: ${response.statusCode ?? 'N/A'}'); } } @visibleForTesting class VoidLogger implements Log { @override - void d(String message, {error, StackTrace? trace}) {} + void d(String message, {error, StackTrace? stackTrace}) {} @override - void debug(String message, {error, StackTrace? trace}) {} + void debug(String message, {error, StackTrace? stackTrace}) {} @override - void e(String message, {error, StackTrace? trace}) {} + void e(String message, {error, StackTrace? stackTrace}) {} @override - void error(String message, {error, StackTrace? trace}) {} + void error(String message, {error, StackTrace? stackTrace}) {} @override - void i(String message, {error, StackTrace? trace}) {} + void i(String message, {error, StackTrace? stackTrace}) {} @override - void info(String message, {error, StackTrace? trace}) {} + void info(String message, {error, StackTrace? stackTrace}) {} @override - void v(String message, {error, StackTrace? trace}) {} + void t(String message, {error, StackTrace? stackTrace}) {} @override - void verbose(String message, {error, StackTrace? trace}) {} + void trace(String message, {error, StackTrace? stackTrace}) {} @override - void w(String message, {error, StackTrace? trace}) {} + void w(String message, {error, StackTrace? stackTrace}) {} @override - void warning(String message, {error, StackTrace? trace}) {} + void warning(String message, {error, StackTrace? stackTrace}) {} @override void logNetworkError(NetworkError error) {} @@ -237,33 +225,26 @@ class PrefixLogger extends Log { PrefixLogger(this._name, this._delegate); @override - void debug(String message, {error, StackTrace? trace}) => - _delegate.debug('[$_name] $message', error: error, trace: trace); + void debug(String message, {error, StackTrace? stackTrace}) => _delegate.debug('[$_name] $message', error: error, stackTrace: stackTrace); @override - void error(String message, {Object? error, StackTrace? trace}) => - _delegate.error('[$_name] $message', error: error, trace: trace); + void error(String message, {Object? error, StackTrace? stackTrace}) => _delegate.error('[$_name] $message', error: error, stackTrace: stackTrace); @override - void info(String message, {error, StackTrace? trace}) => - _delegate.info('[$_name] $message', error: error, trace: trace); + void info(String message, {error, StackTrace? stackTrace}) => _delegate.info('[$_name] $message', error: error, stackTrace: stackTrace); @override void logNetworkError(NetworkError error) => _delegate.logNetworkError(error); @override - void logNetworkRequest(RequestOptions request) => - _delegate.logNetworkRequest(request); + void logNetworkRequest(RequestOptions request) => _delegate.logNetworkRequest(request); @override - void logNetworkResponse(Response response) => - _delegate.logNetworkResponse(response); + void logNetworkResponse(Response response) => _delegate.logNetworkResponse(response); @override - void verbose(String message, {error, StackTrace? trace}) => - _delegate.verbose('[$_name] $message', error: error, trace: trace); + void trace(String message, {error, StackTrace? stackTrace}) => _delegate.trace('[$_name] $message', error: error, stackTrace: stackTrace); @override - void warning(String message, {error, StackTrace? trace}) => - _delegate.warning('[$_name] $message', error: error, trace: trace); + void warning(String message, {error, StackTrace? stackTrace}) => _delegate.warning('[$_name] $message', error: error, stackTrace: stackTrace); } diff --git a/pubspec.yaml b/pubspec.yaml index 225f686..742a107 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,21 +10,21 @@ environment: dependencies: computer: ^3.2.1 - connectivity_plus: ^4.0.2 - device_info_plus: ^9.0.2 - dio: ^5.2.1+1 + connectivity_plus: ^5.0.2 + device_info_plus: ^9.1.2 + dio: ^5.4.0 flutter: sdk: flutter - logger: ^2.0.0 - provider: ^6.0.5 - shared_preferences: ^2.2.0 + logger: ^2.0.2+1 + provider: ^6.1.1 + shared_preferences: ^2.2.2 tuple: ^2.0.2 dev_dependencies: - build_runner: ^2.4.6 + build_runner: ^2.4.8 flutter_test: sdk: flutter - mockito: ^5.4.2 - flutter_lints: ^2.0.2 + mockito: ^5.4.4 + flutter_lints: ^2.0.3 flutter: \ No newline at end of file diff --git a/test/provider/change_notifier_ex_test.mocks.dart b/test/provider/change_notifier_ex_test.mocks.dart index 2a70f70..f1f993e 100644 --- a/test/provider/change_notifier_ex_test.mocks.dart +++ b/test/provider/change_notifier_ex_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.2 from annotations +// Mocks generated by Mockito 5.4.4 from annotations // in icapps_architecture/test/provider/change_notifier_ex_test.dart. // Do not manually edit this file. @@ -14,6 +14,8 @@ import 'package:mockito/src/dummies.dart' as _i3; // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors @@ -45,6 +47,7 @@ class MockStreamSubscription extends _i1.Mock Invocation.getter(#isPaused), returnValue: false, ) as bool); + @override _i2.Future cancel() => (super.noSuchMethod( Invocation.method( @@ -54,6 +57,7 @@ class MockStreamSubscription extends _i1.Mock returnValue: _i2.Future.value(), returnValueForMissingStub: _i2.Future.value(), ) as _i2.Future); + @override void onData(void Function(T)? handleData) => super.noSuchMethod( Invocation.method( @@ -62,6 +66,7 @@ class MockStreamSubscription extends _i1.Mock ), returnValueForMissingStub: null, ); + @override void onError(Function? handleError) => super.noSuchMethod( Invocation.method( @@ -70,6 +75,7 @@ class MockStreamSubscription extends _i1.Mock ), returnValueForMissingStub: null, ); + @override void onDone(void Function()? handleDone) => super.noSuchMethod( Invocation.method( @@ -78,6 +84,7 @@ class MockStreamSubscription extends _i1.Mock ), returnValueForMissingStub: null, ); + @override void pause([_i2.Future? resumeSignal]) => super.noSuchMethod( Invocation.method( @@ -86,6 +93,7 @@ class MockStreamSubscription extends _i1.Mock ), returnValueForMissingStub: null, ); + @override void resume() => super.noSuchMethod( Invocation.method( @@ -94,6 +102,7 @@ class MockStreamSubscription extends _i1.Mock ), returnValueForMissingStub: null, ); + @override _i2.Future asFuture([E? futureValue]) => (super.noSuchMethod( Invocation.method( diff --git a/test/util/connectivity/connectivity_test.mocks.dart b/test/util/connectivity/connectivity_test.mocks.dart index 7eb2e10..d6e49a4 100644 --- a/test/util/connectivity/connectivity_test.mocks.dart +++ b/test/util/connectivity/connectivity_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.2 from annotations +// Mocks generated by Mockito 5.4.4 from annotations // in icapps_architecture/test/util/connectivity/connectivity_test.dart. // Do not manually edit this file. @@ -14,6 +14,8 @@ import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors @@ -35,6 +37,7 @@ class MockConnectivity extends _i1.Mock implements _i2.Connectivity { Invocation.getter(#onConnectivityChanged), returnValue: _i3.Stream<_i4.ConnectivityResult>.empty(), ) as _i3.Stream<_i4.ConnectivityResult>); + @override _i3.Future<_i4.ConnectivityResult> checkConnectivity() => (super.noSuchMethod( Invocation.method( diff --git a/test/util/environment/os_config_test.mocks.dart b/test/util/environment/os_config_test.mocks.dart index eb62264..2992f4e 100644 --- a/test/util/environment/os_config_test.mocks.dart +++ b/test/util/environment/os_config_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.2 from annotations +// Mocks generated by Mockito 5.4.4 from annotations // in icapps_architecture/test/util/environment/os_config_test.dart. // Do not manually edit this file. @@ -15,11 +15,14 @@ import 'package:device_info_plus/src/model/windows_device_info.dart' as _i7; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart' as _i8; import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i11; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors @@ -120,6 +123,7 @@ class MockDeviceInfoPlugin extends _i1.Mock implements _i9.DeviceInfoPlugin { Invocation.getter(#androidInfo), )), ) as _i10.Future<_i2.AndroidDeviceInfo>); + @override _i10.Future<_i3.IosDeviceInfo> get iosInfo => (super.noSuchMethod( Invocation.getter(#iosInfo), @@ -128,6 +132,7 @@ class MockDeviceInfoPlugin extends _i1.Mock implements _i9.DeviceInfoPlugin { Invocation.getter(#iosInfo), )), ) as _i10.Future<_i3.IosDeviceInfo>); + @override _i10.Future<_i4.LinuxDeviceInfo> get linuxInfo => (super.noSuchMethod( Invocation.getter(#linuxInfo), @@ -137,6 +142,7 @@ class MockDeviceInfoPlugin extends _i1.Mock implements _i9.DeviceInfoPlugin { Invocation.getter(#linuxInfo), )), ) as _i10.Future<_i4.LinuxDeviceInfo>); + @override _i10.Future<_i5.WebBrowserInfo> get webBrowserInfo => (super.noSuchMethod( Invocation.getter(#webBrowserInfo), @@ -146,6 +152,7 @@ class MockDeviceInfoPlugin extends _i1.Mock implements _i9.DeviceInfoPlugin { Invocation.getter(#webBrowserInfo), )), ) as _i10.Future<_i5.WebBrowserInfo>); + @override _i10.Future<_i6.MacOsDeviceInfo> get macOsInfo => (super.noSuchMethod( Invocation.getter(#macOsInfo), @@ -155,6 +162,7 @@ class MockDeviceInfoPlugin extends _i1.Mock implements _i9.DeviceInfoPlugin { Invocation.getter(#macOsInfo), )), ) as _i10.Future<_i6.MacOsDeviceInfo>); + @override _i10.Future<_i7.WindowsDeviceInfo> get windowsInfo => (super.noSuchMethod( Invocation.getter(#windowsInfo), @@ -164,6 +172,7 @@ class MockDeviceInfoPlugin extends _i1.Mock implements _i9.DeviceInfoPlugin { Invocation.getter(#windowsInfo), )), ) as _i10.Future<_i7.WindowsDeviceInfo>); + @override _i10.Future<_i8.BaseDeviceInfo> get deviceInfo => (super.noSuchMethod( Invocation.getter(#deviceInfo), @@ -187,23 +196,36 @@ class MockAndroidBuildVersion extends _i1.Mock @override String get codename => (super.noSuchMethod( Invocation.getter(#codename), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#codename), + ), ) as String); + @override String get incremental => (super.noSuchMethod( Invocation.getter(#incremental), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#incremental), + ), ) as String); + @override String get release => (super.noSuchMethod( Invocation.getter(#release), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#release), + ), ) as String); + @override int get sdkInt => (super.noSuchMethod( Invocation.getter(#sdkInt), returnValue: 0, ) as int); + @override Map toMap() => (super.noSuchMethod( Invocation.method( @@ -225,27 +247,46 @@ class MockIosUtsname extends _i1.Mock implements _i3.IosUtsname { @override String get sysname => (super.noSuchMethod( Invocation.getter(#sysname), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#sysname), + ), ) as String); + @override String get nodename => (super.noSuchMethod( Invocation.getter(#nodename), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#nodename), + ), ) as String); + @override String get release => (super.noSuchMethod( Invocation.getter(#release), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#release), + ), ) as String); + @override String get version => (super.noSuchMethod( Invocation.getter(#version), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#version), + ), ) as String); + @override String get machine => (super.noSuchMethod( Invocation.getter(#machine), - returnValue: '', + returnValue: _i11.dummyValue( + this, + Invocation.getter(#machine), + ), ) as String); } @@ -263,36 +304,43 @@ class MockAndroidDisplayMetrics extends _i1.Mock Invocation.getter(#widthPx), returnValue: 0.0, ) as double); + @override double get heightPx => (super.noSuchMethod( Invocation.getter(#heightPx), returnValue: 0.0, ) as double); + @override double get xDpi => (super.noSuchMethod( Invocation.getter(#xDpi), returnValue: 0.0, ) as double); + @override double get yDpi => (super.noSuchMethod( Invocation.getter(#yDpi), returnValue: 0.0, ) as double); + @override double get widthInches => (super.noSuchMethod( Invocation.getter(#widthInches), returnValue: 0.0, ) as double); + @override double get heightInches => (super.noSuchMethod( Invocation.getter(#heightInches), returnValue: 0.0, ) as double); + @override double get sizeInches => (super.noSuchMethod( Invocation.getter(#sizeInches), returnValue: 0.0, ) as double); + @override Map toMap() => (super.noSuchMethod( Invocation.method( diff --git a/test/util/logging/logging_test.dart b/test/util/logging/logging_test.dart index 03c2bec..cff33f7 100644 --- a/test/util/logging/logging_test.dart +++ b/test/util/logging/logging_test.dart @@ -35,24 +35,20 @@ void main() { test('Test logs with prefix', () { final mock = MockLog(); final log = PrefixLogger('TestPrefix', mock); - log.v('Test'); + log.t('Test'); log.d('Test'); log.w('Test'); log.i('Test'); log.e('Test'); log.logNetworkRequest(RequestOptions(path: '/')); - log.logNetworkResponse( - Response(requestOptions: RequestOptions(path: '/'))); - log.logNetworkError(MockNetworkError( - DioException(requestOptions: RequestOptions(path: '/')))); + log.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/'))); + log.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/')))); - verify(mock.verbose(argThat(startsWith('[TestPrefix] ')))).called(1); + verify(mock.trace(argThat(startsWith('[TestPrefix] ')))).called(1); verify(mock.debug(argThat(startsWith('[TestPrefix] ')))).called(1); verify(mock.info(argThat(startsWith('[TestPrefix] ')))).called(1); verify(mock.warning(argThat(startsWith('[TestPrefix] ')))).called(1); - verify(mock.error(argThat(startsWith('[TestPrefix] ')), - trace: anyNamed('trace'), error: anyNamed('error'))) - .called(1); + verify(mock.error(argThat(startsWith('[TestPrefix] ')), stackTrace: anyNamed('stackTrace'), error: anyNamed('error'))).called(1); verify(mock.logNetworkResponse(any)).called(1); verify(mock.logNetworkRequest(any)).called(1); verify(mock.logNetworkError(any)).called(1); @@ -65,18 +61,14 @@ void main() { test('Output logger does not split short items', () { final lines = []; final output = WrappingOutput((str) => lines.add(str)); - output.output(OutputEvent(LogEvent(Level.info, 'Short string'), - ['Short string', 'Longer string that does not need to be split'])); - expect(lines, - ['Short string', 'Longer string that does not need to be split']); + output.output(OutputEvent(LogEvent(Level.info, 'Short string'), ['Short string', 'Longer string that does not need to be split'])); + expect(lines, ['Short string', 'Longer string that does not need to be split']); }); test('Output logger does splits long items', () { - final inputString = - base64Encode(List.generate(1000, (i) => i % 255)); + final inputString = base64Encode(List.generate(1000, (i) => i % 255)); final lines = []; final output = WrappingOutput((str) => lines.add(str)); - output.output(OutputEvent( - LogEvent(Level.info, 'Short string'), ['Short string', inputString])); + output.output(OutputEvent(LogEvent(Level.info, 'Short string'), ['Short string', inputString])); expect(lines, [ 'Short string', 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZ', @@ -88,7 +80,7 @@ void main() { void testWithLogger() { void _logAllLevels() { - staticLogger.v('Verbose message'); + staticLogger.t('Trace message'); staticLogger.d('Debug message'); staticLogger.i('Info message'); staticLogger.w('Warning message'); @@ -119,7 +111,7 @@ void testWithLogger() { onLog: (logLine) => buffer.add(logLine), )); _logAllLevels(); - expect(buffer[0], ' Verbose message'); + expect(buffer[0], ' Trace message'); expect(buffer[1], ' 🐛 Debug message'); expect(buffer[2], ' 💡 Info message'); expect(buffer[3], ' ⚠️ Warning message'); @@ -142,7 +134,7 @@ void testWithLogger() { } test( - 'Test logger level verbose', + 'Test logger level trace', () => _testLogLevel( logLevel: Level.trace, expectLogs: (messages) { @@ -202,21 +194,19 @@ void testWithLogger() { test('Test logger methods void', () { LoggingFactory.resetWithLogger(VoidLogger()); - staticLogger.v('Verbose message'); + staticLogger.t('Trace message'); staticLogger.d('Debug message'); staticLogger.i('Info message'); staticLogger.w('Warning message'); staticLogger.e('Error message'); - staticLogger.verbose('Verbose message'); + staticLogger.trace('Trace message'); staticLogger.debug('Debug message'); staticLogger.info('Info message'); staticLogger.warning('Warning message'); staticLogger.error('Error message'); staticLogger.logNetworkRequest(RequestOptions(path: '/')); - staticLogger.logNetworkResponse( - Response(requestOptions: RequestOptions(path: '/'))); - staticLogger.logNetworkError(MockNetworkError( - DioException(requestOptions: RequestOptions(path: '/')))); + staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/'))); + staticLogger.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/')))); }); test('Test logger methods default pretty', () { final buffer = MemoryOutput(); @@ -236,70 +226,42 @@ void testWithLogger() { ), logNetworkInfo: false), ); - staticLogger.v('Verbose message'); + staticLogger.t('Trace message'); staticLogger.d('Debug message'); staticLogger.i('Info message'); staticLogger.w('Warning message'); - staticLogger.e('Error message', - error: ArgumentError(), trace: StackTrace.current); + staticLogger.e('Error message', error: ArgumentError(), stackTrace: StackTrace.current); final messages = buffer.buffer.toList(growable: false); - expect(messages[0].lines.join(" "), - matches(' \\d+:\\d+:\\d+\\.\\d+\\s+Verbose message')); - expect(messages[1].lines.join(" "), - matches(' \\d+:\\d+:\\d+\\.\\d+\\s+🐛 Debug message')); - expect(messages[2].lines.join(" "), - matches(' \\d+:\\d+:\\d+\\.\\d+\\s+💡 Info message')); - expect(messages[3].lines.join(" "), - matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⚠️ Warning message')); - expect(messages[4].lines[0], - matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⛔ Error message')); - expect(messages[4].lines[1], - matches('\\d+:\\d+:\\d+\\.\\d+\\s+Invalid argument\\(s\\)')); - expect( - messages[4].lines[2], - matches( - '\\d+:\\d+:\\d+\\.\\d+\\s+#0 Declarer.test.. \\(package:test_api/src/backend/declarer.dart:\\d+:\\d+\\)')); - expect(messages[4].lines[3], - matches('\\d+:\\d+:\\d+\\.\\d+\\s+#1 ')); + expect(messages[0].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+Trace message')); + expect(messages[1].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+🐛 Debug message')); + expect(messages[2].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+💡 Info message')); + expect(messages[3].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⚠️ Warning message')); + expect(messages[4].lines[0], matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⛔ Error message')); + expect(messages[4].lines[1], matches('\\d+:\\d+:\\d+\\.\\d+\\s+Invalid argument\\(s\\)')); + expect(messages[4].lines[2], + matches('\\d+:\\d+:\\d+\\.\\d+\\s+#0 Declarer.test.. \\(package:test_api/src/backend/declarer.dart:\\d+:\\d+\\)')); + expect(messages[4].lines[3], matches('\\d+:\\d+:\\d+\\.\\d+\\s+#1 ')); expect( messages[4].lines[4], matches( - '\\d+:\\d+:\\d+\\.\\d+\\s+#2 Declarer.test. \\(package:test_api/src/backend/declarer.dart:\\d+:\\d+\\)')); - expect(messages[4].lines[5], - matches('\\d+:\\d+:\\d+\\.\\d+\\s+#3 ')); + '\\d+:\\d+:\\d+\\.\\d+\\s+#2 StackZoneSpecification._registerUnaryCallback. \\(package:stack_trace/src/stack_zone_specification.dart:\\d+:\\d+\\)')); + expect(messages[4].lines[5], matches('\\d+:\\d+:\\d+\\.\\d+\\s+#3 ')); }); test('Test logger methods default pretty include method', () { final buffer = MemoryOutput(); LoggingFactory.resetWithLogger(LoggerLogImpl( Logger( - printer: OurPrettyPrinter( - methodCount: 1, - errorMethodCount: 5, - stackTraceBeginIndex: 0, - lineLength: 50, - colors: false, - printEmojis: true, - printTime: false), + printer: OurPrettyPrinter(methodCount: 1, errorMethodCount: 5, stackTraceBeginIndex: 0, lineLength: 50, colors: false, printEmojis: true, printTime: false), output: buffer, ), logNetworkInfo: false)); staticLogger.d('Debug message'); final messages = buffer.buffer.toList(growable: false); - expect( - messages[0].lines[1], - matches( - '#0 OurPrettyPrinter.log \\(package:icapps_architecture/src/util/logging/impl/LoggerPrinter.dart:\\d+:\\d+\\)')); + expect(messages[0].lines[1], matches('#0 OurPrettyPrinter.log \\(package:icapps_architecture/src/util/logging/impl/LoggerPrinter.dart:\\d+:\\d+\\)')); expect(messages[0].lines[0], ' 🐛 Debug message'); }); test('Test logger methods default json', () { - final lines = OurPrettyPrinter( - methodCount: 0, - errorMethodCount: 5, - stackTraceBeginIndex: 1, - lineLength: 50, - colors: true, - printEmojis: true, - printTime: false) + final lines = OurPrettyPrinter(methodCount: 0, errorMethodCount: 5, stackTraceBeginIndex: 1, lineLength: 50, colors: true, printEmojis: true, printTime: false) .log(LogEvent(Level.fatal, ['Some', 'body'])); expect(lines[0], '\x1B[38;5;199m 👾 [\x1B[0m'); @@ -308,51 +270,25 @@ void testWithLogger() { expect(lines[3], '\x1B[38;5;199m 👾 ]\x1B[0m'); }); test('Test logger methods default error color', () { - final lines = OurPrettyPrinter( - methodCount: 0, - errorMethodCount: 1, - stackTraceBeginIndex: 0, - lineLength: 50, - colors: true, - printEmojis: true, - printTime: false) + final lines = OurPrettyPrinter(methodCount: 0, errorMethodCount: 1, stackTraceBeginIndex: 0, lineLength: 50, colors: true, printEmojis: true, printTime: false) .log(LogEvent(Level.error, 'Error', error: ArgumentError())); - expect( - lines[1], '\x1B[39m\x1B[48;5;196mInvalid argument(s)\x1B[0m\x1B[49m'); + expect(lines[1], '\x1B[39m\x1B[48;5;196mInvalid argument(s)\x1B[0m\x1B[49m'); expect(lines[0], '\x1B[38;5;196m ⛔ Error\x1B[0m'); }); test('Test logger methods default error color fatal', () { - final lines = OurPrettyPrinter( - methodCount: 0, - errorMethodCount: 1, - stackTraceBeginIndex: 0, - lineLength: 50, - colors: true, - printEmojis: true, - printTime: false) + final lines = OurPrettyPrinter(methodCount: 0, errorMethodCount: 1, stackTraceBeginIndex: 0, lineLength: 50, colors: true, printEmojis: true, printTime: false) .log(LogEvent(Level.fatal, 'Fatal', error: ArgumentError())); - expect( - lines[1], '\x1B[39m\x1B[48;5;199mInvalid argument(s)\x1B[0m\x1B[49m'); - expect(lines[0], '\x1B[38;5;199m 👾 WTF\x1B[0m'); + expect(lines[1], '\x1B[39m\x1B[48;5;199mInvalid argument(s)\x1B[0m\x1B[49m'); + expect(lines[0], '\x1B[38;5;199m 👾 Fatal\x1B[0m'); }); test('Test logger methods default build stack trace', () { - final formatted = OurPrettyPrinter( - methodCount: 0, - errorMethodCount: 1, - stackTraceBeginIndex: 0, - lineLength: 50, - colors: true, - printEmojis: true, - printTime: true) + final formatted = OurPrettyPrinter(methodCount: 0, errorMethodCount: 1, stackTraceBeginIndex: 0, lineLength: 50, colors: true, printEmojis: true, printTime: true) .formatStackTrace( - StackTrace.fromString( - '#1 Logger.log (package:logger/src/logger.dart:115:29)\npackages/logger/src/printers/pretty_printer.dart 91:37\npackage:logger/lib'), - 3); + StackTrace.fromString('#1 Logger.log (package:logger/src/logger.dart:115:29)\npackages/logger/src/printers/pretty_printer.dart 91:37\npackage:logger/lib'), 3); - expect(formatted, - '#0 packages/logger/src/printers/pretty_printer.dart 91:37\n#1 package:logger/lib'); + expect(formatted, '#0 packages/logger/src/printers/pretty_printer.dart 91:37\n#1 package:logger/lib'); }); }); group('Test network logging', () { @@ -363,10 +299,8 @@ void testWithLogger() { onLog: (logLine) => buffer.add(logLine), )); staticLogger.logNetworkRequest(RequestOptions(path: '/')); - staticLogger.logNetworkResponse( - Response(requestOptions: RequestOptions(path: '/'))); - staticLogger.logNetworkError(MockNetworkError( - DioException(requestOptions: RequestOptions(path: '/')))); + staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/'))); + staticLogger.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/')))); expect(buffer.isEmpty, true); }); test('Test logger network enabled', () { @@ -376,52 +310,31 @@ void testWithLogger() { printTime: false, onLog: (logLine) => buffer.add(logLine), )); - staticLogger.logNetworkRequest( - RequestOptions(path: '/', baseUrl: 'https://www.example.com')); - staticLogger.logNetworkResponse(Response( - requestOptions: - RequestOptions(path: '/', baseUrl: 'https://www.example.com'))); - staticLogger.logNetworkResponse(Response( - requestOptions: - RequestOptions(path: '/', baseUrl: 'https://www.example.com'), - statusCode: 404)); - staticLogger.logNetworkError(MockNetworkError(DioException( - requestOptions: - RequestOptions(path: '/', baseUrl: 'https://www.example.com')))); + staticLogger.logNetworkRequest(RequestOptions(path: '/', baseUrl: 'https://www.example.com')); + staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'))); + staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), statusCode: 404)); + staticLogger.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com')))); staticLogger.logNetworkError(MockNetworkError(DioException( - requestOptions: - RequestOptions(path: '/', baseUrl: 'https://www.example.com'), - response: Response( - requestOptions: RequestOptions( - path: '/', baseUrl: 'https://www.example.com'))))); + requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), + response: Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'))))); staticLogger.logNetworkError(MockNetworkError(DioException( - requestOptions: - RequestOptions(path: '/', baseUrl: 'https://www.example.com'), - response: Response( - requestOptions: - RequestOptions(path: '/', baseUrl: 'https://www.example.com'), - statusCode: 404)))); + requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), + response: Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), statusCode: 404)))); - expect(buffer[0], - ' 🐛 ---------------> GET - url: https://www.example.com/'); - expect(buffer[1], - ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: N/A'); - expect(buffer[2], - ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: 404'); + expect(buffer[0], ' 🐛 ---------------> GET - url: https://www.example.com/'); + expect(buffer[1], ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: N/A'); + expect(buffer[2], ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: 404'); expect(buffer[3], ' ⛔ request | GET - url: https://www.example.com/'); expect(buffer[4], ' ⛔ message | '); - expect(buffer[5], - ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); + expect(buffer[5], ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); expect(buffer[6], ' ⛔ '); expect(buffer[7], ' ⛔ response.data | null'); expect(buffer[8], ' ⛔ response.headers | '); - expect(buffer[9], - ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); + expect(buffer[9], ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); expect(buffer[10], ' ⛔ '); expect(buffer[11], ' ⛔ response.data | null'); expect(buffer[12], ' ⛔ response.headers | '); - expect(buffer[13], - ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: 404'); + expect(buffer[13], ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: 404'); }); }); } diff --git a/test/util/logging/logging_test.mocks.dart b/test/util/logging/logging_test.mocks.dart index 5009fd0..e0ae06d 100644 --- a/test/util/logging/logging_test.mocks.dart +++ b/test/util/logging/logging_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.2 from annotations +// Mocks generated by Mockito 5.4.4 from annotations // in icapps_architecture/test/util/logging/logging_test.dart. // Do not manually edit this file. @@ -11,6 +11,8 @@ import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors @@ -23,27 +25,28 @@ import 'package:mockito/mockito.dart' as _i1; /// See the documentation for Mockito's code generation for more information. class MockLog extends _i1.Mock implements _i2.Log { @override - void verbose( + void trace( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( - #verbose, + #trace, [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void debug( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -51,16 +54,17 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void info( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -68,16 +72,17 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void warning( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -85,16 +90,17 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void error( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -102,33 +108,35 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override - void v( + void t( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( - #v, + #t, [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void d( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -136,16 +144,17 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void i( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -153,16 +162,17 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void w( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -170,16 +180,17 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void e( String? message, { dynamic error, - StackTrace? trace, + StackTrace? stackTrace, }) => super.noSuchMethod( Invocation.method( @@ -187,11 +198,12 @@ class MockLog extends _i1.Mock implements _i2.Log { [message], { #error: error, - #trace: trace, + #stackTrace: stackTrace, }, ), returnValueForMissingStub: null, ); + @override void logNetworkError(_i2.NetworkError? error) => super.noSuchMethod( Invocation.method( @@ -200,6 +212,7 @@ class MockLog extends _i1.Mock implements _i2.Log { ), returnValueForMissingStub: null, ); + @override void logNetworkRequest(_i3.RequestOptions? request) => super.noSuchMethod( Invocation.method( @@ -208,6 +221,7 @@ class MockLog extends _i1.Mock implements _i2.Log { ), returnValueForMissingStub: null, ); + @override void logNetworkResponse(_i3.Response? response) => super.noSuchMethod( diff --git a/test/util/preferences/preferences_storage_test.mocks.dart b/test/util/preferences/preferences_storage_test.mocks.dart index 877edd6..05f0dca 100644 --- a/test/util/preferences/preferences_storage_test.mocks.dart +++ b/test/util/preferences/preferences_storage_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.2 from annotations +// Mocks generated by Mockito 5.4.4 from annotations // in icapps_architecture/test/util/preferences/preferences_storage_test.dart. // Do not manually edit this file. @@ -12,6 +12,8 @@ import 'package:shared_preferences/shared_preferences.dart' as _i2; // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors @@ -35,31 +37,37 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: {}, ) as Set); + @override Object? get(String? key) => (super.noSuchMethod(Invocation.method( #get, [key], )) as Object?); + @override bool? getBool(String? key) => (super.noSuchMethod(Invocation.method( #getBool, [key], )) as bool?); + @override int? getInt(String? key) => (super.noSuchMethod(Invocation.method( #getInt, [key], )) as int?); + @override double? getDouble(String? key) => (super.noSuchMethod(Invocation.method( #getDouble, [key], )) as double?); + @override String? getString(String? key) => (super.noSuchMethod(Invocation.method( #getString, [key], )) as String?); + @override bool containsKey(String? key) => (super.noSuchMethod( Invocation.method( @@ -68,12 +76,14 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: false, ) as bool); + @override List? getStringList(String? key) => (super.noSuchMethod(Invocation.method( #getStringList, [key], )) as List?); + @override _i3.Future setBool( String? key, @@ -89,6 +99,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future setInt( String? key, @@ -104,6 +115,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future setDouble( String? key, @@ -119,6 +131,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future setString( String? key, @@ -134,6 +147,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future setStringList( String? key, @@ -149,6 +163,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future remove(String? key) => (super.noSuchMethod( Invocation.method( @@ -157,6 +172,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future commit() => (super.noSuchMethod( Invocation.method( @@ -165,6 +181,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future clear() => (super.noSuchMethod( Invocation.method( @@ -173,6 +190,7 @@ class MockSharedPreferences extends _i1.Mock implements _i2.SharedPreferences { ), returnValue: _i3.Future.value(false), ) as _i3.Future); + @override _i3.Future reload() => (super.noSuchMethod( Invocation.method( From fa6bde730ed1a6591cceff8eab00d37a92cb20ef Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Mon, 12 Feb 2024 15:45:56 +0100 Subject: [PATCH 8/9] format --- lib/src/util/logging/logging.dart | 58 ++++++--- test/util/logging/logging_test.dart | 179 +++++++++++++++++++++------- 2 files changed, 172 insertions(+), 65 deletions(-) diff --git a/lib/src/util/logging/logging.dart b/lib/src/util/logging/logging.dart index 207a3f9..0a21715 100644 --- a/lib/src/util/logging/logging.dart +++ b/lib/src/util/logging/logging.dart @@ -32,15 +32,20 @@ abstract class Log { void error(String message, {dynamic error, StackTrace? stackTrace}); - void t(String message, {dynamic error, StackTrace? stackTrace}) => trace(message, error: error, stackTrace: stackTrace); + void t(String message, {dynamic error, StackTrace? stackTrace}) => + trace(message, error: error, stackTrace: stackTrace); - void d(String message, {dynamic error, StackTrace? stackTrace}) => debug(message, error: error, stackTrace: stackTrace); + void d(String message, {dynamic error, StackTrace? stackTrace}) => + debug(message, error: error, stackTrace: stackTrace); - void i(String message, {dynamic error, StackTrace? stackTrace}) => info(message, error: error, stackTrace: stackTrace); + void i(String message, {dynamic error, StackTrace? stackTrace}) => + info(message, error: error, stackTrace: stackTrace); - void w(String message, {dynamic error, StackTrace? stackTrace}) => warning(message, error: error, stackTrace: stackTrace); + void w(String message, {dynamic error, StackTrace? stackTrace}) => + warning(message, error: error, stackTrace: stackTrace); - void e(String message, {dynamic error, StackTrace? stackTrace}) => this.error(message, error: error, stackTrace: stackTrace); + void e(String message, {dynamic error, StackTrace? stackTrace}) => + this.error(message, error: error, stackTrace: stackTrace); void logNetworkError(NetworkError error); @@ -126,19 +131,24 @@ class LoggerLogImpl extends Log { LoggerLogImpl(this.logger, {required this.logNetworkInfo}); @override - void debug(String message, {dynamic error, StackTrace? stackTrace}) => logger.d(message, error: error, stackTrace: stackTrace); + void debug(String message, {dynamic error, StackTrace? stackTrace}) => + logger.d(message, error: error, stackTrace: stackTrace); @override - void error(String message, {error, StackTrace? stackTrace}) => logger.e(message, error: error, stackTrace: stackTrace); + void error(String message, {error, StackTrace? stackTrace}) => + logger.e(message, error: error, stackTrace: stackTrace); @override - void info(String message, {dynamic error, StackTrace? stackTrace}) => logger.i(message, error: error, stackTrace: stackTrace); + void info(String message, {dynamic error, StackTrace? stackTrace}) => + logger.i(message, error: error, stackTrace: stackTrace); @override - void trace(String message, {dynamic error, StackTrace? stackTrace}) => logger.t(message, error: error, stackTrace: stackTrace); + void trace(String message, {dynamic error, StackTrace? stackTrace}) => + logger.t(message, error: error, stackTrace: stackTrace); @override - void warning(String message, {dynamic error, StackTrace? stackTrace}) => logger.w(message, error: error, stackTrace: stackTrace); + void warning(String message, {dynamic error, StackTrace? stackTrace}) => + logger.w(message, error: error, stackTrace: stackTrace); @override void logNetworkError(NetworkError error) { @@ -157,7 +167,8 @@ class LoggerLogImpl extends Log { ..writeln('response.data | ${response.data}') ..writeln('response.headers | ${response.headers}'); } - message.writeln('<--------------- ${request.method} - url: ${request.uri} - status code: ${response?.statusCode ?? 'N/A'}'); + message.writeln( + '<--------------- ${request.method} - url: ${request.uri} - status code: ${response?.statusCode ?? 'N/A'}'); this.error(message.toString()); } @@ -170,7 +181,8 @@ class LoggerLogImpl extends Log { @override void logNetworkResponse(Response response) { if (!logNetworkInfo) return; - debug('<--------------- ${response.requestOptions.method} - url: ${response.requestOptions.uri} - status code: ${response.statusCode ?? 'N/A'}'); + debug( + '<--------------- ${response.requestOptions.method} - url: ${response.requestOptions.uri} - status code: ${response.statusCode ?? 'N/A'}'); } } @@ -225,26 +237,34 @@ class PrefixLogger extends Log { PrefixLogger(this._name, this._delegate); @override - void debug(String message, {error, StackTrace? stackTrace}) => _delegate.debug('[$_name] $message', error: error, stackTrace: stackTrace); + void debug(String message, {error, StackTrace? stackTrace}) => _delegate + .debug('[$_name] $message', error: error, stackTrace: stackTrace); @override - void error(String message, {Object? error, StackTrace? stackTrace}) => _delegate.error('[$_name] $message', error: error, stackTrace: stackTrace); + void error(String message, {Object? error, StackTrace? stackTrace}) => + _delegate.error('[$_name] $message', + error: error, stackTrace: stackTrace); @override - void info(String message, {error, StackTrace? stackTrace}) => _delegate.info('[$_name] $message', error: error, stackTrace: stackTrace); + void info(String message, {error, StackTrace? stackTrace}) => + _delegate.info('[$_name] $message', error: error, stackTrace: stackTrace); @override void logNetworkError(NetworkError error) => _delegate.logNetworkError(error); @override - void logNetworkRequest(RequestOptions request) => _delegate.logNetworkRequest(request); + void logNetworkRequest(RequestOptions request) => + _delegate.logNetworkRequest(request); @override - void logNetworkResponse(Response response) => _delegate.logNetworkResponse(response); + void logNetworkResponse(Response response) => + _delegate.logNetworkResponse(response); @override - void trace(String message, {error, StackTrace? stackTrace}) => _delegate.trace('[$_name] $message', error: error, stackTrace: stackTrace); + void trace(String message, {error, StackTrace? stackTrace}) => _delegate + .trace('[$_name] $message', error: error, stackTrace: stackTrace); @override - void warning(String message, {error, StackTrace? stackTrace}) => _delegate.warning('[$_name] $message', error: error, stackTrace: stackTrace); + void warning(String message, {error, StackTrace? stackTrace}) => _delegate + .warning('[$_name] $message', error: error, stackTrace: stackTrace); } diff --git a/test/util/logging/logging_test.dart b/test/util/logging/logging_test.dart index cff33f7..2d458f8 100644 --- a/test/util/logging/logging_test.dart +++ b/test/util/logging/logging_test.dart @@ -41,14 +41,18 @@ void main() { log.i('Test'); log.e('Test'); log.logNetworkRequest(RequestOptions(path: '/')); - log.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/'))); - log.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/')))); + log.logNetworkResponse( + Response(requestOptions: RequestOptions(path: '/'))); + log.logNetworkError(MockNetworkError( + DioException(requestOptions: RequestOptions(path: '/')))); verify(mock.trace(argThat(startsWith('[TestPrefix] ')))).called(1); verify(mock.debug(argThat(startsWith('[TestPrefix] ')))).called(1); verify(mock.info(argThat(startsWith('[TestPrefix] ')))).called(1); verify(mock.warning(argThat(startsWith('[TestPrefix] ')))).called(1); - verify(mock.error(argThat(startsWith('[TestPrefix] ')), stackTrace: anyNamed('stackTrace'), error: anyNamed('error'))).called(1); + verify(mock.error(argThat(startsWith('[TestPrefix] ')), + stackTrace: anyNamed('stackTrace'), error: anyNamed('error'))) + .called(1); verify(mock.logNetworkResponse(any)).called(1); verify(mock.logNetworkRequest(any)).called(1); verify(mock.logNetworkError(any)).called(1); @@ -61,14 +65,18 @@ void main() { test('Output logger does not split short items', () { final lines = []; final output = WrappingOutput((str) => lines.add(str)); - output.output(OutputEvent(LogEvent(Level.info, 'Short string'), ['Short string', 'Longer string that does not need to be split'])); - expect(lines, ['Short string', 'Longer string that does not need to be split']); + output.output(OutputEvent(LogEvent(Level.info, 'Short string'), + ['Short string', 'Longer string that does not need to be split'])); + expect(lines, + ['Short string', 'Longer string that does not need to be split']); }); test('Output logger does splits long items', () { - final inputString = base64Encode(List.generate(1000, (i) => i % 255)); + final inputString = + base64Encode(List.generate(1000, (i) => i % 255)); final lines = []; final output = WrappingOutput((str) => lines.add(str)); - output.output(OutputEvent(LogEvent(Level.info, 'Short string'), ['Short string', inputString])); + output.output(OutputEvent( + LogEvent(Level.info, 'Short string'), ['Short string', inputString])); expect(lines, [ 'Short string', 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZ', @@ -205,8 +213,10 @@ void testWithLogger() { staticLogger.warning('Warning message'); staticLogger.error('Error message'); staticLogger.logNetworkRequest(RequestOptions(path: '/')); - staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/'))); - staticLogger.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/')))); + staticLogger.logNetworkResponse( + Response(requestOptions: RequestOptions(path: '/'))); + staticLogger.logNetworkError(MockNetworkError( + DioException(requestOptions: RequestOptions(path: '/')))); }); test('Test logger methods default pretty', () { final buffer = MemoryOutput(); @@ -230,38 +240,66 @@ void testWithLogger() { staticLogger.d('Debug message'); staticLogger.i('Info message'); staticLogger.w('Warning message'); - staticLogger.e('Error message', error: ArgumentError(), stackTrace: StackTrace.current); + staticLogger.e('Error message', + error: ArgumentError(), stackTrace: StackTrace.current); final messages = buffer.buffer.toList(growable: false); - expect(messages[0].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+Trace message')); - expect(messages[1].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+🐛 Debug message')); - expect(messages[2].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+💡 Info message')); - expect(messages[3].lines.join(" "), matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⚠️ Warning message')); - expect(messages[4].lines[0], matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⛔ Error message')); - expect(messages[4].lines[1], matches('\\d+:\\d+:\\d+\\.\\d+\\s+Invalid argument\\(s\\)')); - expect(messages[4].lines[2], - matches('\\d+:\\d+:\\d+\\.\\d+\\s+#0 Declarer.test.. \\(package:test_api/src/backend/declarer.dart:\\d+:\\d+\\)')); - expect(messages[4].lines[3], matches('\\d+:\\d+:\\d+\\.\\d+\\s+#1 ')); + expect(messages[0].lines.join(" "), + matches(' \\d+:\\d+:\\d+\\.\\d+\\s+Trace message')); + expect(messages[1].lines.join(" "), + matches(' \\d+:\\d+:\\d+\\.\\d+\\s+🐛 Debug message')); + expect(messages[2].lines.join(" "), + matches(' \\d+:\\d+:\\d+\\.\\d+\\s+💡 Info message')); + expect(messages[3].lines.join(" "), + matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⚠️ Warning message')); + expect(messages[4].lines[0], + matches(' \\d+:\\d+:\\d+\\.\\d+\\s+⛔ Error message')); + expect(messages[4].lines[1], + matches('\\d+:\\d+:\\d+\\.\\d+\\s+Invalid argument\\(s\\)')); + expect( + messages[4].lines[2], + matches( + '\\d+:\\d+:\\d+\\.\\d+\\s+#0 Declarer.test.. \\(package:test_api/src/backend/declarer.dart:\\d+:\\d+\\)')); + expect(messages[4].lines[3], + matches('\\d+:\\d+:\\d+\\.\\d+\\s+#1 ')); expect( messages[4].lines[4], matches( '\\d+:\\d+:\\d+\\.\\d+\\s+#2 StackZoneSpecification._registerUnaryCallback. \\(package:stack_trace/src/stack_zone_specification.dart:\\d+:\\d+\\)')); - expect(messages[4].lines[5], matches('\\d+:\\d+:\\d+\\.\\d+\\s+#3 ')); + expect(messages[4].lines[5], + matches('\\d+:\\d+:\\d+\\.\\d+\\s+#3 ')); }); test('Test logger methods default pretty include method', () { final buffer = MemoryOutput(); LoggingFactory.resetWithLogger(LoggerLogImpl( Logger( - printer: OurPrettyPrinter(methodCount: 1, errorMethodCount: 5, stackTraceBeginIndex: 0, lineLength: 50, colors: false, printEmojis: true, printTime: false), + printer: OurPrettyPrinter( + methodCount: 1, + errorMethodCount: 5, + stackTraceBeginIndex: 0, + lineLength: 50, + colors: false, + printEmojis: true, + printTime: false), output: buffer, ), logNetworkInfo: false)); staticLogger.d('Debug message'); final messages = buffer.buffer.toList(growable: false); - expect(messages[0].lines[1], matches('#0 OurPrettyPrinter.log \\(package:icapps_architecture/src/util/logging/impl/LoggerPrinter.dart:\\d+:\\d+\\)')); + expect( + messages[0].lines[1], + matches( + '#0 OurPrettyPrinter.log \\(package:icapps_architecture/src/util/logging/impl/LoggerPrinter.dart:\\d+:\\d+\\)')); expect(messages[0].lines[0], ' 🐛 Debug message'); }); test('Test logger methods default json', () { - final lines = OurPrettyPrinter(methodCount: 0, errorMethodCount: 5, stackTraceBeginIndex: 1, lineLength: 50, colors: true, printEmojis: true, printTime: false) + final lines = OurPrettyPrinter( + methodCount: 0, + errorMethodCount: 5, + stackTraceBeginIndex: 1, + lineLength: 50, + colors: true, + printEmojis: true, + printTime: false) .log(LogEvent(Level.fatal, ['Some', 'body'])); expect(lines[0], '\x1B[38;5;199m 👾 [\x1B[0m'); @@ -270,25 +308,51 @@ void testWithLogger() { expect(lines[3], '\x1B[38;5;199m 👾 ]\x1B[0m'); }); test('Test logger methods default error color', () { - final lines = OurPrettyPrinter(methodCount: 0, errorMethodCount: 1, stackTraceBeginIndex: 0, lineLength: 50, colors: true, printEmojis: true, printTime: false) + final lines = OurPrettyPrinter( + methodCount: 0, + errorMethodCount: 1, + stackTraceBeginIndex: 0, + lineLength: 50, + colors: true, + printEmojis: true, + printTime: false) .log(LogEvent(Level.error, 'Error', error: ArgumentError())); - expect(lines[1], '\x1B[39m\x1B[48;5;196mInvalid argument(s)\x1B[0m\x1B[49m'); + expect( + lines[1], '\x1B[39m\x1B[48;5;196mInvalid argument(s)\x1B[0m\x1B[49m'); expect(lines[0], '\x1B[38;5;196m ⛔ Error\x1B[0m'); }); test('Test logger methods default error color fatal', () { - final lines = OurPrettyPrinter(methodCount: 0, errorMethodCount: 1, stackTraceBeginIndex: 0, lineLength: 50, colors: true, printEmojis: true, printTime: false) + final lines = OurPrettyPrinter( + methodCount: 0, + errorMethodCount: 1, + stackTraceBeginIndex: 0, + lineLength: 50, + colors: true, + printEmojis: true, + printTime: false) .log(LogEvent(Level.fatal, 'Fatal', error: ArgumentError())); - expect(lines[1], '\x1B[39m\x1B[48;5;199mInvalid argument(s)\x1B[0m\x1B[49m'); + expect( + lines[1], '\x1B[39m\x1B[48;5;199mInvalid argument(s)\x1B[0m\x1B[49m'); expect(lines[0], '\x1B[38;5;199m 👾 Fatal\x1B[0m'); }); test('Test logger methods default build stack trace', () { - final formatted = OurPrettyPrinter(methodCount: 0, errorMethodCount: 1, stackTraceBeginIndex: 0, lineLength: 50, colors: true, printEmojis: true, printTime: true) + final formatted = OurPrettyPrinter( + methodCount: 0, + errorMethodCount: 1, + stackTraceBeginIndex: 0, + lineLength: 50, + colors: true, + printEmojis: true, + printTime: true) .formatStackTrace( - StackTrace.fromString('#1 Logger.log (package:logger/src/logger.dart:115:29)\npackages/logger/src/printers/pretty_printer.dart 91:37\npackage:logger/lib'), 3); + StackTrace.fromString( + '#1 Logger.log (package:logger/src/logger.dart:115:29)\npackages/logger/src/printers/pretty_printer.dart 91:37\npackage:logger/lib'), + 3); - expect(formatted, '#0 packages/logger/src/printers/pretty_printer.dart 91:37\n#1 package:logger/lib'); + expect(formatted, + '#0 packages/logger/src/printers/pretty_printer.dart 91:37\n#1 package:logger/lib'); }); }); group('Test network logging', () { @@ -299,8 +363,10 @@ void testWithLogger() { onLog: (logLine) => buffer.add(logLine), )); staticLogger.logNetworkRequest(RequestOptions(path: '/')); - staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/'))); - staticLogger.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/')))); + staticLogger.logNetworkResponse( + Response(requestOptions: RequestOptions(path: '/'))); + staticLogger.logNetworkError(MockNetworkError( + DioException(requestOptions: RequestOptions(path: '/')))); expect(buffer.isEmpty, true); }); test('Test logger network enabled', () { @@ -310,31 +376,52 @@ void testWithLogger() { printTime: false, onLog: (logLine) => buffer.add(logLine), )); - staticLogger.logNetworkRequest(RequestOptions(path: '/', baseUrl: 'https://www.example.com')); - staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'))); - staticLogger.logNetworkResponse(Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), statusCode: 404)); - staticLogger.logNetworkError(MockNetworkError(DioException(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com')))); + staticLogger.logNetworkRequest( + RequestOptions(path: '/', baseUrl: 'https://www.example.com')); + staticLogger.logNetworkResponse(Response( + requestOptions: + RequestOptions(path: '/', baseUrl: 'https://www.example.com'))); + staticLogger.logNetworkResponse(Response( + requestOptions: + RequestOptions(path: '/', baseUrl: 'https://www.example.com'), + statusCode: 404)); + staticLogger.logNetworkError(MockNetworkError(DioException( + requestOptions: + RequestOptions(path: '/', baseUrl: 'https://www.example.com')))); staticLogger.logNetworkError(MockNetworkError(DioException( - requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), - response: Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'))))); + requestOptions: + RequestOptions(path: '/', baseUrl: 'https://www.example.com'), + response: Response( + requestOptions: RequestOptions( + path: '/', baseUrl: 'https://www.example.com'))))); staticLogger.logNetworkError(MockNetworkError(DioException( - requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), - response: Response(requestOptions: RequestOptions(path: '/', baseUrl: 'https://www.example.com'), statusCode: 404)))); + requestOptions: + RequestOptions(path: '/', baseUrl: 'https://www.example.com'), + response: Response( + requestOptions: + RequestOptions(path: '/', baseUrl: 'https://www.example.com'), + statusCode: 404)))); - expect(buffer[0], ' 🐛 ---------------> GET - url: https://www.example.com/'); - expect(buffer[1], ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: N/A'); - expect(buffer[2], ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: 404'); + expect(buffer[0], + ' 🐛 ---------------> GET - url: https://www.example.com/'); + expect(buffer[1], + ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: N/A'); + expect(buffer[2], + ' 🐛 <--------------- GET - url: https://www.example.com/ - status code: 404'); expect(buffer[3], ' ⛔ request | GET - url: https://www.example.com/'); expect(buffer[4], ' ⛔ message | '); - expect(buffer[5], ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); + expect(buffer[5], + ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); expect(buffer[6], ' ⛔ '); expect(buffer[7], ' ⛔ response.data | null'); expect(buffer[8], ' ⛔ response.headers | '); - expect(buffer[9], ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); + expect(buffer[9], + ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: N/A'); expect(buffer[10], ' ⛔ '); expect(buffer[11], ' ⛔ response.data | null'); expect(buffer[12], ' ⛔ response.headers | '); - expect(buffer[13], ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: 404'); + expect(buffer[13], + ' ⛔ <--------------- GET - url: https://www.example.com/ - status code: 404'); }); }); } From a1028b8961554d451d875d31993c84a3d9eed09a Mon Sep 17 00:00:00 2001 From: WilliamVerhaeghe Date: Mon, 12 Feb 2024 15:51:10 +0100 Subject: [PATCH 9/9] Fixed test --- test/util/logging/logging_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/util/logging/logging_test.dart b/test/util/logging/logging_test.dart index 2d458f8..9a929b4 100644 --- a/test/util/logging/logging_test.dart +++ b/test/util/logging/logging_test.dart @@ -264,7 +264,7 @@ void testWithLogger() { expect( messages[4].lines[4], matches( - '\\d+:\\d+:\\d+\\.\\d+\\s+#2 StackZoneSpecification._registerUnaryCallback. \\(package:stack_trace/src/stack_zone_specification.dart:\\d+:\\d+\\)')); + '\\d+:\\d+:\\d+\\.\\d+\\s+#2 Declarer.test. \\(package:test_api/src/backend/declarer.dart:\\d+:\\d+\\)')); expect(messages[4].lines[5], matches('\\d+:\\d+:\\d+\\.\\d+\\s+#3 ')); });