From 5309d648d5957f76ade8d83d616e654654924436 Mon Sep 17 00:00:00 2001 From: zach Date: Thu, 21 Mar 2024 20:46:40 -0700 Subject: [PATCH] cleanup: update rust tests --- .github/workflows/rust.yml | 6 +++--- Cargo.toml | 4 ++++ Makefile | 2 +- src/tests/mod.rs => examples/rust.rs | 32 +++++++++------------------- src/lib.rs | 4 ---- 5 files changed, 18 insertions(+), 30 deletions(-) rename src/tests/mod.rs => examples/rust.rs (85%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 31b9777..fa8d37a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -47,16 +47,16 @@ jobs: crate: mdbook - name: Build - run: opam exec -- cargo build --tests --features=link + run: opam exec -- cargo build --example rust --features=link - name: Build build run: opam exec -- cargo build --package ocaml-build --features=dune - name: Run Rust tests - run: opam exec -- cargo test --features=link -- --test-threads=1 + run: opam exec -- cargo run --example rust --features=link - name: Check mdbook run: mdbook test doc -L ./target/debug/deps - name: Test `no_std` - run: opam exec -- cargo build --tests --features=no-std + run: opam exec -- cargo build --example rust --features=no-std,link diff --git a/Cargo.toml b/Cargo.toml index aa4f2cc..00f37cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,3 +43,7 @@ members = [ [dev-dependencies] serial_test = "3.0.0" + +[[example]] +name = "rust" +required-features = ["link"] diff --git a/Makefile b/Makefile index 44f58da..332c94b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ test: test-rust test-ocaml test-rust: - @cargo test --features=link -- --test-threads=1 + @cargo run --example rust --features=link test-ocaml: @dune clean --root=test diff --git a/src/tests/mod.rs b/examples/rust.rs similarity index 85% rename from src/tests/mod.rs rename to examples/rust.rs index 406075c..1de4b3a 100644 --- a/src/tests/mod.rs +++ b/examples/rust.rs @@ -1,14 +1,7 @@ -use crate as ocaml; +use ocaml::{Error, FromValue, ToValue, Value}; -use crate::{Error, FromValue, ToValue, Value}; - -#[cfg(test)] -use serial_test::serial; - -#[test] -#[serial] fn test_basic_array() -> Result<(), Error> { - ocaml::runtime::init_persistent(); + ocaml::runtime::init(); let gc = unsafe { ocaml::Runtime::recover_handle() }; unsafe { let mut a: ocaml::Array<&str> = ocaml::Array::alloc(2); @@ -16,17 +9,12 @@ fn test_basic_array() -> Result<(), Error> { a.set(gc, 1, &"123")?; let b: Vec<&str> = FromValue::from_value(a.to_value(gc)); assert!(b.as_slice() == &["testing", "123"]); - unsafe { - ocaml::sys::caml_enter_blocking_section(); - } Ok(()) } } -#[test] -#[serial] fn test_basic_list() { - ocaml::runtime::init_persistent(); + ocaml::runtime::init(); let gc = unsafe { ocaml::Runtime::recover_handle() }; let mut list = ocaml::List::empty(); let a = 3i64.to_value(gc); @@ -50,8 +38,6 @@ fn test_basic_list() { } } -#[test] -#[serial] fn test_int() { ocaml::runtime::init_persistent(); let gc = unsafe { ocaml::Runtime::recover_handle() }; @@ -78,13 +64,8 @@ pub fn make_tuple(a: Value, b: Value) -> (Value, Value) { (a, b) } -#[test] -#[serial] fn test_tuple_of_tuples() { ocaml::runtime::init_persistent(); - unsafe { - ocaml::sys::caml_leave_blocking_section(); - } let gc = unsafe { ocaml::Runtime::recover_handle() }; let x = (1f64, 2f64, 3f64, 4f64, 5f64, 6f64, 7f64, 8f64, 9f64).to_value(gc); @@ -105,3 +86,10 @@ fn test_tuple_of_tuples() { assert!(h == k); assert!(i == j); } + +fn main() { + test_basic_array().unwrap(); + test_basic_list(); + test_int(); + test_tuple_of_tuples(); +} diff --git a/src/lib.rs b/src/lib.rs index 39d6bbd..509f3b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -178,10 +178,6 @@ pub fn ocamlopt() -> std::process::Command { std::process::Command::new(sys::COMPILER) } -#[cfg(feature = "link")] -#[cfg(test)] -mod tests; - /// OCaml runtime handle pub struct Runtime { _private: (),