cli
cli copied to clipboard
Caching dark vs light theme makes it harder to create reproducible output
If I set cli_theme_dark
in my RProfile, this changes snapshot outputs where ANSI escapes are enabled. This concerns only a few tests in rlang (most of the tests disable ANSI markup), but it'd be useful to be able to ensure reproducibility within a given version of cli.
We can solve this with a helper that turns "off" all cli options.
It seems that this is best solved in testthat, by including it in the reproducible context or supporting some hooks that people can use to do it themselves.
For the time being I usually run tests in a clean environment for packages that have issues with this.
Or should there be an init or default variant of that option, like for cli.num_colors
? There seems to be a common theme with these issues.
I am not sure how that would work here.
The detection is costly, so we need to cache it, but we could have a way to clean the cache.
That does not help with the test cases, though. For the test cases, you need to set the cli.theme_dark
option, or run the tests in a clean environment.
Maybe we could have some local_cli_config_reset()
function that temporarily removes all cli env vars and options?
On a second thought, the reset function is not great. Pretty error prone to write it, and also does not allow running the tests with specific options set.
So I am afraid that we'll just have to live with this.
and also does not allow running the tests with specific options set.
Are you sure this is the case? Once in the reproducible env (after a reset) you should still be able to change options?
Yeah, but sometimes you want to parameterize multiple tests or the whole test suite with some setting.
In any case, since this is a common problem, ideally we would fix it in testthat. (Btw. the testthat tests also fail if you set certain testthat options in your profile....)