Skip to content

Commit

Permalink
Test that errors returned by vim.notify are propagated
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Dec 26, 2024
1 parent 9d1559e commit a835ad4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ neovim-0-9 = ["nvim-oxi/neovim-0-9"]
neovim-0-10 = ["neovim-0-9", "nvim-oxi/neovim-0-10"]
neovim-nightly = ["neovim-0-10", "nvim-oxi/neovim-nightly"]

[target.'cfg(not(any(target_os = "windows", target_env = "msvc")))'.dependencies]
[dependencies]
all_asserts = "2.3"
thiserror = { workspace = true }

[target.'cfg(not(any(target_os = "windows", target_env = "msvc")))'.dependencies]
nvim-oxi = { path = "..", features = ["libuv", "mlua", "test"] }

[target.'cfg(any(target_os = "windows", target_env = "msvc"))'.dependencies]
all_asserts = "2.3"
nvim-oxi = { path = "..", features = ["mlua", "test"] }

[build-dependencies]
Expand Down
21 changes: 19 additions & 2 deletions tests/src/api/global.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::sync::Arc;

use all_asserts::*;
use nvim_oxi::api::{self, opts::*, types::*, Buffer, Window};
use nvim_oxi::mlua::{IntoLuaMulti, Lua, Result as LuaResult, Table};
use nvim_oxi::mlua::{Error as LuaError, IntoLuaMulti, Lua, Table};
use nvim_oxi::{Dictionary, Object};

#[nvim_oxi::test]
Expand Down Expand Up @@ -199,6 +201,21 @@ fn notify_custom() {
assert_eq!(ret, message.into());
}

#[nvim_oxi::test]
fn notify_custom_err() {
#[derive(Debug, thiserror::Error)]
#[error("")]
struct CustomError;

// Set up a custom notification provider.
set_notification_provider(move |_lua, _msg, _level, _opts| {
Err::<(), _>(LuaError::ExternalError(Arc::new(CustomError)))
});

let opts = Dictionary::new();
let _err = api::notify("", LogLevel::Error, &opts).unwrap_err();
}

#[nvim_oxi::test]
fn set_get_del_current_line() {
let res = api::set_current_line("foo");
Expand Down Expand Up @@ -299,7 +316,7 @@ fn hex_to_dec(hex_color: &str) -> u32 {

fn set_notification_provider<P, R>(mut provider: P)
where
P: FnMut(&Lua, String, u32, Table) -> LuaResult<R> + 'static,
P: FnMut(&Lua, String, u32, Table) -> Result<R, LuaError> + 'static,
R: IntoLuaMulti,
{
let lua = nvim_oxi::mlua::lua();
Expand Down

0 comments on commit a835ad4

Please sign in to comment.