Skip to content

Commit 1f388b6

Browse files
author
smeyer
committed
add tests for R CMD Rd2pdf
git-svn-id: https://svn.r-project.org/R/trunk@87664 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 3d3ceac commit 1f388b6

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/library/tools/tests/Rd2pdf.R

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
## test rendering the PDF manual of a package with non-ASCII help and \figure
2+
library("tools")
3+
4+
if (interactive()) setwd(tempdir()) # keep srcdir clean
5+
## unlink(c("pkg.*.pdf", "lib", "lib_latex", "pkg.latin1", "pkg.utf8"), recursive=TRUE)
6+
7+
create_pkg <- function (name = "pkg.utf8", encoding = "UTF-8")
8+
{
9+
write_DESCRIPTION <- function (dir, package = "pkg", encoding = "UTF-8")
10+
{
11+
desc <- c(
12+
"Package" = package,
13+
"Title" = "Package with Non-ASCII Help and Figure",
14+
"Version" = "1.0",
15+
"Author" = "D\u00e9j\u00e0 Vu", # Déjà Vu
16+
"Maintainer" = "\u00d3RF\u00c3O <[email protected]>", # ÓRFÃO
17+
"Description" = "Gr\u00fc\u00dfe.", # Grüße
18+
"License" = "GPL-2",
19+
"Encoding" = encoding
20+
)
21+
write.dcf(t(desc), file(file.path(dir, "DESCRIPTION"), encoding = encoding))
22+
}
23+
24+
dir.create(pkgdir <- name)
25+
dir.create(mandir <- file.path(pkgdir, "man"))
26+
dir.create(figuresdir <- file.path(mandir, "figures"))
27+
file.copy(file.path(R.home("doc"), "html", "Rlogo.pdf"), figuresdir) |> stopifnot()
28+
write_DESCRIPTION(pkgdir, package = name, encoding = encoding)
29+
promptPackage(name,
30+
filename = file(file.path(mandir, paste0(name, "-package.Rd")),
31+
encoding = encoding),
32+
final = TRUE) |> suppressMessages()
33+
writeLines(c("\\name{figure}", "\\alias{figure}",
34+
"\\title{Ilustraci\u00f3n}",
35+
"\\description{\\figure{Rlogo.pdf}{options: width=1cm}}"),
36+
file(file.path(mandir, "figure.Rd"), encoding = encoding))
37+
pkgdir
38+
}
39+
40+
Rd2pdf_opts <- c("--quiet", "--no-preview", "--force", "--no-index")
41+
INSTALL_opts <- c("--no-staged-install", "--no-lock", "--no-test-load")
42+
43+
for (encoding in c("UTF-8", "latin1"))
44+
{
45+
pkgname <- paste0("pkg.", tools:::latex_canonical_encoding(encoding))
46+
pkgdir <- create_pkg(pkgname, encoding)
47+
48+
## Render a single Rd file
49+
rdfile <- file.path(pkgdir, "man", "figure.Rd")
50+
Rcmd(c("Rd2pdf", Rd2pdf_opts, paste0("--encoding=", encoding),
51+
sprintf("--output=%s-figure.pdf", pkgname), rdfile)) == 0L ||
52+
stop("failed to render ", sQuote(rdfile))
53+
54+
## Render the package manual
55+
## - the following three variants all (over)write <pkgname>.pdf
56+
## - the first two are skipped as they are also exercised via check-all
57+
## (base pkgs are rendered from source, recommended from installed help)
58+
## - currently only the exit code is checked, not generated content
59+
if (interactive()) {
60+
Rcmd(c("Rd2pdf", Rd2pdf_opts, pkgdir)) == 0L ||
61+
stop("failed to render from source directory of ", sQuote(pkgname))
62+
63+
stopifnot(dir.exists("lib") || dir.create("lib"))
64+
install.packages(pkgdir, lib = "lib", repos = NULL,
65+
INSTALL_opts = INSTALL_opts)
66+
Rcmd(c("Rd2pdf", Rd2pdf_opts, file.path("lib", pkgname))) == 0L ||
67+
stop("failed to render from installed ", sQuote(pkgname))
68+
}
69+
stopifnot(dir.exists("lib_latex") || dir.create("lib_latex"))
70+
install.packages(pkgdir, lib = "lib_latex", repos = NULL,
71+
INSTALL_opts = c(INSTALL_opts, "--latex"))
72+
Rcmd(c("Rd2pdf", Rd2pdf_opts, file.path("lib_latex", pkgname))) == 0L ||
73+
stop("failed to render preconverted LaTeX help for ", sQuote(pkgname))
74+
## this failed in R 4.4.[012] due to undefined \inputencoding, but also,
75+
## in R < 4.5.0, due to undefined \includegraphics and unset \graphicspath,
76+
## and for "latin1" input from a fragile sub() of the \HeaderA line.
77+
}

0 commit comments

Comments
 (0)