From 7ee45bbe8919dab359cbf9ba771ad01ae6d46983 Mon Sep 17 00:00:00 2001 From: mutlusun Date: Mon, 14 Oct 2024 07:23:39 +0200 Subject: [PATCH] test(quarto): fix failing test on windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Output was: ``` ── Failure ('test-tar_quarto.R:521:3'): tar_quarto() reruns if target changes in included file ── sort(basename(out)) (`actual`) not equal to sort(c("main.html", "main.qmd", "file1.qmd")) (`expected`). `actual`: "file1.qmd" "file1.qmd" "main.html" "main.qmd" `expected`: "file1.qmd" "main.html" "main.qmd" ``` Thus, `file1.qmd` were not detected as a duplicate of the other `file1.qmd`. Probably because they have different paths. Thus, make `unique` command apear later in chain (after `path_rel`). This way, we should fix this issue. --- R/tar_quarto_files.R | 10 +++++++--- tests/testthat/test-tar_quarto_files.R | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/R/tar_quarto_files.R b/R/tar_quarto_files.R index 7ebf074..4843d93 100644 --- a/R/tar_quarto_files.R +++ b/R/tar_quarto_files.R @@ -51,7 +51,7 @@ tar_quarto_files <- function(path = ".", profile = NULL) { tar_quarto_files_document(path) ) for (field in c("sources", "output", "input")) { - out[[field]] <- sort(fs::path_rel(unique(as.character(out[[field]])))) + out[[field]] <- sort(unique(fs::path_rel(as.character(out[[field]])))) out[[field]] <- as.character(out[[field]]) } out @@ -72,13 +72,17 @@ tar_quarto_files_document <- function(path) { ) } - # Collect data about input files. + # Collect data about input files. It seems that quarto only puts the main + # rendering file (in this case `path`) into `fileInformation`. Even though + # included files might include other files, they still appear in + # `includeMap$target` and not as an own `fileInformation` entry. for (myfile in names(info$fileInformation)) { out$input <- c( out$input, # `myfile` are relative paths starting from `path`. myfile, - # `includeMap` contains relative paths starting from `myfile`. + # `includeMap` contains relative paths starting from `myfile`. We can use + # `dirname(path)` here as this is the directory of `myfile`. file.path( dirname(path), info$fileInformation[[myfile]]$includeMap$target diff --git a/tests/testthat/test-tar_quarto_files.R b/tests/testthat/test-tar_quarto_files.R index 4a1fb70..63d766f 100644 --- a/tests/testthat/test-tar_quarto_files.R +++ b/tests/testthat/test-tar_quarto_files.R @@ -89,15 +89,15 @@ targets::tar_test("tar_quarto_files() detects non-code dependencies", { "output_format: html", "---", "", - "{{< include \"text1.qmd\" >}}", - "", - "{{< include \"subdir/text2.qmd\" >}}" + "{{< include \"text1.qmd\" >}}" ) writeLines(lines, file.path("report", "main.qmd")) lines <- c( "# First File", "", - "Some text here." + "Some text here.", + "", + "{{< include \"subdir/text2.qmd\" >}}" ) writeLines(lines, file.path("report", "text1.qmd")) lines <- c(