Skip to content

Commit

Permalink
Test printing the output of installation failures
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Apr 2, 2024
1 parent b476a9a commit afe9395
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/library/zip/src/init.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <R.h>
#include <Rinternals.h>
#include <stdlib.h> // for NULL
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/fixtures/badcompile/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Package: badcompile
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R:
person("First", "Last", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1.9000
3 changes: 3 additions & 0 deletions tests/testthat/fixtures/badcompile/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by roxygen2: do not edit by hand

useDynLib(badcompile, .registration = TRUE)
4 changes: 4 additions & 0 deletions tests/testthat/fixtures/badcompile/R/badcompile-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## usethis namespace: start
#' @useDynLib badcompile, .registration = TRUE
## usethis namespace: end
NULL
3 changes: 3 additions & 0 deletions tests/testthat/fixtures/badcompile/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.so
*.dll
31 changes: 31 additions & 0 deletions tests/testthat/fixtures/badcompile/src/bad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
void f1() {

}

void f2() {

}

void f3() {

}

void f4() {

}

void f5() {

}

void f6() {

}

void f7() {

}

void f() {
foobar;
}
14 changes: 14 additions & 0 deletions tests/testthat/fixtures/badcompile/src/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <R.h>
#include <Rinternals.h>
#include <R_ext/Rdynload.h>
#define r_export attribute_visible extern

static const R_CallMethodDef CallEntries[] = {
{ NULL, NULL, 0 }
};

r_export void R_init_zip(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
R_forceSymbols(dll, TRUE);
}
43 changes: 43 additions & 0 deletions tests/testthat/test-failure-output.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
test_that("output is printed on failure", {
skip_on_cran()

# Full output in interactive sessions
badcompile <- paste0(
"local::",
normalizePath(test_path("fixtures/badcompile"))
)
tmp <- tempfile()
on.exit(unlink(tmp), add = TRUE)

expect_error(
callr::r(stdout = tmp, stderr = tmp, function(pkg) {
pkgload::load_all()
options(rlib_interactive = TRUE)
pak::pkg_install(pkg)
}, list(pkg = badcompile))
)

lines <- readLines(tmp)
expect_true(any(grepl("Failed to build badcompile", lines)))
expect_true(any(grepl("Full installation output", lines)))
expect_true(any(grepl(
"compilation failed for package .*badcompile.*",
lines
)))

expect_error(
callr::r(stdout = tmp, stderr = tmp, function(pkg) {
pkgload::load_all()
options(rlib_interactive = FALSE)
pak::pkg_install(pkg)
}, list(pkg = badcompile))
)

lines <- readLines(tmp)
expect_true(any(grepl("Failed to build badcompile", lines)))
expect_true(any(grepl("Full installation output", lines)))
expect_true(any(grepl(
"compilation failed for package .*badcompile.*",
lines
)))
})

0 comments on commit afe9395

Please sign in to comment.