You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use sink to export the messages (message/warning/error) generated by R function to a log file in a R package (via a specific parameter logFile).
I would expect expect_silent to return TRUE if the output is exported to a file with sink, as no message/warning/error are printed to the console.
However, expect_silent mentions that messages have been produced:
library(testthat)
myFct <- function(logFile = NULL){
if(!is.null(logFile)){
logFileCon <- file(logFile, "w");
sink(file = logFileCon, type = "message");
on.exit(sink(type="message"))
}
message("This is a test message")
}
testthat::expect_silent(myFct(logFile = "log.txt")))
Error: `myFct(logFile = "log.txt")` produced messages.
Unfortunately I think it's going to be too difficult to tell if sink() is activated inside of expect_silent(), so you'll need to tackle this a different way.
I can reproduce this by sleeping my computer. The problem appears to be with the temporary file not being a valid path and not being opened in such a way that the containing folder is created. a tryCatch seems like it could fix this by simply creating the path. But the actual problem is that this file is not valid and that's not part of testthat.
I use
sink
to export the messages (message/warning/error) generated by R function to a log file in a R package (via a specific parameterlogFile
).I would expect
expect_silent
to return TRUE if the output is exported to a file with sink, as no message/warning/error are printed to the console.However,
expect_silent
mentions that messages have been produced:(This could be linked to #460)
The text was updated successfully, but these errors were encountered: