Skip to content

Commit aafd634

Browse files
committed
Add escape hatch in r_task() for unit tests
1 parent 4850e34 commit aafd634

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

crates/ark/src/r_task.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ use std::{
1010
time::Duration,
1111
};
1212

13+
use crate::interface::{RMain, R_MAIN};
14+
use crossbeam::channel::bounded;
1315
use harp::exec::safely;
16+
use harp::test::R_TASK_BYPASS;
17+
use log::info;
1418

1519
extern "C" {
1620
pub static mut R_PolledEvents: Option<unsafe extern "C" fn()>;
1721
}
1822

19-
use crossbeam::channel::bounded;
20-
use log::info;
21-
22-
use crate::interface::{RMain, R_MAIN};
23-
2423
type SharedOption<T> = Arc<Mutex<Option<T>>>;
2524

2625
pub fn r_task<'env, F, T>(f: F) -> T
@@ -29,6 +28,11 @@ where
2928
F: 'env + Send,
3029
T: 'env + Send,
3130
{
31+
// Escape hatch for unit tests
32+
if unsafe { R_TASK_BYPASS } {
33+
return f();
34+
}
35+
3236
let main = acquire_r_main();
3337

3438
// Recursive case: If we're on ark-r-main already, just run the

crates/ark/tests/environment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn test_environment_list() {
179179
assert_eq!(Rf_length(*contents), 0);
180180
}
181181

182-
// create some more variables
182+
// Create some more variables
183183
r_lock! {
184184
let sym = r_symbol!("a");
185185
Rf_defineVar(sym, Rf_ScalarInteger(42), test_env.sexp);
@@ -225,6 +225,6 @@ fn test_environment_list() {
225225
assert_eq!(update.removed, ["a"]);
226226
assert_eq!(update.version, 6);
227227

228-
// close the comm. Otherwise the thread panics
228+
// Close the comm. Otherwise the thread panics
229229
incoming_tx.send(CommChannelMsg::Close).unwrap();
230230
}

crates/harp/src/test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ use stdext::cargs;
2222

2323
use crate::lock::with_r_lock;
2424

25+
// Escape hatch for unit tests
26+
pub static mut R_TASK_BYPASS: bool = false;
27+
2528
static INIT: Once = Once::new();
2629

2730
pub fn start_r() {
2831
INIT.call_once(|| {
32+
unsafe {
33+
R_TASK_BYPASS = true;
34+
}
35+
2936
// TODO: Right now, tests can fail if the version of R discovered
3037
// on the PATH, and the version of R that 'ark' linked to at compile
3138
// time, do not match. We could relax this requirement by allowing

0 commit comments

Comments
 (0)