blob: 97d4f5797817148cea490558b4406ffd78780ae2 [file] [log] [blame]
// Copyright (c) 2018, 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.
// @dart = 2.9
/// @assertion void writeln([Object obj = ""])
/// Converts obj to a String by invoking Object.toString and writes the result to
/// this, followed by a newline.
///
/// This operation is non-blocking. See flush or done for how to get any errors
/// generated by this call.
/// @description Checks that any errors generated by this call can be caught
/// @author sgrekhov@unipro.ru
import "dart:io";
import "../../../Utils/expect.dart";
class C {
String toString() {
if (1 + 1 == 2) {
throw new Exception("An exception");
}
return "This is C";
}
}
var localhost = InternetAddress.loopbackIPv4.address;
test(String method) async {
asyncStart();
C c = new C();
HttpServer server = await HttpServer.bind(localhost, 0);
server.listen((HttpRequest request) {
});
HttpClient client = new HttpClient();
client.open(method, localhost, server.port, "")
.then((HttpClientRequest request) {
request.contentLength = c.toString().length;
request.writeln(c);
return request.close();
}).then((HttpClientResponse response) {
Expect.fail("Error expected");
}, onError: (_) {
client.close(force: true);
server.close();
asyncEnd();
});
}
main() {
test("get");
test("head");
test("delete");
test("put");
test("post");
test("patch");
}