diff --git a/.cargo/config.toml b/.cargo/config.toml index d502b62d..26e283ae 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,3 +7,6 @@ r-test = "run --manifest-path ./savvy-cli/Cargo.toml -- test" # makes the linker ignore these problems. [target.x86_64-pc-windows-msvc] rustflags = ["-C", "link-arg=/FORCE:UNRESOLVED"] + +[toolchain] +channel = "nightly" diff --git a/CHANGELOG.md b/CHANGELOG.md index bbb790c3..7e1b54ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,12 @@ * `r_print!()` and `r_eprint!()` now can print strings containing `%`. +### Breaking Change + +* The notation for `savvy-cli test` is now changed to `#[cfg(feature = + "savvy-test")]` from `#[cfg(savvy_test)]`. This is to avoid the upcoming + change in Cargo ([ref](https://blog.rust-lang.org/2024/05/06/check-cfg.html)). + ## [v0.6.3] (2024-05-05) ### New features diff --git a/Cargo.toml b/Cargo.toml index c45a8e22..12efe4d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,8 @@ altrep = ["savvy-ffi/altrep"] # Support logger logger = ["log", "env_logger"] +savvy-test = [] + [build-dependencies] cc = "1" diff --git a/R-package/src/rust/src/lib.rs b/R-package/src/rust/src/lib.rs index a087f76a..39961b6e 100644 --- a/R-package/src/rust/src/lib.rs +++ b/R-package/src/rust/src/lib.rs @@ -409,7 +409,7 @@ fn set_name_external(x: &mut Person, name: &str) -> savvy::Result<()> { x.set_name(name) } -#[cfg(savvy_test)] +#[cfg(feature = "savvy-test")] mod tests { #[test] fn test_to_upper() -> savvy::Result<()> { diff --git a/book/src/test.md b/book/src/test.md index cc0a1c83..77a21f40 100644 --- a/book/src/test.md +++ b/book/src/test.md @@ -52,13 +52,13 @@ pub fn foo() -> savvy::Result<()> { ### Test module -You can write tests under a module marked with `#[cfg(savvy_test)]` instead of +You can write tests under a module marked with `#[cfg(feature = "savvy-test")]` instead of `#[cfg(test)]`. A `#[test]` function needs to have the return value of `savvy::Result<()>`, which is the same convention as `#[savvy]`. To check if an SEXP contains the expected data, `assert_eq_r_code` is convenient. ```rust -#[cfg(savvy_test)] +#[cfg(feature = "savvy-test")] mod test { use savvy::{OwnedIntegerSexp, assert_eq_r_code}; @@ -73,6 +73,15 @@ mod test { } ``` +Note that `savvy-test` is just a marker for `savvy-cli`, not a real feature. So, +in theory, you don't really need this. However, in reality, you probably want to +add it to the `[features]` section of `Cargo.toml` because otherwise Cargo warns. + +```toml +[features] +savvy-test = [] +``` + To test a function that takes user-supplied SEXPs like `IntegerSexp`, you can use `.as_read_only()` to convert from the corresponding `Owned-` type. For example, if you have a function `your_fn()` that accepts `IntegerSexp`, you can @@ -85,7 +94,7 @@ pub fn your_fn(x: IntegerSexp) -> savvy::Result<()> { // ...snip... } -#[cfg(savvy_test)] +#[cfg(feature = "savvy-test")] mod test { use savvy::OwnedIntegerSexp; diff --git a/savvy-bindgen/src/gen/templates/lib_rs b/savvy-bindgen/src/gen/templates/lib_rs index f137dba4..9b94e3e5 100644 --- a/savvy-bindgen/src/gen/templates/lib_rs +++ b/savvy-bindgen/src/gen/templates/lib_rs @@ -95,10 +95,10 @@ mod test1 { } } -// Tests marked under `#[cfg(savvy_test)]` are run by `savvy-cli test`, which +// Tests marked under `#[cfg(feature = "savvy-test")]` are run by `savvy-cli test`, which // executes the Rust code on a real R session so that you can use R things for // testing. -#[cfg(savvy_test)] +#[cfg(feature = "savvy-test")] mod test1 { // The return type must be `savvy::Result<()>` #[test] diff --git a/savvy-bindgen/src/parse_file.rs b/savvy-bindgen/src/parse_file.rs index 01f8651f..6d1112a2 100644 --- a/savvy-bindgen/src/parse_file.rs +++ b/savvy-bindgen/src/parse_file.rs @@ -169,7 +169,7 @@ impl ParsedResult { let is_test_mod = item_mod .attrs .iter() - .any(|attr| attr == &parse_quote!(#[cfg(savvy_test)])); + .any(|attr| attr == &parse_quote!(#[cfg(feature = "savvy-test")])); match (&item_mod.content, is_test_mod) { (None, false) => { @@ -346,10 +346,10 @@ fn transform_test_mod( ) -> ParsedTestCase { let mut item_mod = item_mod.clone(); - // Remove #[cfg(savvy_test)] + // Remove #[cfg(feature = "savvy-test")] item_mod .attrs - .retain(|attr| attr != &parse_quote!(#[cfg(savvy_test)])); + .retain(|attr| attr != &parse_quote!(#[cfg(feature = "savvy-test")])); item_mod.ident = format_ident!("__UNIQUE_PREFIX__mod_{}", item_mod.ident); diff --git a/src/eval.rs b/src/eval.rs index 51a9033c..1de6124d 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -128,7 +128,7 @@ pub fn assert_eq_r_code, T2: AsRef>(actual: T1, expected: T2 assert!(is_r_identical(actual, parsed)); } -#[cfg(savvy_test)] +#[cfg(feature = "savvy-test")] mod test { use crate::{IntegerSexp, RealSexp}; diff --git a/src/sexp/integer.rs b/src/sexp/integer.rs index ac0f2db4..89668031 100644 --- a/src/sexp/integer.rs +++ b/src/sexp/integer.rs @@ -460,7 +460,7 @@ impl IndexMut for OwnedIntegerSexp { } } -#[cfg(savvy_test)] +#[cfg(feature = "savvy-test")] mod test { use super::OwnedIntegerSexp; use crate::NotAvailableValue;