Closed peterdesmet closed 1 week ago
For future reference we should note the commit where the test for shift_time()
fails, or maybe include logs of a github actions run?
Sure, the two commits before my correction to cli::cli_inform()
fail:
https://github.com/inbo/camtrapdp/commit/44cebe6ed4ba855528fdca45c048989ba8dd0bbd https://github.com/inbo/camtrapdp/commit/f2338dceb1f5d11750e75f5baf52ff076401eb9e
@sannegovaert 's original use of cli::cli_alert_success()
did not fail:
https://github.com/inbo/camtrapdp/commit/18f34e01a97e37a124d507f02bc2f726aa67d4b4
If I capture the message class with cli_alert_success()
, I don't get the expected message class of camtrapdp_message_shift_time
:
tryCatch(shift_time(x, deployment_id, duration), message = function(m){print(class(m))})
#> [1] "cliMessage" "simpleMessage" "message" "condition"
While with cli_inform()
, I do:
tryCatch(shift_time(x, deployment_id, duration), message = function(m){print(class(m))})
#> [1] "camtrapdp_message_shift_time" "rlang_message"
#> [3] "message" "condition"
I also noticed that cli_alert_success()
results in a simpleMessage
and cli_inform()
in a rlang_message
, I was under the impression that all cli messaging was using rlang under the hood; https://rlang.r-lib.org/reference/abort.html
In cli_inform()
the class argument is actually passed to rlang via ...
tripledots/ellipsis. While in cli_alert_success()
, class is a defined argument
Via a helper, this class (of the message) is set here: https://github.com/r-lib/cli/blob/d33aeeee137bba67c423bc3e03949e45c48b8157/R/cli.R#L987-L991
I'm getting the feeling that while class from rlang and class from cli sound the same, they do different things. I wonder what is meant exactly by alert, it's not clear how they differ from the other functions in cli.
Thus ends my investigation, I'm not convinced the added value of cli_alert_success()
is worth the hassle in this case. I'm going to leave it here, feel free to reassign me if you want to revisit this.
Thanks for investigating. Closing this, ✔ can be replicated with "v" = "My message..."
, see #116.
I had to revert
cli::cli_alert_success()
tocli::cli_inform()
inshift_time()
in https://github.com/inbo/camtrapdp/pull/108/commits/093e85fc819447de83c5260ddcd51ed8fe87b909.The reason is that
cli::cli_alert_success()
failed thetestthat::expect_message()
tests. Both the test for theclass
(is class not supported forcli_alert_success()
?) and the test withregexp
(is thewrap = TRUE
not working as expected?).This is not an important bug, users just won't get a nice ✔ in front of the message. It is an odd bug though, that I find hard to reproduce.
For example, a small reprex example does pass the tests:
Created on 2024-09-05 with reprex v2.1.0
So I don't understand what is causing the tests to fail in
shift_time()
. Note that an unassigned call toshift_time()
will return two messages (the message + the default print), but that is not causing the issue.Created on 2024-09-05 with reprex v2.1.0