Skip to content

Commit 3083050

Browse files
liamappelbecommit-bot@chromium.org
authored andcommitted
[nnbd] Fix some IO strong mode tests
Fixes: standalone/io/directory_test standalone/io/file_test standalone/io/http_read_test/* standalone/io/http_reuse_server_port_test/* standalone/io/http_server_early_client_close_test/* standalone/io/regress_8828_test/* standalone/io/socket_cancel_connect_test/* standalone/io/socket_finalizer_test/* standalone/io/web_socket_typed_data_test/* Change-Id: I46b7d8691b66222b61b72bfe4d29ce81fadf511f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143182 Commit-Queue: Liam Appelbe <[email protected]> Reviewed-by: Jonas Termansen <[email protected]> Reviewed-by: Régis Crelier <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent 5cd6606 commit 3083050

9 files changed

+26
-22
lines changed

tests/standalone/io/directory_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ class DirectoryTest {
196196
}
197197
}
198198

199-
long.delete().catchError(onError);
200-
long.delete(recursive: true).catchError(onError);
199+
Future<void>.value(long.delete()).catchError(onError);
200+
Future<void>.value(long.delete(recursive: true)).catchError(onError);
201201
});
202202
});
203203
}
@@ -453,7 +453,7 @@ class DirectoryTest {
453453
class NestedTempDirectoryTest {
454454
List<Directory> createdDirectories;
455455

456-
NestedTempDirectoryTest.run() : createdDirectories = new List<Directory>() {
456+
NestedTempDirectoryTest.run() : createdDirectories = <Directory>[] {
457457
Directory.systemTemp.createTemp('dart_directory').then(createPhaseCallback);
458458
}
459459

@@ -511,7 +511,7 @@ testCreateTempError() {
511511

512512
asyncStart();
513513
var future = new Directory(location).createTemp('dart_tempdir');
514-
future.catchError((_) => asyncEnd());
514+
Future<Directory?>.value(future).catchError((_) => asyncEnd());
515515
}
516516

517517
testCreateExistingSync() {

tests/standalone/io/file_test.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class FileTest {
7474
File file = new File(filename);
7575
Expect.isTrue('$file'.contains(file.path));
7676
var subscription;
77-
List<int> buffer = new List<int>();
77+
List<int> buffer = <int>[];
7878
subscription = file.openRead().listen((d) {
7979
buffer.addAll(d);
8080
if (buffer.length >= 12) {
@@ -105,7 +105,7 @@ class FileTest {
105105
int bytesRead;
106106

107107
var file1 = new File(inFilename);
108-
List<int> buffer = new List<int>();
108+
List<int> buffer = <int>[];
109109
file1.openRead().listen((d) {
110110
buffer.addAll(d);
111111
}, onDone: () {
@@ -118,7 +118,7 @@ class FileTest {
118118
output.flush().then((_) => output.close());
119119
output.done.then((_) {
120120
// Now read the contents of the file just written.
121-
List<int> buffer2 = new List<int>();
121+
List<int> buffer2 = <int>[];
122122
new File(outFilename).openRead().listen((d) {
123123
buffer2.addAll(d);
124124
}, onDone: () {
@@ -819,11 +819,11 @@ class FileTest {
819819
}
820820

821821
read(0, 3, 3, [1, 2, 3]);
822-
read(0, 2, 2, [1, 2, null]);
823-
read(1, 2, 1, [null, 1, null]);
824-
read(1, 3, 2, [null, 1, 2]);
825-
read(2, 3, 1, [null, null, 1]);
826-
read(0, 0, 0, [null, null, null]);
822+
read(0, 2, 2, [1, 2, -1]);
823+
read(1, 2, 1, [-1, 1, -1]);
824+
read(1, 3, 2, [-1, 1, 2]);
825+
read(2, 3, 1, [-1, -1, 1]);
826+
read(0, 0, 0, [-1, -1, -1]);
827827

828828
openedFile.closeSync();
829829
}
@@ -1296,7 +1296,7 @@ class FileTest {
12961296
int done = 0;
12971297
bool error = false;
12981298
void getLength() {
1299-
file.length().catchError((e) {
1299+
Future<int?>.value(file.length()).catchError((e) {
13001300
error = true;
13011301
}).whenComplete(() {
13021302
if (++done == 2) {
@@ -1564,9 +1564,12 @@ class FileTest {
15641564
.then((_) => lift(Expect.isFalse)(newfile.exists()))
15651565
.then((_) {
15661566
if (Platform.operatingSystem != "windows") {
1567-
new Link(source).create(dest).then((_) => file.rename("xxx")).then((_) {
1567+
Future<File?>.value(new Link(source)
1568+
.create(dest)
1569+
.then((_) => file.rename("xxx"))
1570+
.then((_) {
15681571
throw "Rename of broken link succeeded";
1569-
}).catchError((e) {
1572+
})).catchError((e) {
15701573
Expect.isTrue(e is FileSystemException);
15711574
asyncTestDone("testRename$targetExists");
15721575
});

tests/standalone/io/http_read_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void testRead(bool chunkedEncoding) {
187187
return request.close();
188188
}).then((response) {
189189
Expect.equals(HttpStatus.ok, response.statusCode);
190-
List<int> body = new List<int>();
190+
List<int> body = <int>[];
191191
response.listen(body.addAll, onDone: () {
192192
Expect.equals(data, new String.fromCharCodes(body));
193193
count++;

tests/standalone/io/http_reuse_server_port_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void testReusePort() {
4949
asyncStart();
5050
runServer(0, 10, true).then((int port) {
5151
// Stress test the port reusing it 10 times.
52-
Future.forEach(new List(10), (_) {
52+
Future.forEach(List.filled(10, null), (_) {
5353
return runServer(port, 10, true);
5454
}).then((_) {
5555
asyncEnd();
@@ -61,7 +61,7 @@ void testUncleanReusePort() {
6161
asyncStart();
6262
runServer(0, 10, false).then((int port) {
6363
// Stress test the port reusing it 10 times.
64-
Future.forEach(new List(10), (_) {
64+
Future.forEach(List.filled(10, null), (_) {
6565
return runServer(port, 10, false);
6666
}).then((_) {
6767
asyncEnd();

tests/standalone/io/http_server_early_client_close_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class EarlyCloseTest {
7575
}
7676

7777
void testEarlyClose1() {
78-
List<EarlyCloseTest> tests = new List<EarlyCloseTest>();
78+
List<EarlyCloseTest> tests = <EarlyCloseTest>[];
7979
void add(Object data, [String? exception, bool expectRequest = false]) {
8080
tests.add(new EarlyCloseTest(data, exception, expectRequest));
8181
}

tests/standalone/io/regress_8828_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void main() {
2424
client.get("127.0.0.1", server.port, "/").then((HttpClientRequest request) {
2525
return request.close();
2626
}).then((HttpClientResponse response) {
27-
List<int> body = new List();
27+
List<int> body = [];
2828
response.listen(body.addAll, onDone: () {
2929
Expect.equals(
3030
"first line\nsecond line\n", new String.fromCharCodes(body));

tests/standalone/io/socket_cancel_connect_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void main() {
1919
Socket.startConnect("8.8.8.7", 80).then((task) {
2020
task.socket.timeout(timeout, onTimeout: () {
2121
task.cancel();
22+
return task.socket;
2223
});
2324
task.socket.then((socket) {
2425
Expect.fail("Unexpected connection made.");

tests/standalone/io/socket_finalizer_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ main() async {
4848
}
4949

5050
@pragma('vm:never-inline')
51-
produceGarbage() => all.add(List(1024));
51+
produceGarbage() => all.add(List.filled(1024, null));
5252

5353
final all = [];

tests/standalone/io/web_socket_typed_data_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void testOutOfRangeServer({bool compression: false}) {
200200
webSocket.listen((message) => Expect.fail("No message expected"),
201201
onDone: () => completer.complete(true),
202202
onError: (e) => completer.completeError(e));
203-
webSocket.add(new List()..add(i));
203+
webSocket.add([i]);
204204
});
205205
return completer.future;
206206
}

0 commit comments

Comments
 (0)