|
| 1 | +#!/usr/bin/env r |
| 2 | +# -*- mode: R; tab-width: 4; -*- |
| 3 | +# |
| 4 | +# Copyright (C) 2018 RStudio |
| 5 | +# |
| 6 | +# This file is part of Rcpp. |
| 7 | +# |
| 8 | +# Rcpp is free software: you can redistribute it and/or modify it |
| 9 | +# under the terms of the GNU General Public License as published by |
| 10 | +# the Free Software Foundation, either version 2 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | +# |
| 13 | +# Rcpp is distributed in the hope that it will be useful, but |
| 14 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU General Public License |
| 19 | +# along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
| 20 | +.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" |
| 21 | + |
| 22 | +if (.runThisTest) { |
| 23 | + |
| 24 | + test.interface.unwind <- function() { |
| 25 | + exporter_name <- "testRcppInterfaceExporter" |
| 26 | + user_name <- "testRcppInterfaceUser" |
| 27 | + |
| 28 | + tempdir <- tempfile() |
| 29 | + dir.create(tempdir) |
| 30 | + old_wd <- setwd(tempdir) |
| 31 | + on.exit({ |
| 32 | + setwd(old_wd) |
| 33 | + unlink(tempdir, recursive = TRUE) |
| 34 | + }) |
| 35 | + |
| 36 | + file.copy(system.file("unitTests", exporter_name, package = "Rcpp"), |
| 37 | + tempdir, |
| 38 | + recursive = TRUE) |
| 39 | + file.copy(system.file("unitTests", user_name, package = "Rcpp"), |
| 40 | + tempdir, |
| 41 | + recursive = TRUE) |
| 42 | + |
| 43 | + exporter_path <- file.path(tempdir, exporter_name) |
| 44 | + user_path <- file.path(tempdir, user_name) |
| 45 | + |
| 46 | + Rcpp::compileAttributes(exporter_path) |
| 47 | + Rcpp::compileAttributes(user_path) |
| 48 | + |
| 49 | + lib_path <- file.path(tempdir, "templib") |
| 50 | + dir.create(lib_path) |
| 51 | + |
| 52 | + install <- function(path, lib_path) { |
| 53 | + install.packages( |
| 54 | + path, |
| 55 | + lib_path, |
| 56 | + repos = NULL, |
| 57 | + type = "source", |
| 58 | + INSTALL_opts = "--install-tests" |
| 59 | + ) |
| 60 | + } |
| 61 | + install(exporter_path, lib_path) |
| 62 | + install(user_path, lib_path) |
| 63 | + |
| 64 | + old_lib_paths <- .libPaths() |
| 65 | + on.exit(.libPaths(old_lib_paths)) |
| 66 | + .libPaths(lib_path) |
| 67 | + |
| 68 | + # Without this testInstalledPackage() won't find installed |
| 69 | + # packages even though we've passed `lib.loc` |
| 70 | + old_libs_envvar <- Sys.getenv("R_LIBS") |
| 71 | + on.exit(Sys.setenv(R_LIBS = old_libs_envvar), add = TRUE) |
| 72 | + |
| 73 | + sys_sep <- if (.Platform$OS.type == "windows") ";" else ":" |
| 74 | + Sys.setenv(R_LIBS = paste(c(lib_path, old_lib_paths), collapse = sys_sep)) |
| 75 | + |
| 76 | + result <- tools::testInstalledPackage(user_name, lib.loc = lib_path, types = "test") |
| 77 | + |
| 78 | + # Be verbose if tests were not successful |
| 79 | + if (result) { |
| 80 | + log <- file.path(paste0(user_name, "-tests"), "tests.Rout.fail") |
| 81 | + cat(">> tests.Rout.fail", readLines(log), sep = "\n", file = stderr()) |
| 82 | + } |
| 83 | + |
| 84 | + checkEquals(result, 0L) |
| 85 | + } |
| 86 | + |
| 87 | +} |
0 commit comments