Skip to content

Commit

Permalink
Add tests for crashing neovim with linebuffering
Browse files Browse the repository at this point in the history
  • Loading branch information
KillTheMule committed Jan 26, 2024
1 parent c5cfcc9 commit 7ea91dc
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,15 @@ required-features = ["use_tokio"]

[[test]]
name = "basic"

[[test]]
name = "regression"
path = "tests/regression/mod.rs"

[[bin]]
name = "linebuffercrash"
required-features = ["use_tokio"]

[[bin]]
name = "linebuffercrash_as"
required-features = ["use_async-std"]
24 changes: 24 additions & 0 deletions src/bin/linebuffercrash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

use nvim_rs::{
create::tokio as create,
rpc::handler::Dummy as DummyHandler
};


#[tokio::main]
async fn main() {
let handler = DummyHandler::new();
let (nvim, _io_handler) = create::new_parent(handler).await.unwrap();
let curbuf = nvim.get_current_buf().await.unwrap();

// If our Stdout is linebuffered, this has a high chance of crashing neovim
// Should probably befixed in neovim itself, but for now, let's just make
// sure we're not using linebuffering, or at least don't crash neovim with
// this.
for i in 0..20 {
curbuf.set_name(&format!("a{i}")).await.unwrap();
}

let _ = nvim.command("quit!").await;

}
24 changes: 24 additions & 0 deletions src/bin/linebuffercrash_as.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

use nvim_rs::{
create::async_std as create,
rpc::handler::Dummy as DummyHandler
};


#[async_std::main]
async fn main() {
let handler = DummyHandler::new();
let (nvim, _io_handler) = create::new_parent(handler).await.unwrap();
let curbuf = nvim.get_current_buf().await.unwrap();

// If our Stdout is linebuffered, this has a high chance of crashing neovim
// Should probably befixed in neovim itself, but for now, let's just make
// sure we're not using linebuffering, or at least don't crash neovim with
// this.
for i in 0..20 {
curbuf.set_name(&format!("a{i}")).await.unwrap();
}

let _ = nvim.command("quit!").await;

}
45 changes: 45 additions & 0 deletions tests/regression/buffering.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#[path = "../common/mod.rs"]
mod common;
use common::*;

use std::{path::PathBuf, process::Command};

fn viml_escape(in_str: &str) -> String {
in_str.replace('\\', r"\\")
}

fn linebuffercrashbin() -> &'static str {
#[cfg(feature = "use_tokio")]
return "linebuffercrash";
#[cfg(feature = "use_async-std")]
return "linebuffercrash_as";
}

#[test]
fn linebuffer_crash() {
let c1 = format!(
"let jobid = jobstart([\"{}\"], {{\"rpc\": v:true}})",
viml_escape(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("debug")
.join(linebuffercrashbin())
.to_str()
.unwrap()
)
);

let status = Command::new(nvim_path())
.args(&[
"-u",
"NONE",
"--headless",
"-c",
&c1,
])
.status()
.unwrap();

assert!(status.success());

}
4 changes: 4 additions & 0 deletions tests/regression/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[cfg(feature = "use_tokio")]
pub mod buffering;
#[cfg(feature = "use_async-std")]
pub mod buffering;

0 comments on commit 7ea91dc

Please sign in to comment.