Skip to content

Commit

Permalink
[rust] re-enable cxx-integraion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea committed Nov 1, 2024
1 parent e928f0b commit fdb45d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 46 deletions.
50 changes: 26 additions & 24 deletions src/rust/cxx-integration-test/BUILD
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# load("//:build/kj_test.bzl", "kj_test")
# load("//:build/wd_rust_crate.bzl", "wd_rust_crate")
load("//:build/kj_test.bzl", "kj_test")
load("//:build/wd_rust_crate.bzl", "wd_rust_crate")

# wd_rust_crate(
# name = "cxx-integration-test",
# cxx_bridge_src = "lib.rs",
# test_deps = [
# "@crates_vendor//:nix",
# ],
# visibility = ["//visibility:public"],
# deps = [
# "//src/rust/cxx-integration",
# "@capnp-cpp//src/kj",
# "@crates_vendor//:tokio",
# "@crates_vendor//:tracing",
# ],
# )
wd_rust_crate(
name = "cxx-integration-test",
cxx_bridge_deps = [
"@capnp-cpp//src/kj",
],
cxx_bridge_src = "lib.rs",
test_deps = [
"@crates_vendor//:nix",
],
visibility = ["//visibility:public"],
deps = [
"//src/rust/cxx-integration",
"@crates_vendor//:tokio",
"@crates_vendor//:tracing",
],
)

# kj_test(
# src = "cxx-rust-integration-test.c++",
# deps = [
# ":cxx-integration-test",
# "//src/rust/cxx-integration",
# "@capnp-cpp//src/kj:kj-async",
# ],
# )
kj_test(
src = "cxx-rust-integration-test.c++",
deps = [
":cxx-integration-test",
"//src/rust/cxx-integration",
"@capnp-cpp//src/kj:kj-async",
],
)
33 changes: 11 additions & 22 deletions src/rust/cxx-integration-test/cxx-rust-integration-test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

namespace workerd::rust {

KJ_TEST("init cxx_integration") {
// this tests initializes cxx integration for the rest of the tests
rust::cxx_integration::init();
}

KJ_TEST("panic results in abort") {
// our panic hook doesn't change the behavior but prints additional
// information. still expected to abort.
KJ_EXPECT_SIGNAL(SIGABRT, rust::cxx_integration::trigger_panic("foobar"));
}

KJ_TEST("ok Result") { KJ_EXPECT(42 == rust::test::result_ok()); }

KJ_TEST("err Result") {
Expand All @@ -25,28 +36,6 @@ KJ_TEST("err Result") {
}
}

KJ_TEST("panic without hook results in exception") {
try {
rust::cxx_integration::trigger_panic("foobar");
KJ_UNREACHABLE;
} catch (::rust::Error e) {
// this is expected
KJ_EXPECT(e.what() == "panic in cxx_integration::ffi::trigger_panic: foobar"_kj);
}
}

KJ_TEST("panic with panic hook installed results in exception") {
rust::cxx_integration::init();

try {
rust::cxx_integration::trigger_panic("foobar");
KJ_UNREACHABLE;
} catch (::rust::Error e) {
// this is expected
KJ_EXPECT(e.what() == "panic in cxx_integration::ffi::trigger_panic: foobar"_kj);
}
}

KJ_TEST("test callback") {
rust::test::TestCallback callback = [](size_t a, size_t b) { return a + b; };
auto result = rust::test::call_callback(callback, 40, 2);
Expand Down

0 comments on commit fdb45d2

Please sign in to comment.