Skip to content

Commit

Permalink
Add testing for knitr and run
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanzomorrodi committed Nov 18, 2024
1 parent 7e7d66b commit 40dee39
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sas_run_file <- function(input_path, output_path, overwrite = FALSE) {
)
write_file(
output = paste(results$LOG, collapse = "\n"),
path = paste0(output_path[2], ".log"),
path = paste0(output_path[1], ".log"),
overwrite
)
}
7 changes: 7 additions & 0 deletions tests/testthat/test-knitr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("multiplication works", {
sas_use_quarto()

files <- c("sasquatch.qmd", "sas.xml")
expect_true(all(files %in% list.files()))
file.remove(files)
})
16 changes: 14 additions & 2 deletions tests/testthat/test-run.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_that("Run SAS code from string", {
expect_error(sas_run_string("PROC MEANS DATA = sashelp.cars;\nRUN;"))

sas_connect()

expect_s3_class(sas_run_string("PROC MEANS DATA = sashelp.cars;\nRUN;"), "sas_widget")
Expand All @@ -8,11 +10,21 @@ test_that("Run SAS code from string", {

test_that("Run SAS code from file", {
local_path <- "test.sas"
output_path <- "test.html"
cat("PROC MEANS DATA = sashelp.cars;\nRUN;", file = local_path)

expect_error(sas_run_file(local_path))

sas_connect()
expect_s3_class(sas_run_file(local_path), "sas_widget")

expect_no_error(sas_run_file(local_path, output_path))

output_paths <- c(output_path, gsub("html", "log", output_path))
expect_true(all(output_paths %in% list.files()))

expect_error(sas_run_file(local_path, output_path))

sas_disconnect()
file.remove(local_path)
})
file.remove(c(local_path, output_paths))
})
2 changes: 0 additions & 2 deletions tests/testthat/test.sas

This file was deleted.

0 comments on commit 40dee39

Please sign in to comment.