From 61ad0e42c5c21ad006d603cc4299ee9e3ea8db4b Mon Sep 17 00:00:00 2001 From: Aron Atkins Date: Fri, 18 Oct 2024 15:07:28 -0400 Subject: [PATCH] bugfix: .R, .Rmd, .qmd are extensions, not substrings (#1107) Consider files with .R, .Rmd, and .qmd as extensions when detecting the primary document. fixes #1106 --- NEWS.md | 4 ++++ R/appMetadata.R | 4 ++-- rsconnect.Rproj | 1 + tests/testthat/_snaps/appMetadata.md | 4 ++-- tests/testthat/test-appMetadata.R | 13 ++++++++++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index e3396590..91d7d0d8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # rsconnect (development version) +* Primary Quarto document detection only considers `.R`, `.Rmd`, and `.qmd` as + end-of-file extensions. Previously, a file with `.R` elsewhere in its name, + such as `.Rprofile`, was incorrectly considered. (#1106) + * Use the public Connect server API endpoint `/v1/tasks/{id}` to poll task progress. (#1088) diff --git a/R/appMetadata.R b/R/appMetadata.R index a7fd9254..56df16fa 100644 --- a/R/appMetadata.R +++ b/R/appMetadata.R @@ -267,8 +267,8 @@ inferAppPrimaryDoc <- function(appPrimaryDoc, appFiles, appMode) { # determine expected primary document extension ext <- switch(appMode, "static" = "\\.html?$", - "quarto-static" = "\\.(r|rmd|qmd)", - "quarto-shiny" = "\\.(rmd|qmd)", + "quarto-static" = "\\.(r|rmd|qmd)$", + "quarto-shiny" = "\\.(rmd|qmd)$", "\\.rmd$") # use index file if it exists diff --git a/rsconnect.Rproj b/rsconnect.Rproj index 7e916bd0..beb581e4 100644 --- a/rsconnect.Rproj +++ b/rsconnect.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 3d8f30a6-9562-4255-8985-ba9413556e97 RestoreWorkspace: No SaveWorkspace: No diff --git a/tests/testthat/_snaps/appMetadata.md b/tests/testthat/_snaps/appMetadata.md index b096c678..03575416 100644 --- a/tests/testthat/_snaps/appMetadata.md +++ b/tests/testthat/_snaps/appMetadata.md @@ -48,11 +48,11 @@ Condition Error in `inferAppPrimaryDoc()`: ! Failed to determine `appPrimaryDoc` for "quarto-static" content. - x No files matching "\\.(r|rmd|qmd)". + x No files matching "\\.(r|rmd|qmd)$". Code inferAppPrimaryDoc(NULL, "a.html", "quarto-shiny") Condition Error in `inferAppPrimaryDoc()`: ! Failed to determine `appPrimaryDoc` for "quarto-shiny" content. - x No files matching "\\.(rmd|qmd)". + x No files matching "\\.(rmd|qmd)$". diff --git a/tests/testthat/test-appMetadata.R b/tests/testthat/test-appMetadata.R index c6452c0c..d51b2e15 100644 --- a/tests/testthat/test-appMetadata.R +++ b/tests/testthat/test-appMetadata.R @@ -263,9 +263,20 @@ test_that("uses index file if present", { }) test_that("otherwise fails back to first file with matching extensions", { - files <- c("a.html", "b.html", "a.Rmd", "b.Rmd") + files <- c(".Rprofile", "a.html", "b.html", "a.Rmd", "b.Rmd") expect_equal(inferAppPrimaryDoc(NULL, files, "static"), "a.html") + expect_equal(inferAppPrimaryDoc(NULL, files, "rmd-static"), "a.Rmd") expect_equal(inferAppPrimaryDoc(NULL, files, "rmd-shiny"), "a.Rmd") + expect_equal(inferAppPrimaryDoc(NULL, files, "quarto-static"), "a.Rmd") + expect_equal(inferAppPrimaryDoc(NULL, files, "quarto-shiny"), "a.Rmd") +}) + +test_that("can use R, Rmd, and qmd files for Quarto modes", { + expect_equal(inferAppPrimaryDoc(NULL, c(".Rprofile", "foo.R"), "quarto-static"), "foo.R") + expect_equal(inferAppPrimaryDoc(NULL, c(".Rprofile", "foo.Rmd"), "quarto-static"), "foo.Rmd") + expect_equal(inferAppPrimaryDoc(NULL, c(".Rprofile", "foo.qmd"), "quarto-static"), "foo.qmd") + expect_equal(inferAppPrimaryDoc(NULL, c(".Rprofile", "foo.Rmd"), "quarto-shiny"), "foo.Rmd") + expect_equal(inferAppPrimaryDoc(NULL, c(".Rprofile", "foo.qmd"), "quarto-shiny"), "foo.qmd") }) test_that("errors if no files with needed extension", {