Skip to content

Commit

Permalink
test(quarto): fix failing test on windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mutlusun committed Oct 14, 2024
1 parent 1c7f122 commit 7ee45bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions R/tar_quarto_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-tar_quarto_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7ee45bb

Please sign in to comment.