macros: remove the #[nvim_oxi::test(library_path = ..)] attribute

I added it to implement re-compiling the tests with
on `cargo t` in `nvimx`, but that's now implemented
directly in `nvim_oxi` so we don't need it anymore.
This commit is contained in:
Riccardo Mazzarini 2024-12-22 02:27:04 +08:00
parent 18e1cd0730
commit 1e15a4973e
No known key found for this signature in database
GPG key ID: 38165222613796F5
3 changed files with 11 additions and 87 deletions

View file

@ -141,28 +141,6 @@ pub fn plugin(attr: TokenStream, item: TokenStream) -> TokenStream {
///
/// If the given string spans multiple lines, it will be joined into a single
/// line using `;` as the separator.
///
/// ## `library_path`
///
/// The `library_path` attribute is used to specify the path to the compiled
/// shared library containing the code to test. This can be useful if you're
/// building your own macro on top of `test`, but should otherwise be left
/// unspecified.
///
/// It can be set to any expression that evaluates to a type implementing
/// `AsRef<Path>`.
///
/// ```ignore
/// # use nvim_oxi::api;
/// # use std::path::PathBuf;
/// #[nvim_oxi::test(library_path = my_custom_library_path())]
/// fn print_42() -> Result<(), api::Error> {
/// api::command("lua print(42)")
/// }
///
/// fn my_custom_library_path() -> PathBuf {
/// todo!();
/// }
/// ```
#[cfg(feature = "test")]
#[proc_macro_attribute]

View file

@ -27,13 +27,6 @@ pub fn test(attrs: TokenStream, item: TokenStream) -> TokenStream {
let nvim_oxi = &attrs.nvim_oxi;
let library_path = match &attrs.library_path {
Some(LibraryPath { path, .. }) => {
quote! { ::core::option::Option::Some(#path) }
},
None => quote! { ::core::option::Option::<&str>::None },
};
let extra_cmd = match &attrs.cmd {
Some(Cmd { cmd, .. }) => quote! { ::core::option::Option::Some(#cmd) },
None => quote! { ::core::option::Option::None },
@ -71,7 +64,6 @@ pub fn test(attrs: TokenStream, item: TokenStream) -> TokenStream {
env!("CARGO_CRATE_NAME"),
env!("CARGO_MANIFEST_PATH"),
stringify!(#plugin_name),
#library_path,
#extra_cmd,
)
}
@ -87,7 +79,6 @@ pub fn test(attrs: TokenStream, item: TokenStream) -> TokenStream {
#[derive(Default)]
struct Attributes {
cmd: Option<Cmd>,
library_path: Option<LibraryPath>,
nvim_oxi: NvimOxi,
}
@ -106,12 +97,6 @@ impl Parse for Attributes {
}
this.cmd = Some(cmd);
},
Attribute::LibraryPath(library_path) => {
if this.library_path.is_some() {
return Err(DuplicateError(library_path).into());
}
this.library_path = Some(library_path);
},
Attribute::NvimOxi(nvim_oxi) => {
if has_parsed_nvim_oxi {
return Err(DuplicateError(nvim_oxi).into());
@ -132,7 +117,6 @@ impl Parse for Attributes {
enum Attribute {
Cmd(Cmd),
LibraryPath(LibraryPath),
NvimOxi(NvimOxi),
}
@ -142,7 +126,6 @@ impl Parse for Attribute {
input
.parse::<Cmd>()
.map(Self::Cmd)
.or_else(|_| input.parse::<LibraryPath>().map(Self::LibraryPath))
.or_else(|_| input.parse::<NvimOxi>().map(Self::NvimOxi))
}
}
@ -182,30 +165,3 @@ impl ToTokens for Cmd {
lit.to_tokens(tokens);
}
}
/// The path to the compiled test library.
struct LibraryPath {
key_span: Span,
path: Expr,
}
impl KeyedAttribute for LibraryPath {
const KEY: &'static str = "library_path";
type Value = Expr;
#[inline]
fn key_span(&self) -> Span {
self.key_span
}
}
impl Parse for LibraryPath {
#[inline]
fn parse(input: ParseStream) -> syn::Result<Self> {
Ok(Self {
key_span: Span::call_site(),
path: input.parse::<Keyed<Self>>()?.value,
})
}
}