Skip to content

Commit

Permalink
Patch to avoid accessing R off the main thread in integration test (#618
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DavisVaughan authored Nov 4, 2024
1 parent e17d38b commit e3d0efc
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions crates/ark/tests/rstudioapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit e3d0efc

Please sign in to comment.