cli icon indicating copy to clipboard operation
cli copied to clipboard

Caching dark vs light theme makes it harder to create reproducible output

Open lionel- opened this issue 2 years ago • 6 comments

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.

lionel- avatar Dec 09 '21 09:12 lionel-

We can solve this with a helper that turns "off" all cli options.

gaborcsardi avatar Dec 09 '21 09:12 gaborcsardi

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.

gaborcsardi avatar Jan 20 '22 10:01 gaborcsardi

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.

lionel- avatar Jan 20 '22 10:01 lionel-

I am not sure how that would work here.

gaborcsardi avatar Jan 20 '22 10:01 gaborcsardi

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.

gaborcsardi avatar Mar 04 '22 12:03 gaborcsardi

Maybe we could have some local_cli_config_reset() function that temporarily removes all cli env vars and options?

gaborcsardi avatar Mar 04 '22 12:03 gaborcsardi

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.

gaborcsardi avatar Aug 24 '22 14:08 gaborcsardi

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?

lionel- avatar Aug 24 '22 14:08 lionel-

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....)

gaborcsardi avatar Aug 24 '22 14:08 gaborcsardi