-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2933. Add tests for Stream.error
and Stream.value
constructors.
#2934
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@lrhn, it would be great if you could take a look as well.
/// This stream emits a single error event of `error` and `stackTrace` and then | ||
/// completes with a done event. | ||
/// | ||
/// @description Checks that if `stackTrace` is specified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps?:
/// @description Checks that if `stackTrace` is specified. | |
/// @description Checks that if `stackTrace` is specified it is provided | |
/// if and when a `catch` clause is executed to catch the error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My normal phrasing is that "provided" is used for being given as an argument, and I'd use "available in"/"part of" the emitted event to describe where it comes out again.
/// This stream emits a single error event of `error` and `stackTrace` and then | ||
/// completes with a done event. | ||
/// | ||
/// @description Checks that `Stream.error()` constructor creates a stream which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// @description Checks that `Stream.error()` constructor creates a stream which | |
/// @description Checks that the `Stream.error()` constructor creates a stream which |
/// This stream emits a single data event of value and then closes with a done | ||
/// event. | ||
/// | ||
/// @description Checks that `Stream.value()` constructor creates a stream which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// @description Checks that `Stream.value()` constructor creates a stream which | |
/// @description Checks that the `Stream.value()` constructor creates a stream which |
/// This stream emits a single data event of value and then closes with a done | ||
/// event. | ||
/// | ||
/// @description Checks that `Stream.value()` constructor creates a stream which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// @description Checks that `Stream.value()` constructor creates a stream which | |
/// @description Checks that the `Stream.value()` constructor creates a stream which |
asyncStart(); | ||
Stream stream = Stream.value("Stream.value"); | ||
stream.listen((v) { | ||
Expect.equals("Stream.value", v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add a side effect (++counter
) and check it in onDone
, in order to see that the data event does get posted?
Yes, it does look like LibTest/async/Stream/Stream.value_A01_t01.dart will test this already, but it seems reasonable to check it here as well, because it's non-trivial to see when looking at this test that there is another test which is indeed testing that behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, if behavior differs depending on whether you provide an onDone
handler, the two tests might not agree.)
/// This stream emits a single error event of `error` and `stackTrace` and then | ||
/// completes with a done event. | ||
/// | ||
/// @description Checks that if `stackTrace` is specified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My normal phrasing is that "provided" is used for being given as an argument, and I'd use "available in"/"part of" the emitted event to describe where it comes out again.
var v = await stream.first; | ||
Expect.fail("Unexpected event $v"); | ||
} catch (e, st) { | ||
Expect.equals(stackTrace, st); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't assume that stack traces preserve identity.
I'd do Expect.equals("My StackTrace", st.toString());
.
(It's probably preserved here, but it isn't necessarily by Error.throwWithStackTrace
because that goes through the platform throw. And we don't promise to not use Error.throwWithStackTrace
internally in Stream.error
.)
stream.listen((v) { | ||
Expect.fail("Unexpected event $v"); | ||
}, onError: (e) { | ||
Expect.equals("Stream.error", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could count onError invocations here, to check that it's not called twice.
var onErrors = 0;
...
onError: (e) {
onErrors++;
...
}, onDone: () {
Expect.equals(onErrors, 1);
...
});
asyncStart(); | ||
Stream stream = Stream.value("Stream.value"); | ||
stream.listen((v) { | ||
Expect.equals("Stream.value", v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also, if behavior differs depending on whether you provide an onDone
handler, the two tests might not agree.)
Thank you! Updated. PTAL. |
No description provided.