Skip to content
File

Blob: src/workerd/util/test-test.c++

967 bytes
1// Copyright (c) 2024 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5#include "test.h"
6 
7namespace workerd {
8namespace {
9 
10KJ_TEST("can check thrown exception type and message") {
11 
12 WD_EXPECT_THROW(KJ_EXCEPTION(DISCONNECTED, "foo"),
13 kj::throwRecoverableException(KJ_EXCEPTION(DISCONNECTED, "foo")));
14 
15 {
16 KJ_EXPECT_LOG(ERROR, "exception description didn't match");
17 
18 WD_EXPECT_THROW(KJ_EXCEPTION(DISCONNECTED, "bar"),
19 kj::throwRecoverableException(KJ_EXCEPTION(DISCONNECTED, "foo")));
20 }
21 
22 {
23 KJ_EXPECT_LOG(ERROR, "code threw wrong exception type");
24 
25 WD_EXPECT_THROW(KJ_EXCEPTION(UNIMPLEMENTED, "foo"),
26 kj::throwRecoverableException(KJ_EXCEPTION(DISCONNECTED, "foo")));
27 }
28 
29 {
30 KJ_EXPECT_LOG(ERROR, "code did not throw");
31 
32 WD_EXPECT_THROW(KJ_EXCEPTION(DISCONNECTED, "foo"), {});
33 }
34}
35 
36} // namespace
37} // namespace workerd