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

Second attempt to fix snapshot test on CI #2

Merged
merged 7 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions R/cran-compliance.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ use_cran_defaults <- function(path = ".", quiet = FALSE, overwrite = NULL, lib_n
#' @export
#' @name cran
vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
stderr_line_callback <- function(x, proc) {
if (!cli::ansi_grepl("To use vendored sources", x) && cli::ansi_nzchar(x)) {
cli::cat_bullet(stringi::stri_trim_left(x))
}
}
local_quiet_cli(quiet)

# get path to rust folder
Expand All @@ -140,13 +145,10 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
"--manifest-path",
file.path(src_dir, "Cargo.toml")
),
stderr_line_callback = function(x, proc) {
if (!grepl("To use vendored sources", x) && x != "") {
cli::cat_bullet(stringi::stri_trim_left(x))
}
}
stderr_line_callback = stderr_line_callback
)
})

if (update_res[["status"]] != 0) {
cli::cli_abort(
"{.file Cargo.lock} could not be created using {.code cargo generate-lockfile}",
Expand All @@ -155,8 +157,6 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
}
}



# vendor crates
withr::with_dir(src_dir, {
vendor_res <- processx::run(
Expand All @@ -167,11 +167,7 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
"--manifest-path",
file.path(src_dir, "Cargo.toml")
),
stderr_line_callback = function(x, proc) {
if (!grepl("To use vendored sources", x) && x != "") {
cli::cat_bullet(stringi::stri_trim_left(x))
}
}
stderr_line_callback = stderr_line_callback
)
})

Expand All @@ -182,8 +178,22 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
)
}

# create a dataframe of vendored crates
vendored <- vendor_res[["stderr"]] %>%
cli::ansi_strip() %>%
stringi::stri_split_lines1()

res <- stringi::stri_match_first_regex(vendored, "Vendoring\\s([A-z0-9_][A-z0-9_-]*?)\\s[vV](.+?)(?=\\s)") %>%
tibble::as_tibble(.name_repair = "minimal") %>%
rlang::set_names(c("source", "crate", "version")) %>%
dplyr::filter(!is.na(source)) %>%
dplyr::select(-source) %>%
dplyr::arrange(crate) # nolint: object_usage_linter

# capture vendor-config.toml content
config_toml <- stringi::stri_split(vendor_res$stdout, coll = "\n")[[1]]
config_toml <- vendor_res[["stdout"]] %>%
cli::ansi_strip() %>%
stringi::stri_split_lines1()

# always write to file as cargo vendor catches things like patch.crates-io
# and provides the appropriate configuration.
Expand All @@ -206,14 +216,6 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
)
}

# create a dataframe of vendored crates
vendored <- stringi::stri_split_lines1(vendor_res[["stderr"]])
res <- stringi::stri_match_first_regex(vendored, "Vendoring\\s([A-z0-9_][A-z0-9_-]*?)\\s[vV](.+?)(?=\\s)") %>%
tibble::as_tibble(.name_repair = "minimal") %>%
rlang::set_names(c("source", "crate", "version")) %>%
dplyr::filter(!is.na(source)) %>%
dplyr::select(-source)

# return packages and versions invisibly
invisible(res)
}
25 changes: 12 additions & 13 deletions tests/testthat/_snaps/use_cran_defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,18 @@
# vendor_pkgs() vendors dependencies

Code
print(x)
cat_file("src", "rust", "vendor-config.toml")
Output
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"

---

Code
package_versions
Output
# A tibble: 10 x 2
crate version
Expand All @@ -186,15 +197,3 @@
9 syn 1.0.109
10 unicode-ident 1.0.12

---

Code
cat_file("src", "rust", "vendor-config.toml")
Output
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"


4 changes: 2 additions & 2 deletions tests/testthat/test-use_cran_defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("vendor_pkgs() vendors dependencies", {
use_extendr(path, quiet = TRUE)
use_cran_defaults(path, quiet = TRUE, overwrite = TRUE)

x <- vendor_pkgs(path, quiet = TRUE)
expect_snapshot(print(x))
package_versions <- vendor_pkgs(path, quiet = TRUE)
expect_snapshot(cat_file("src", "rust", "vendor-config.toml"))
expect_snapshot(package_versions)
})