Skip to content

Commit

Permalink
rust: try to work around windows permission problem during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
randommm committed Feb 18, 2024
1 parent c06599c commit e58c695
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions rust/tests/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod common;
use std::{f64::consts::PI, ffi::CString, fs::remove_file};
use std::{f64::consts::PI, ffi::CString, fs};

use common::{get_model, model_dir};

Expand Down Expand Up @@ -47,11 +47,16 @@ fn logp_gradient() {
fn model_compiling() {
let name = "stdnormal";
let mut base = model_dir();
let stan_path_orig = base.join(name).join(format!("{}.stan", name));

let name = "stdnormal_compile_test";
base.push(name);
let lib_path = base.join(format!("{}_model.so", name));
fs::create_dir_all(base.as_path()).unwrap();
let stan_path = base.join(format!("{}.stan", name));
remove_file(lib_path).unwrap();
compile_model(stan_path, vec![], vec![], None).unwrap();
fs::copy(stan_path_orig, stan_path.as_path()).unwrap();

let lib_path = base.join(format!("{}_model.so", name));
compile_model(stan_path.as_path(), vec![], vec![], None).unwrap();

let (lib, data) = get_model(name);
let model = Model::new(&lib, data, 42).unwrap();
Expand All @@ -62,6 +67,10 @@ fn model_compiling() {
.unwrap();
assert_ulps_eq!(logp, (2. * PI).sqrt().recip().ln() - 0.5);
assert_ulps_eq!(grad[0], -1f64);

fs::remove_file(lib_path).unwrap_or_default();
fs::remove_file(stan_path).unwrap_or_default();
fs::remove_dir(base).unwrap_or_default();
}

#[test]
Expand Down

0 comments on commit e58c695

Please sign in to comment.