Skip to content

Commit

Permalink
Add infun_read test
Browse files Browse the repository at this point in the history
  • Loading branch information
johndharrison committed Jan 15, 2017
1 parent e7cba25 commit 5e0b30d
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@ generic_start_log <- function(handle, poll = 3000L, increment = 500L){
e
}
)
print(errchk)
end <- Sys.time()
progress <-
progress + min(as.numeric(end-begin)*1000L, increment, poll)
39 changes: 39 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
context("utils")

test_that("canCallInfun_read", {
with_mock(
`subprocess::process_read` = function(handle, pipe, ...){
out <- list()
if(pipe %in% c(subprocess::PIPE_STDOUT)){
return("stdout here")
}
if(pipe %in% c(subprocess::PIPE_STDERR)){
return("stderr here")
}
if(pipe %in% c(subprocess::PIPE_BOTH)){
return(list(stdout = "stdout here", stderr = "stderr here"))
}
},
{
testenv <- new.env()
ifout <- wdman:::infun_read(handle = "",
pipe = subprocess::PIPE_STDOUT,
env = testenv)
iferr <- wdman:::infun_read(handle = "",
pipe = subprocess::PIPE_STDERR,
env = testenv)
ifboth <- wdman:::infun_read(handle = "",
pipe = subprocess::PIPE_BOTH,
env = testenv)
expect_identical(ifboth, list(stdout = "stdout here",
stderr = "stderr here"))
}
)
expect_identical(ifout, "stdout here")
expect_identical(iferr, "stderr here")
expect_identical(ifboth, list(stdout = "stdout here",
stderr = "stderr here"))
expect_identical(testenv[["stdout"]], rep("stdout here", 2))
expect_identical(testenv[["stderr"]], rep("stderr here", 2))
rm(testenv)
})

0 comments on commit 5e0b30d

Please sign in to comment.