From 953c7876baa15fcacd7b1c5c575a502c8aeb6032 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Mon, 8 Jun 2020 12:33:31 -0700 Subject: [PATCH] fix nnbd tests to run with strong null safety (#116) * fix nnbd tests to run with strong null safety * update travis config * fix analyzer issues --- .travis.yml | 31 +++++++++++++++----- lib/src/lazy_stream.dart | 2 +- lib/src/result/result.dart | 2 +- lib/src/single_subscription_transformer.dart | 4 +-- test/result/result_test.dart | 8 ++--- test/utils.dart | 8 ++--- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6fb2f8d..e2acfa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,33 @@ language: dart dart: - - dev - - 2.2.0 + - be/raw/latest -dart_task: - - test: --platform vm - - test: --platform chrome - - dartanalyzer - - dartfmt +jobs: + include: + - stage: analyze_and_format + name: "Analyzer" + dart: be/raw/latest + os: linux + script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos . + - stage: analyze_and_format + name: "Format" + dart: be/raw/latest + os: linux + script: dartfmt -n --set-exit-if-changed . + - stage: test + name: "Vm Tests" + dart: be/raw/latest + os: linux + script: pub run --enable-experiment=non-nullable test -p vm + +stages: + - analyze_and_format + - test # Only building master means that we don't run two builds for each pull request. branches: - only: [master] + only: [master, null_safety] cache: directories: diff --git a/lib/src/lazy_stream.dart b/lib/src/lazy_stream.dart index a253ba8..e6779ee 100644 --- a/lib/src/lazy_stream.dart +++ b/lib/src/lazy_stream.dart @@ -41,7 +41,7 @@ class LazyStream extends Stream { if (result is Future>) { stream = StreamCompleter.fromFuture(result); } else { - stream = result as Stream; + stream = result; } return stream.listen(onData, diff --git a/lib/src/result/result.dart b/lib/src/result/result.dart index 4a43dbd..5f93b55 100644 --- a/lib/src/result/result.dart +++ b/lib/src/result/result.dart @@ -112,7 +112,7 @@ abstract class Result { } }); } else { - results.add(Result.value(element as T)); + results.add(Result.value(element)); } } if (pending == 0) { diff --git a/lib/src/single_subscription_transformer.dart b/lib/src/single_subscription_transformer.dart index e9bdb32..2e056b2 100644 --- a/lib/src/single_subscription_transformer.dart +++ b/lib/src/single_subscription_transformer.dart @@ -11,7 +11,7 @@ import 'dart:async'; /// listening to a stream as soon as it's bound. /// /// This also casts the source stream's events to type `T`. If the cast fails, -/// the result stream will emit a [CastError]. This behavior is deprecated, and +/// the result stream will emit a [TypeError]. This behavior is deprecated, and /// should not be relied upon. class SingleSubscriptionTransformer extends StreamTransformerBase { const SingleSubscriptionTransformer(); @@ -26,7 +26,7 @@ class SingleSubscriptionTransformer extends StreamTransformerBase { // type parameter and avoid this conversion. try { controller.add(value as T); - } on CastError catch (error, stackTrace) { + } on TypeError catch (error, stackTrace) { controller.addError(error, stackTrace); } }, onError: controller.addError, onDone: controller.close); diff --git a/test/result/result_test.dart b/test/result/result_test.dart index f0a32e8..154785b 100644 --- a/test/result/result_test.dart +++ b/test/result/result_test.dart @@ -72,7 +72,7 @@ void main() { var c = Completer(); c.future.then((bool v) { fail('Unexpected value $v'); - }, onError: expectAsync2((e, s) { + }).then((_) {}, onError: expectAsync2((e, s) { expect(e, equals('BAD')); expect(s, same(stack)); })); @@ -109,7 +109,7 @@ void main() { Result result = ErrorResult('BAD', stack); result.asFuture.then((bool v) { fail('Unexpected value $v'); - }, onError: expectAsync2((e, s) { + }).then((_) {}, onError: expectAsync2((e, s) { expect(e, equals('BAD')); expect(s, same(stack)); })); @@ -154,7 +154,7 @@ void main() { var future = Future>.value(Result.error('BAD', stack)); Result.release(future).then((v) { fail('Unexpected value: $v'); - }, onError: expectAsync2((e, s) { + }).then((_) {}, onError: expectAsync2((e, s) { expect(e, equals('BAD')); expect(s, same(stack)); })); @@ -165,7 +165,7 @@ void main() { var future = Future>.error('BAD', stack); Result.release(future).then((v) { fail('Unexpected value: $v'); - }, onError: expectAsync2((e, s) { + }).then((_) {}, onError: expectAsync2((e, s) { expect(e, equals('BAD')); expect(s, same(stack)); })); diff --git a/test/utils.dart b/test/utils.dart index 0085ce2..4cc743e 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -37,11 +37,11 @@ Matcher throwsZoned(matcher) => predicate((void Function() callback) { }); /// A matcher that runs a callback in its own zone and asserts that that zone -/// emits a [CastError]. -final throwsZonedCastError = throwsZoned(TypeMatcher()); +/// emits a [TypeError]. +final throwsZonedCastError = throwsZoned(TypeMatcher()); -/// A matcher that matches a callback or future that throws a [CastError]. -final throwsCastError = throwsA(TypeMatcher()); +/// A matcher that matches a callback or future that throws a [TypeError]. +final throwsCastError = throwsA(TypeMatcher()); /// A badly behaved stream which throws if it's ever listened to. ///