Skip to content

Commit 6b3e0a7

Browse files
committed
Add some integration tests
1 parent 80b2d01 commit 6b3e0a7

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

crates/ark/tests/options.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use std::io::Write;
2+
3+
use ark_test::DummyArkFrontendRprofile;
4+
5+
// These tests verify that options set in `.Rprofile` interact correctly with
6+
// `initialize_options()` during startup. Each test needs its own process
7+
// because `DummyArkFrontendRprofile` can only be locked once, which is
8+
// handled by nextest.
9+
10+
#[test]
11+
fn test_override_option_replaces_user_value() {
12+
let mut file = tempfile::NamedTempFile::new().unwrap();
13+
writeln!(file, "options(max.print = 500)").unwrap();
14+
unsafe { std::env::set_var("R_PROFILE_USER", file.path()) };
15+
16+
let frontend = DummyArkFrontendRprofile::lock();
17+
18+
frontend.execute_request("getOption('max.print')", |result| {
19+
assert_eq!(result, "[1] 1000");
20+
});
21+
}
22+
23+
#[test]
24+
fn test_protected_override_option_keeps_user_value() {
25+
let mut file = tempfile::NamedTempFile::new().unwrap();
26+
writeln!(
27+
file,
28+
"options(max.print = 500, positron.protected_options = 'max.print')"
29+
)
30+
.unwrap();
31+
unsafe { std::env::set_var("R_PROFILE_USER", file.path()) };
32+
33+
let frontend = DummyArkFrontendRprofile::lock();
34+
35+
frontend.execute_request("getOption('max.print')", |result| {
36+
assert_eq!(result, "[1] 500");
37+
});
38+
}
39+
40+
#[test]
41+
fn test_default_option_keeps_user_value() {
42+
let mut file = tempfile::NamedTempFile::new().unwrap();
43+
writeln!(file, "options(help_type = 'text')").unwrap();
44+
unsafe { std::env::set_var("R_PROFILE_USER", file.path()) };
45+
46+
let frontend = DummyArkFrontendRprofile::lock();
47+
48+
frontend.execute_request("getOption('help_type')", |result| {
49+
assert_eq!(result, "[1] \"text\"");
50+
});
51+
}
52+
53+
#[test]
54+
fn test_default_option_sets_when_null() {
55+
let mut file = tempfile::NamedTempFile::new().unwrap();
56+
writeln!(file).unwrap();
57+
unsafe { std::env::set_var("R_PROFILE_USER", file.path()) };
58+
59+
let frontend = DummyArkFrontendRprofile::lock();
60+
61+
frontend.execute_request("getOption('help_type')", |result| {
62+
assert_eq!(result, "[1] \"html\"");
63+
});
64+
}
65+
66+
#[test]
67+
fn test_protected_default_option_stays_null() {
68+
let mut file = tempfile::NamedTempFile::new().unwrap();
69+
writeln!(file, "options(positron.protected_options = 'help_type')").unwrap();
70+
unsafe { std::env::set_var("R_PROFILE_USER", file.path()) };
71+
72+
let frontend = DummyArkFrontendRprofile::lock();
73+
74+
frontend.execute_request("is.null(getOption('help_type'))", |result| {
75+
assert_eq!(result, "[1] TRUE");
76+
});
77+
}

0 commit comments

Comments
 (0)