Files
sdk/tests/lib/async/stream_state_test.dart
Lasse R.H. Nielsen f8086c81ae Collect all test-related files in package:expect.
Collects files from `package:async_helper` and `tests/language`
that are generally useful, so that all test-related helpers are
in `package:expect`.

Moves the two libraries from `package:async_helper` into `package:expect`,
and the `tests/language/static_type_helper.dart` file too.

Deprecates `async_minitest.dart`, to follow `minitest.dart`,
expecting the Flutter use of it to have been fixed to not break
on deprecation (I believe Flutter no longer breaks builds on deprecations at all).

Patch 1 is the actual change.
Patch 2+4+8 is changing all existing references to the files.
Patch 6 ignores deprecation in files still using `async_minitest.dart`.

3+5+7+9 are updating this text to make the numbers match.
Then it's just test-expectations and small tweaks from there.

Change-Id: I1b665135b5fef9b9a0c3b340ffe9daf874d0174c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373120
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-10-11 16:53:52 +00:00

206 lines
5.0 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test the event/callback protocol of the stream implementations.
library stream_state_test;
import 'package:expect/legacy/async_minitest.dart'; // ignore: deprecated_member_use
import 'stream_state_helper.dart';
const ms5 = const Duration(milliseconds: 5);
main() {
mainTest(sync: true, asBroadcast: false);
mainTest(sync: true, asBroadcast: true);
mainTest(sync: false, asBroadcast: false);
mainTest(sync: false, asBroadcast: true);
}
void terminateWithDone(t, asBroadcast) {
if (asBroadcast) {
t
..expectCancel()
..expectDone()
..expectBroadcastCancel((_) => t.terminate());
} else {
t
..expectCancel()
..expectDone(t.terminate);
}
}
mainTest({required bool sync, required bool asBroadcast}) {
var p = (sync ? "S" : "AS") + (asBroadcast ? "BC" : "SC");
test("$p-sub-data-done", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectData(42);
terminateWithDone(t, asBroadcast);
t
..listen()
..add(42)
..close();
});
test("$p-data-done-sub-sync", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectData(42);
terminateWithDone(t, asBroadcast);
t
..add(42)
..close()
..listen();
});
test("$p-data-done-sub-async", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectData(42);
terminateWithDone(t, asBroadcast);
t
..add(42)
..close()
..listen();
});
test("$p-sub-data/pause+resume-done", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectData(42, () {
t.pause();
t.resume();
t.close();
});
terminateWithDone(t, asBroadcast);
t
..listen()
..add(42);
});
test("$p-sub-data-unsubonerror", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
if (asBroadcast) {
t
..expectListen()
..expectBroadcastListen()
..expectData(42)
..expectError("bad")
..expectBroadcastCancel()
..expectCancel(t.terminate);
} else {
t
..expectListen()
..expectData(42)
..expectCancel()
..expectError("bad", t.terminate);
}
t
..listen(cancelOnError: true)
..add(42)
..error("bad")
..add(43)
..close();
});
test("$p-sub-data-no-unsubonerror", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectData(42)
..expectError("bad")
..expectData(43);
terminateWithDone(t, asBroadcast);
t
..listen(cancelOnError: false)
..add(42)
..error("bad")
..add(43)
..close();
});
test("$p-pause-resume-during-event", () {
var t = asBroadcast
? new StreamProtocolTest.broadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectData(42, () {
t.pause();
t.resume();
});
if (!asBroadcast && !sync) {
t..expectPause();
}
if (asBroadcast && sync) {
t
..expectDone()
..expectCancel(t.terminate);
} else {
t
..expectCancel()
..expectDone(t.terminate);
}
t
..listen()
..add(42)
..close();
});
test("$p-cancel-on-data", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectData(42, t.cancel)
..expectBroadcastCancelOpt()
..expectCancel(t.terminate);
t
..listen(cancelOnError: false)
..add(42)
..close();
});
test("$p-cancel-on-error", () {
var t = asBroadcast
? new StreamProtocolTest.asBroadcast(sync: sync)
: new StreamProtocolTest(sync: sync);
t
..expectListen()
..expectBroadcastListenOpt()
..expectError(42, t.cancel)
..expectBroadcastCancelOpt()
..expectCancel(t.terminate);
t
..listen(cancelOnError: false)
..error(42)
..close();
});
}