From a3b36d0b7be50338751d421cf3c3813f4475f1c5 Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Thu, 10 Jan 2019 20:44:21 -0700 Subject: [PATCH 1/3] fix reporter runtime error in Dart 2.1.0 --- lib/src/reporter.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/reporter.dart b/lib/src/reporter.dart index 44ab2e85..3f2ffe02 100644 --- a/lib/src/reporter.dart +++ b/lib/src/reporter.dart @@ -93,7 +93,10 @@ class Reporter { color && message.isNotEmpty ? pen(message) : message; void _log(IOSink sink, String message, {bool shout: false}) { - if (quiet && !shout) return; + // This may look like a strange conditional, but please leave it. + // Somehow when using the tearoff `reporter.log` the `quiet` variable + // is null, which causes a runtime error when running tests in Dart 2.1.0 + if (quiet == true && shout != true) return; sink.writeln(message); } } From b10dabadb2c7781b8c0bee5efeefc700be1e1cfe Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Fri, 11 Jan 2019 14:05:33 -0700 Subject: [PATCH 2/3] Don't allow nulls by: - default constructor values - extra null checks --- lib/src/reporter.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/src/reporter.dart b/lib/src/reporter.dart index 3f2ffe02..f535c800 100644 --- a/lib/src/reporter.dart +++ b/lib/src/reporter.dart @@ -30,7 +30,11 @@ class Reporter { bool color = true; bool quiet = false; - Reporter({bool this.color, bool this.quiet}); + Reporter({this.color: true, this.quiet: false}) { + // Do an additional check here to make sure nulls were not passed + color ??= true; + quiet ??= false; + } String colorBlue(String message) => _color(_blue, message); @@ -93,10 +97,11 @@ class Reporter { color && message.isNotEmpty ? pen(message) : message; void _log(IOSink sink, String message, {bool shout: false}) { - // This may look like a strange conditional, but please leave it. - // Somehow when using the tearoff `reporter.log` the `quiet` variable - // is null, which causes a runtime error when running tests in Dart 2.1.0 - if (quiet == true && shout != true) return; + // Ensure that even if quiet or shout are null, the conditional + // will result in a boolean + if (quiet == true && shout != true) { + return; + } sink.writeln(message); } } From 9732d3780fb20b0c95d2f5778e53eadb741f34e7 Mon Sep 17 00:00:00 2001 From: Rob Becker Date: Fri, 11 Jan 2019 16:21:09 -0700 Subject: [PATCH 3/3] prevent people from setting quiet,color to null --- lib/src/reporter.dart | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/src/reporter.dart b/lib/src/reporter.dart index f535c800..ee3a71bd 100644 --- a/lib/src/reporter.dart +++ b/lib/src/reporter.dart @@ -27,22 +27,27 @@ final AnsiPen _red = new AnsiPen()..red(); final AnsiPen _yellow = new AnsiPen()..yellow(); class Reporter { - bool color = true; - bool quiet = false; + bool _color; + bool _quiet; - Reporter({this.color: true, this.quiet: false}) { - // Do an additional check here to make sure nulls were not passed - color ??= true; - quiet ??= false; + Reporter({color: true, quiet: false}) { + this.color = color; + this.quiet = quiet; } - String colorBlue(String message) => _color(_blue, message); + bool get color => _color; + bool get quiet => _quiet; - String colorGreen(String message) => _color(_green, message); + set color(bool b) => _color = b ?? true; + set quiet(bool b) => _quiet = b ?? false; - String colorRed(String message) => _color(_red, message); + String colorBlue(String message) => _colorMessage(_blue, message); - String colorYellow(String message) => _color(_yellow, message); + String colorGreen(String message) => _colorMessage(_green, message); + + String colorRed(String message) => _colorMessage(_red, message); + + String colorYellow(String message) => _colorMessage(_yellow, message); void log(String message, {bool shout: false}) { _log(stdout, message, shout: shout); @@ -93,15 +98,11 @@ class Reporter { _log(stderr, colorYellow(message), shout: shout); } - String _color(AnsiPen pen, String message) => + String _colorMessage(AnsiPen pen, String message) => color && message.isNotEmpty ? pen(message) : message; void _log(IOSink sink, String message, {bool shout: false}) { - // Ensure that even if quiet or shout are null, the conditional - // will result in a boolean - if (quiet == true && shout != true) { - return; - } + if (quiet && !shout) return; sink.writeln(message); } }