tests/testthat/test-chr-io.R

test_that("Can read last line without trailing newline", {

  px <- get_tool("px")

  p <- process$new(px, c("out", "foobar"), stdout = "|")
  on.exit(p$kill(), add = TRUE)
  out <- p$read_all_output_lines()
  expect_equal(out, "foobar")
})

test_that("Can read single characters", {

  px <- get_tool("px")

  p <- process$new(px, c("out", "123"), stdout = "|")
  on.exit(p$kill(), add = TRUE)
  p$wait()

  p$poll_io(-1)
  expect_equal(p$read_output(1), "1")
  expect_equal(p$read_output(1), "2")
  expect_equal(p$read_output(1), "3")
  expect_equal(p$read_output(1), "")
  expect_false(p$is_incomplete_output())
})

test_that("Can read multiple characters", {

  px <- get_tool("px")

  p <- process$new(px, c("out", "123456789"), stdout = "|")
  on.exit(p$kill(), add = TRUE)
  p$wait()

  p$poll_io(-1)
  expect_equal(p$read_output(3), "123")
  expect_equal(p$read_output(4), "4567")
  expect_equal(p$read_output(2), "89")
  expect_equal(p$read_output(1), "")
  expect_false(p$is_incomplete_output())
})

Try the processx package in your browser

Any scripts or data that you put into this service are public.

processx documentation built on May 29, 2024, 5:53 a.m.