Skip to content

Commit 5309d64

Browse files
committed
cleanup: update rust tests
1 parent 2cea9bc commit 5309d64

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

.github/workflows/rust.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ jobs:
4747
crate: mdbook
4848

4949
- name: Build
50-
run: opam exec -- cargo build --tests --features=link
50+
run: opam exec -- cargo build --example rust --features=link
5151

5252
- name: Build build
5353
run: opam exec -- cargo build --package ocaml-build --features=dune
5454

5555
- name: Run Rust tests
56-
run: opam exec -- cargo test --features=link -- --test-threads=1
56+
run: opam exec -- cargo run --example rust --features=link
5757

5858
- name: Check mdbook
5959
run: mdbook test doc -L ./target/debug/deps
6060

6161
- name: Test `no_std`
62-
run: opam exec -- cargo build --tests --features=no-std
62+
run: opam exec -- cargo build --example rust --features=no-std,link

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ members = [
4343

4444
[dev-dependencies]
4545
serial_test = "3.0.0"
46+
47+
[[example]]
48+
name = "rust"
49+
required-features = ["link"]

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
test: test-rust test-ocaml
22

33
test-rust:
4-
@cargo test --features=link -- --test-threads=1
4+
@cargo run --example rust --features=link
55

66
test-ocaml:
77
@dune clean --root=test

src/tests/mod.rs examples/rust.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
1-
use crate as ocaml;
1+
use ocaml::{Error, FromValue, ToValue, Value};
22

3-
use crate::{Error, FromValue, ToValue, Value};
4-
5-
#[cfg(test)]
6-
use serial_test::serial;
7-
8-
#[test]
9-
#[serial]
103
fn test_basic_array() -> Result<(), Error> {
11-
ocaml::runtime::init_persistent();
4+
ocaml::runtime::init();
125
let gc = unsafe { ocaml::Runtime::recover_handle() };
136
unsafe {
147
let mut a: ocaml::Array<&str> = ocaml::Array::alloc(2);
158
a.set(gc, 0, &"testing")?;
169
a.set(gc, 1, &"123")?;
1710
let b: Vec<&str> = FromValue::from_value(a.to_value(gc));
1811
assert!(b.as_slice() == &["testing", "123"]);
19-
unsafe {
20-
ocaml::sys::caml_enter_blocking_section();
21-
}
2212
Ok(())
2313
}
2414
}
2515

26-
#[test]
27-
#[serial]
2816
fn test_basic_list() {
29-
ocaml::runtime::init_persistent();
17+
ocaml::runtime::init();
3018
let gc = unsafe { ocaml::Runtime::recover_handle() };
3119
let mut list = ocaml::List::empty();
3220
let a = 3i64.to_value(gc);
@@ -50,8 +38,6 @@ fn test_basic_list() {
5038
}
5139
}
5240

53-
#[test]
54-
#[serial]
5541
fn test_int() {
5642
ocaml::runtime::init_persistent();
5743
let gc = unsafe { ocaml::Runtime::recover_handle() };
@@ -78,13 +64,8 @@ pub fn make_tuple(a: Value, b: Value) -> (Value, Value) {
7864
(a, b)
7965
}
8066

81-
#[test]
82-
#[serial]
8367
fn test_tuple_of_tuples() {
8468
ocaml::runtime::init_persistent();
85-
unsafe {
86-
ocaml::sys::caml_leave_blocking_section();
87-
}
8869
let gc = unsafe { ocaml::Runtime::recover_handle() };
8970

9071
let x = (1f64, 2f64, 3f64, 4f64, 5f64, 6f64, 7f64, 8f64, 9f64).to_value(gc);
@@ -105,3 +86,10 @@ fn test_tuple_of_tuples() {
10586
assert!(h == k);
10687
assert!(i == j);
10788
}
89+
90+
fn main() {
91+
test_basic_array().unwrap();
92+
test_basic_list();
93+
test_int();
94+
test_tuple_of_tuples();
95+
}

src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ pub fn ocamlopt() -> std::process::Command {
178178
std::process::Command::new(sys::COMPILER)
179179
}
180180

181-
#[cfg(feature = "link")]
182-
#[cfg(test)]
183-
mod tests;
184-
185181
/// OCaml runtime handle
186182
pub struct Runtime {
187183
_private: (),

0 commit comments

Comments
 (0)