From 2866bed187eea53e2912b42733a82b2206fec11f Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Tue, 21 Jan 2025 20:51:28 +1300 Subject: [PATCH] minor edits --- R/compile.R | 2 +- tests/testthat/app.R | 2 -- tests/testthat/test-compile.R | 64 ++++++++++++++++++----------------- tests/testthat/test-deploy.R | 5 +++ tests/testthat/test_deploy.R | 25 -------------- 5 files changed, 39 insertions(+), 59 deletions(-) create mode 100644 tests/testthat/test-deploy.R delete mode 100644 tests/testthat/test_deploy.R diff --git a/R/compile.R b/R/compile.R index dcc4c02..2a9aa7e 100644 --- a/R/compile.R +++ b/R/compile.R @@ -27,7 +27,7 @@ ts_compile.ts_function <- function(f, ..., name = deparse(substitute(f))) { #' @export ts_compile.character <- function( f, - file = sprintf("%s.d.ts", tools::file_path_sans_ext(f))) { + file = sprintf("%s.rserve.ts", tools::file_path_sans_ext(f))) { if (length(f) > 1) { return(sapply(f, ts_compile)) } diff --git a/tests/testthat/app.R b/tests/testthat/app.R index ebac7d5..855ee6b 100644 --- a/tests/testthat/app.R +++ b/tests/testthat/app.R @@ -1,5 +1,3 @@ -library(ts) - fn_mean <- ts_function(mean, x = ts_numeric(), result = ts_numeric(1)) fn_first <- ts_function(function(x = ts_character()) x[1], result = ts_character(1) diff --git a/tests/testthat/test-compile.R b/tests/testthat/test-compile.R index 1470bbc..43db551 100644 --- a/tests/testthat/test-compile.R +++ b/tests/testthat/test-compile.R @@ -4,41 +4,43 @@ test_that("anonomous functions", { result = ts_numeric(1) ) - ts_compile(add) - - # expect_equal(add$call(1, 2), 3) - # expect_error(add$call("a", 2)) + add_c <- ts_compile(add) + expect_equal(add_c, "const add = Robj.ocap([z.number(), z.number()], Robj.numeric(1));") }) -test_that("Complex functions", { - get_sample <- ts_function( - function(n = ts_numeric(1)) { - sample(values, n) - }, - result = ts_numeric() - ) +# test_that("Complex functions", { +# get_sample <- ts_function( +# function(n = ts_numeric(1)) { +# sample(values, n) +# }, +# result = ts_numeric() +# ) - sampler <- ts_function( - function(values = ts_numeric()) { - list( - get = get_sample$copy(), - set = ts_function( - function(value = ts_numeric()) { - values <<- value - } - ) - ) - }, - result = ts_list( - get = get_sample, - set = ts_function(NULL, value = ts_numeric()) - ) - ) +# sampler <- ts_function( +# function(values = ts_numeric()) { +# list( +# get = get_sample$copy(), +# set = ts_function( +# function(value = ts_numeric()) { +# values <<- value +# } +# ) +# ) +# }, +# result = ts_list( +# get = get_sample, +# set = ts_function(NULL, value = ts_numeric()) +# ) +# ) - ts_compile(sampler) -}) +# sampler_c <- ts_compile(sampler) +# s <- sampler_c(1:10) +# expect_equal() +# }) test_that("Compile files", { - on.exit(if (file.exists("app.d.ts")) unlink("app.d.ts")) - res <- ts_compile("app.R") + f <- tempfile(fileext = ".rserve.ts") + on.exit(unlink(f)) + res <- ts_compile("app.R", file = f) + expect_true(file.exists(f)) }) diff --git a/tests/testthat/test-deploy.R b/tests/testthat/test-deploy.R new file mode 100644 index 0000000..d89ef9b --- /dev/null +++ b/tests/testthat/test-deploy.R @@ -0,0 +1,5 @@ +test_that("Deploy converts ts functions into valid ocap lists", { + on.exit(if (file.exists("app.rserve.R")) unlink("app.rserve.R")) + ts_deploy("app.R") + expect_true(file.exists("app.rserve.R")) +}) diff --git a/tests/testthat/test_deploy.R b/tests/testthat/test_deploy.R deleted file mode 100644 index 56ec867..0000000 --- a/tests/testthat/test_deploy.R +++ /dev/null @@ -1,25 +0,0 @@ -test_that("Deploy converts ts functions into valid ocap lists", { - get_sample <- ts_function( - function(n = ts_numeric(1)) { - sample(values, n) - }, - result = ts_numeric() - ) - - sampler <- ts_function( - function(values = ts_numeric()) { - list( - get = get_sample$copy(), - set = ts_function( - function(value = ts_numeric()) { - values <<- value - } - ) - ) - }, - result = ts_list( - get = get_sample, - set = ts_function(NULL, value = ts_numeric()) - ) - ) -})