mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-27 20:53:38 +08:00
681a165721
This allow testing Rust functions (from fish_tests.cpp) which need to cross the FFI. See the example in smoke.rs.
27 lines
434 B
Rust
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);
|
|
});
|