fish-shell/fish-rust/src/smoke.rs
ridiculousfish 681a165721 Add an FFI test facility
This allow testing Rust functions (from fish_tests.cpp) which need to
cross the FFI. See the example in smoke.rs.
2023-02-02 19:34:48 -07:00

27 lines
434 B
Rust

#[cxx::bridge(namespace = rust)]
mod ffi {
extern "Rust" {
fn add(left: usize, right: usize) -> usize;
}
}
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
use crate::ffi_tests::add_test;
add_test!("test_add", || {
assert_eq!(add(2, 3), 5);
});