Skip to content

Commit

Permalink
draft and test
Browse files Browse the repository at this point in the history
  • Loading branch information
kbvernon committed Sep 22, 2024
1 parent aeba4b7 commit 9ae8f3a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
44 changes: 44 additions & 0 deletions R/read_cargo_metadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' Retrieve metadata for packages and workspaces
#'
#' @param path character scalar, the R package directory
#'
#' @details
#' For more details, see
#' \href{https://doc.rust-lang.org/cargo/commands/cargo-metadata.html}{Cargo docs}
#' for `cargo-metadata`. See especially "JSON Format" to get a sense of what you
#' can expect to find in the returned list.
#'
#' @return `list`, including the following elements:
#' - "packages"
#' - "workspace_members"
#' - "workspace_default_members"
#' - "resolve"
#' - "target_directory"
#' - "version"
#' - "workspace_root"
#' - "metadata"
#'
#' @export
#'
#' @examples
#' \dontrun{
#' read_cargo_metadata()
#' }
#'
read_cargo_metadata <- function(path = ".") {
root <- rprojroot::find_package_root_file(path = path)

rust_folder <- normalizePath(
file.path(root, "src", "rust"),
winslash = "/",
mustWork = FALSE
)

out <- processx::run(
"cargo",
args = c("metadata", "--format-version=1", "--no-deps"),
wd = rust_folder
)

jsonlite::fromJSON(out[["stdout"]])
}
14 changes: 14 additions & 0 deletions tests/testthat/test-read_cargo_metadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test_that("read_cargo_metadata() returns package or workspace metadata", {
skip_if_not_installed("usethis")

path <- local_package("testpkg")

# capture setup messages
withr::local_options(usethis.quiet = FALSE)

use_extendr(path, quiet = TRUE)

out <- read_cargo_metadata()

expect_s3_class(out, "list")
})

0 comments on commit 9ae8f3a

Please sign in to comment.