Skip to content

Commit

Permalink
Update the README and CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Dec 21, 2024
1 parent 9d14440 commit bb77c73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- a `StringBuilder` struct that can be used to incrementally build
`nvim_oxi::String`s;

- a `nvim_oxi::tests::build()` function to be used in the build script of
a crate containing integration tests annotated with `#[nvim_oxi::test]`
([#201](https://github.com/noib3/nvim-oxi/pull/201));

### Changed

- `nvim_oxi::api::echo` is now generic over the highlight group type instead of
Expand Down
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,28 @@ might add a new example documenting your use case (if it can be done).

## Testing

The `test` feature flag enables the `#[nvim_oxi::test]` proc macro. This macro
replaces the regular `#[test]` annotations and can be used to test a piece of
code from within a Neovim instance using Rust's excellent testing framework.
Turning on the `test` feature enables `#[nvim_oxi::test]`, which replaces the
regular `#[test]` macro and allows you to test a piece of code from within a
Neovim instance using Rust's testing framework.

For example:

```rust
use nvim_oxi::{self as oxi, api};
use nvim_oxi::api;

#[oxi::test]
#[nvim_oxi::test]
fn set_get_del_var() {
api::set_var("foo", 42).unwrap();
assert_eq!(Ok(42), api::get_var("foo"));
assert_eq!(Ok(()), api::del_var("foo"));
}
```

Then `cargo test` will spawn a new Neovim process with an empty config, run
that code and exit. There are a couple of gotchas:
When `cargo test` is executed, the generated code will spawn a new Neovim
process with the `nvim` binary in your `$PATH`, test your code, and exit.

- after changing a piece of code, `cargo build` has to be run before you can
test that with `cargo test`;

- you cannot have two test functions with the same name, even if they belong to
different modules. For example this won't work:
There's a gotcha: you can't have two tests with the same name in the same
crate, even if they belong to different modules. For example, this won't work:

```rust
mod a {
Expand All @@ -97,3 +94,13 @@ mod b {
fn foo() {}
}
```

Note that all integration tests must live inside a separate `cdylib` crate with
the following build script:

```rust
// build.rs
fn main() -> Result<(), nvim_oxi::tests::BuildError> {
nvim_oxi::tests::build()
}
```

0 comments on commit bb77c73

Please sign in to comment.