From a452bffe579b1326fe635c2a229fe4b86362e1db Mon Sep 17 00:00:00 2001 From: CGMossa Date: Sun, 8 Oct 2023 00:03:11 +0200 Subject: [PATCH] Use `R_ParseEvalString` in test (#188) * Remove unnecessary `tasks.json` file! * Since all supported versions have `R_ParseEvalString`, then we should use it! --- .vscode/tasks.json | 18 ------------------ src/lib.rs | 12 ++---------- 2 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 62016596..00000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "type": "cargo", - "subcommand": "test", - "problemMatcher": [ - "$rustc" - ], - "group": { - "kind": "build", - "isDefault": true - } - } - ] -} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index eea9dff9..cd882a0a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,19 +137,11 @@ mod tests { fn test_eval() { start_R(); unsafe { - // In an ideal world, we would do the following. - // let res = R_ParseEvalString(cstr!("1"), R_NilValue); - // But R_ParseEvalString is only in recent packages. - - let s = Rf_protect(Rf_mkString(cstr!("1"))); - let mut status: ParseStatus = 0; - let status_ptr = &mut status as *mut ParseStatus; - let ps = Rf_protect(R_ParseVector(s, -1, status_ptr, R_NilValue)); - let val = Rf_eval(VECTOR_ELT(ps, 0), R_GlobalEnv); + let val = Rf_protect(R_ParseEvalString(cstr!("1"), R_NilValue)); Rf_PrintValue(val); assert_eq!(TYPEOF(val) as u32, REALSXP); assert_eq!(*REAL(val), 1.); - Rf_unprotect(2); + Rf_unprotect(1); } } }