Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1074 to improve code coverage of R/utils.R to 100% #1075

Merged
merged 6 commits into from
Aug 8, 2023

Conversation

ilyaZar
Copy link
Contributor

@ilyaZar ilyaZar commented Aug 4, 2023

Fix #1074

Testing strategy:

  1. Some interactive code inside R/utils.R is tested using {mockery} which is not part of {golem} so this is experimental. However, it is the recommended way to go when interactive() code parts should be tested (as far as I understood), hence the approach (and the implied request to add {mockery} to Suggests, which also is used here Fix 887 and improve code coverage of R/config.R from 28.21% to 100% #1043).

  2. CLI messaging is tested via snapping the output which has the benefit that whenever the underlying {cli} package changes output style one gets automatic notifications making devs aware of the fact that screen output changes.

PR parts in detail:

Done

The following a "rather" independent so commits can be cherry picked:

  • d0feaf5: some minor additions to is_existing_module() with cleaner testing (to actually delete redundant artefact dirs on exit)

  • 8ed4ccf: add tests for non-interactive part of create_if_needed() function:
    move coverage to 58.58 %

  • cea07f2: add tests for interactive part of create_if_needed() function mimicking user behavior: "no"/FALSE:
    move coverage to 60.09 %

  • de07bb3: add tests for interactive part of create_if_needed() function mimicking user behavior: "yes"/TRUE:
    move coverage to 62.62 %

  • 9025d9f: shallow test encapsulated ask_golem_creation_file() AND remove never used function check_file_exist(); I could not find any call to this function inside golem and it is unexported as well....
    move coverage to 67.79%

  • fcd73a7: snapshot test cli messages
    move coverage to 88.98 %

To-Do

  • add test for "after_creation_messages" functions
  • add test for "check installed/required version of packages" functions
  • some other corner cases of the functions in that file

ilyaZar added 6 commits August 4, 2023 14:16
    - make it self-check if is called inside an R package (by checking for existence of an R-directory)
    - improve docs: add information that it checks for the existence of a module /!\ file /!\ name which is not the same as a module
    - improve tests:
        - proper cleanup of a golem
        - check failure/error if not inside a R-package (in the above sense)
- must produce error when called non-interactively for argyment type="file"
…vely 'no'

- allow mocking of user interaction with "no"-response for testing purposes
    - requires encapsulation of yesno() to a separate function
- restyle the file with grkstyler
- add a test that mimicks user interation with "no" response of the yesno()-function

=> improve test coverage to 60.09 %
whereby improving coverage to 62.62 %
- shallow-test encapsulated function ask_golem_creation_file()
- remove redundant check_file_exist() which is never used inside `{golem}`!
- improve formatting of some comments inside create_if_needed()

=> improve test coverage to 67.79%
- snapshot tests save the output of cli-messages and check options
    - if cli:: package changes we see a different output and the snapshots will inform about this
    - additionally check do_if_unquiet() feature of these message functions
@VincentGuyader VincentGuyader changed the base branch from dev to dev_1074 August 8, 2023 11:11
@VincentGuyader VincentGuyader merged commit cf3eb8b into ThinkR-open:dev_1074 Aug 8, 2023
VincentGuyader added a commit that referenced this pull request Aug 8, 2023
* Fix 1074 to improve code coverage of `R/utils.R` to 100% (#1075)

* feature: improve is_exisiting_module()

    - make it self-check if is called inside an R package (by checking for existence of an R-directory)
    - improve docs: add information that it checks for the existence of a module /!\ file /!\ name which is not the same as a module
    - improve tests:
        - proper cleanup of a golem
        - check failure/error if not inside a R-package (in the above sense)

* tests: test create_if_need() function non-interactively

- must produce error when called non-interactively for argyment type="file"

* refactor: add clearer logic for create_if_needed() and test interactively 'no'

- allow mocking of user interaction with "no"-response for testing purposes
    - requires encapsulation of yesno() to a separate function
- restyle the file with grkstyler
- add a test that mimicks user interation with "no" response of the yesno()-function

=> improve test coverage to 60.09 %

* tests: add test for user interactive behavior "yes"

whereby improving coverage to 62.62 %

* refactor:

- shallow-test encapsulated function ask_golem_creation_file()
- remove redundant check_file_exist() which is never used inside `{golem}`!
- improve formatting of some comments inside create_if_needed()

=> improve test coverage to 67.79%

* tests: increaset R/utils.R coverage to 88.98%

- snapshot tests save the output of cli-messages and check options
    - if cli:: package changes we see a different output and the snapshots will inform about this
    - additionally check do_if_unquiet() feature of these message functions

* chore set att_amend_desc default parameters

---------

Co-authored-by: Ilya Zarubin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants