tests/testthat/test-progress-handler-say.R

test_that("say_out", {
  px <- asNamespace("processx")$get_tool("px")
  tmp <- tempfile("cli-test-")
  on.exit(unlink(tmp), add = TRUE)
  withr::local_options(
    cli.progress_say_command = px,
    cli.progress_say_args = c("writefile", tmp)
  )
  p <- say_out(" 70%")
  expect_s3_class(p, "process")
  p$wait(3000)
  expect_false(p$is_alive())
  p$kill()
  expect_equal(readLines(tmp, warn = FALSE), " 70%")
})

test_that("say_update", {
  withr::local_options(cli.progress_say_frequency = 1e-9)
  mockery::stub(say_update, "say_out", function(text) text)
  bar <- new.env(parent = emptyenv())
  bar$current <- 10
  bar$total <- NA
  say_update(bar)
  expect_equal(bar$say_proc, 10)

  bar$total <- 50
  say_update(bar)
  expect_equal(bar$say_proc, " 20%")
})

Try the cli package in your browser

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

cli documentation built on March 31, 2023, 9:04 p.m.