-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-mw_ss.R
More file actions
26 lines (23 loc) · 1.05 KB
/
test-mw_ss.R
File metadata and controls
26 lines (23 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if (!interactive()) options(warn=2, error = function() { sink(stderr()) ; traceback(3) ; q(status = 1) })
library(unittest)
source('mw_ss.R')
ok_baseline <- function (test_name, output) {
file_path <- here::here(paste('test-mw_ss', test_name, 'baseline', sep = "."))
if (!file.exists(file_path) || nzchar(Sys.getenv("RESET_BASELINE"))) {
writeLines(output, con = file_path)
}
base_output <- paste(readLines(file_path), collapse = "\n")
ok(ut_cmp_identical(output, base_output), sprintf("%s: Matches baseline", test_name))
}
xlsx_to_spec <- function (xlsx_path = 'anch.xlsx') {
spec_tbls <- c('time', 'area', 'stock', 'comm', 'surv')
structure(
lapply(spec_tbls, function(n) readxl::read_xlsx(xlsx_path, n)),
names = spec_tbls)
}
code <- mw_ss_script(xlsx_to_spec("anch.xlsx"), xlsx = "anch.xlsx")
ok_baseline('script-anch', code)
if (!interactive()) options(warn=0) # NB: ECOREC contains an all-zero line, generating a warning
eval(parse(text = code))
if (!interactive()) options(warn=2)
i2 <- r4ss::SS_read(dir = mod_path)