-
Notifications
You must be signed in to change notification settings - Fork 11
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
tests: clean up, simplify tests #716
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0826db7
refactor create_remote() and friends
maelle 571a7dd
simplify bump_version() tests, make structure clearer
maelle 1723f34
simplify create_repo()
maelle 340fd71
simplify one test file
maelle 44f65c1
slightly tweak test file
maelle da0e010
use testthat for mocking, more structure
maelle a70cbe8
clean test file
maelle 2dd85cf
align test switches names
maelle c057523
format, rm variant
maelle 3216e34
align this file with the others, less cumbersome syntax
maelle 4c3bf4a
more quiet, less cumbersome
maelle 0963472
update test since expect_snapshot_error() is experimental
maelle 9069751
oops, fix dep
maelle 3147057
Auto-update from GitHub Actions
maelle ae75fc6
expect_snapshot(error = TRUE in lieu of expect_snapshot_error()
maelle 87e8bf0
quiet
maelle 72b23ec
Auto-update from GitHub Actions
maelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,7 +279,7 @@ harvest_pr_data <- function(message) { | |
{ | ||
# suppressMessages() for quiet mocking | ||
suppressMessages( | ||
gh::gh(glue("GET /repos/{slug}/pulls/{pr_number}")) | ||
gh(glue("GET /repos/{slug}/pulls/{pr_number}")) | ||
) | ||
}, | ||
error = function(e) { | ||
|
@@ -360,10 +360,10 @@ has_internet <- function() { | |
if (!rlang::is_installed("curl")) { | ||
return(FALSE) | ||
} | ||
if (nzchar(Sys.getenv("YES_INTERNET_TEST_FLEDGE"))) { | ||
if (nzchar(Sys.getenv("FLEDGE_YES_INTERNET_TEST"))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these were the only test switches not starting with |
||
return(TRUE) | ||
} | ||
if (nzchar(Sys.getenv("NO_INTERNET_TEST_FLEDGE"))) { | ||
if (nzchar(Sys.getenv("FLEDGE_NO_INTERNET_TEST"))) { | ||
return(FALSE) | ||
} | ||
curl::has_internet() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gh <- function(...) { | ||
gh::gh(...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# with_demo_project errors informatively | ||
|
||
x Can't find the directory 'unexisting-dir'. | ||
Code | ||
with_demo_project(1 + 1, dir = "unexisting-dir") | ||
Condition | ||
Error in `local_demo_project()`: | ||
x Can't find the directory 'unexisting-dir'. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
create_remote <- function() { | ||
# assuming this is a temporary directory :-) | ||
parent_dir <- dirname(getwd()) | ||
dir.create(file.path(parent_dir, "remote")) | ||
gert::git_init(file.path(parent_dir, "remote"), bare = TRUE) | ||
remote_url <- file.path(parent_dir, "remote") | ||
gert::git_remote_add(remote_url, name = "origin") | ||
create_remote <- function(tempdir_remote) { | ||
|
||
gert::git_init(tempdir_remote, bare = TRUE) | ||
|
||
current_remotes <- gert::git_remote_list() | ||
origin_exists <- "origin" %in% current_remotes[["name"]] | ||
if (origin_exists) { | ||
cli::cli_abort(c( | ||
"Found an origin, we're in {getwd()}, was this expected?", | ||
i = "Did you forget to set up a local toy repo?" | ||
)) | ||
} | ||
|
||
gert::git_remote_add(tempdir_remote, name = "origin") | ||
gert::git_push(remote = "origin") | ||
remote_url | ||
|
||
tempdir_remote | ||
} | ||
|
||
show_tags <- function(remote_url) { | ||
|
||
tempdir_remote <- withr::local_tempdir(pattern = "remote") | ||
|
||
withr::with_dir(tempdir_remote, { | ||
gert::git_clone(remote_url) | ||
gert::git_clone(remote_url, path = "remote") | ||
gert::git_tag_list(repo = "remote")[, c("name", "ref")] | ||
}) | ||
} | ||
|
||
show_files <- function(remote_url) { | ||
if (!gert::user_is_configured()) { | ||
usethis::use_git_config(user.name = "Jane Doe", user.email = "[email protected]") | ||
usethis::use_git_config( | ||
user.name = "Jane Doe", | ||
user.email = "[email protected]" | ||
) | ||
} | ||
|
||
git_config <- gert::git_config_global() | ||
|
@@ -28,7 +42,7 @@ show_files <- function(remote_url) { | |
|
||
tempdir_remote <- withr::local_tempdir(pattern = "remote") | ||
withr::with_dir(tempdir_remote, { | ||
gert::git_clone(remote_url) | ||
gert::git_clone(remote_url, path = "remote") | ||
suppressMessages(gert::git_branch_checkout("main", force = TRUE, repo = "remote")) | ||
fs::dir_ls("remote", recurse = TRUE) | ||
}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is for being able to mock it while respecting the guidance in https://testthat.r-lib.org/reference/local_mocked_bindings.html#namespaced-calls