diff --git a/crates/ark/tests/rstudioapi.rs b/crates/ark/tests/rstudioapi.rs index 38441bbab..4c5c0b1be 100644 --- a/crates/ark/tests/rstudioapi.rs +++ b/crates/ark/tests/rstudioapi.rs @@ -11,7 +11,10 @@ fn test_get_version() { } let value = "1.0.0"; - harp::envvar::set_var("POSITRON_VERSION", value); + // Can't directly talk to R, need an `r_task()` that can be used alongside + // the `frontend`. See https://github.com/posit-dev/ark/issues/609. + // harp::envvar::set_var("POSITRON_VERSION", value); + set_var("POSITRON_VERSION", value, &frontend); let code = "as.character(rstudioapi::getVersion())"; frontend.send_execute_request(code, ExecuteRequestOptions::default()); @@ -39,7 +42,10 @@ fn test_get_mode() { } let value = "desktop"; - harp::envvar::set_var("POSITRON_MODE", value); + // Can't directly talk to R, need an `r_task()` that can be used alongside + // the `frontend`. See https://github.com/posit-dev/ark/issues/609. + // harp::envvar::set_var("POSITRON_MODE", value); + set_var("POSITRON_MODE", value, &frontend); let code = "rstudioapi::getMode()"; frontend.send_execute_request(code, ExecuteRequestOptions::default()); @@ -57,6 +63,19 @@ fn test_get_mode() { assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count) } +fn set_var(key: &str, value: &str, frontend: &DummyArkFrontend) { + let code = format!("Sys.setenv({key} = \"{value}\")"); + frontend.send_execute_request(code.as_str(), ExecuteRequestOptions::default()); + frontend.recv_iopub_busy(); + + let input = frontend.recv_iopub_execute_input(); + assert_eq!(input.code, code); + + frontend.recv_iopub_idle(); + + assert_eq!(frontend.recv_shell_execute_reply(), input.execution_count) +} + fn has_rstudioapi(frontend: &DummyArkFrontend) -> bool { let code = ".ps.is_installed('rstudioapi')"; frontend.send_execute_request(code, ExecuteRequestOptions::default());