Skip to content

Commit

Permalink
[rust] re-enable cxx-integraion tests (#3041)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea authored Nov 1, 2024
1 parent b46b62c commit 3e18d19
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 48 deletions.
26 changes: 0 additions & 26 deletions src/rust/cxx-integration-test/BUILD

This file was deleted.

29 changes: 29 additions & 0 deletions src/rust/cxx-integration-test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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_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",
"//deps/rust:runtime",
"//src/rust/cxx-integration",
"@capnp-cpp//src/kj:kj-async",
],
)
31 changes: 9 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,15 @@

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") {
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 +34,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
File renamed without changes.

0 comments on commit 3e18d19

Please sign in to comment.