Skip to content

Commit d565325

Browse files
committed
Fix 🐛 in catAndRun()
Show appropriate time unit, not always "seconds"
1 parent 7183157 commit d565325

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- subexpressionMatches(): rename arg "regularExpression" to "pattern", improve
1818
- add nameElements()
1919
- parallelNonNA(): use class of input vector "a" as class of output vector
20+
- fix bug in catAndRun(): show an appropriate time unit, not always "seconds"
2021

2122
# [kwb.utils 0.13.0](https://github.com/KWB-R/kwb.utils/releases/tag/v0.13.0) <small>2022-06-04</small>
2223

R/io.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ catAndRun <- function(
3939

4040
catIf(dbg, "ok. ")
4141

42-
catIf(dbg && log_time, sprintf("(%0.2fs) ", Sys.time() - start_time))
42+
dt <- Sys.time() - start_time
43+
44+
catIf(dbg && log_time, sprintf("(%0.2f %s) ", dt, attr(dt, "units")))
4345

4446
catNewLineIf(dbg && bitwAnd(newLine, 2))
4547

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
#kwb.utils::assignPackageObjects("kwb.utils")
2+
#library(testthat)
3+
14
test_that("catAndRun() works", {
25

36
x <- 1L
47

5-
expect_output(x <- catAndRun("work hard", x + 1L))
8+
expect_output(
9+
x <- catAndRun("work hard", x + 1L),
10+
regexp = "work hard \\.\\.\\. ok\\. \\(0\\.\\d\\d secs\\)",
11+
)
612

713
expect_identical(x, 2L)
814

915
expect_silent(catAndRun("work hard", x + 1L, dbg = FALSE))
1016
})
17+
18+
catAndRun("hello", Sys.sleep(time = 60))

0 commit comments

Comments
 (0)