Skip to content
Newer
Older
100644 101 lines (92 sloc) 3.86 KB
ff56dcb split up the slow reg-tests-1.R
ripley authored
1 ## PR 1271 detach("package:base") crashes R.
2 try(detach("package:base"))
3
4
5 ## invalid 'lib.loc'
6 stopifnot(length(installed.packages("mgcv")) == 0)
7 ## gave a low-level error message
8
9
10 ## package.skeleton() with metadata-only code
11 ## work in current (= ./tests/ directory):
12 tmp <- tempfile()
13 writeLines(c('setClass("foo", contains="numeric")',
14 'setMethod("show", "foo",',
15 ' function(object) cat("I am a \\"foo\\"\\n"))'),
16 tmp)
17 if(file.exists("myTst")) unlink("myTst", recursive=TRUE)
18 package.skeleton("myTst", code_files = tmp)# with a file name warning
19 file.copy(tmp, (tm2 <- paste(tmp,".R", sep="")))
20 unlink("myTst", recursive=TRUE)
21 op <- options(warn=2) # *NO* "invalid file name" warning {failed in 2.7.[01]}:
22 package.skeleton("myTst", code_files = tm2, namespace=TRUE)
23 options(op)
24 ##_2_ only a class, no generics/methods:
25 writeLines(c('setClass("DocLink",',
26 'representation(name="character",',
27 ' desc="character"))'), tmp)
28 if(file.exists("myTst2")) unlink("myTst2", recursive=TRUE)
29 package.skeleton("myTst2", code_files = tmp)
30 ##- end_2_ # failed in R 2.11.0
31 stopifnot(1 == grep("setClass",
32 readLines(list.files("myTst/R", full.names=TRUE))),
33 c("foo-class.Rd","show-methods.Rd") %in% list.files("myTst/man"))
34 ## failed for several reasons in R < 2.7.0
35 ##
36 ## Part 2: -- build, install, load and "inspect" the package:
812e5f1 do package tests on Windows
ripley authored
37 dir.exists <- function(x)
38 is.character(x) && file.exists(x) && file.info(path.expand(x))$isdir
39 build.pkg <- function(dir) {
40 stopifnot(dir.exists(dir))
26841fd remove naughty construct, allow empty dirs here
ripley authored
41 patt <- paste(basename(dir), ".*tar\\.gz$", sep="_")
42 unlink(dir('.', pattern = patt))
812e5f1 do package tests on Windows
ripley authored
43 Rcmd <- paste(file.path(R.home("bin"), "R"), "CMD")
26841fd remove naughty construct, allow empty dirs here
ripley authored
44 r <- tail(system(paste(Rcmd, "build --keep-empty-dirs", dir),
45 intern = TRUE), 3)
812e5f1 do package tests on Windows
ripley authored
46 ## return name of tar file built
26841fd remove naughty construct, allow empty dirs here
ripley authored
47 dir('.', pattern = patt)
812e5f1 do package tests on Windows
ripley authored
48 }
49 build.pkg("myTst")
50 ## clean up any previous attempt (which might have left a 00LOCK)
51 unlink("myLib", recursive = TRUE)
52 dir.create("myLib")
53 install.packages("myTst", lib = "myLib", repos=NULL, type = "source") # with warnings
54 print(installed.packages(lib.loc= "myLib", priority= "NA"))## (PR#13332)
55 stopifnot(require("myTst",lib = "myLib"))
b14cc87 add regression test for the Sweave fix in r53494
maechler authored
56 sm <- findMethods(show, where= as.environment("package:myTst"))
57 stopifnot(names(sm@names) == "foo")
812e5f1 do package tests on Windows
ripley authored
58 unlink("myTst_*")
ff56dcb split up the slow reg-tests-1.R
ripley authored
59
812e5f1 do package tests on Windows
ripley authored
60 ## More building & installing packages
61 ## NB: tests were added here for 2.11.0.
62 ## NB^2: do not do this in the R sources!
63 ## and this testdir is not installed.
64 pkgSrcPath <- file.path(Sys.getenv("SRCDIR"), "Pkgs")
65 if(file_test("-d", pkgSrcPath)) {
66 ## could use file.copy(recursive = TRUE)
b14cc87 add regression test for the Sweave fix in r53494
maechler authored
67 system(paste('cp -r', shQuote(pkgSrcPath), shQuote(tempdir())))
812e5f1 do package tests on Windows
ripley authored
68 pkgPath <- file.path(tempdir(), "Pkgs")
e9fc47d there really should be warnings!
ripley authored
69 # op <- options(warn = 2) # There should be *NO* warnings here!
812e5f1 do package tests on Windows
ripley authored
70 ## pkgB tests an empty R directory
71 dir.create(file.path(pkgPath, "pkgB", "R"), recursive = TRUE,
72 showWarnings = FALSE)
607aa7e Pointless testing a package without a namespace
ripley authored
73 p.lis <- c("pkgA", "pkgB", "exNSS4")
812e5f1 do package tests on Windows
ripley authored
74 for(p. in p.lis) {
75 cat("building package", p., "...\n")
76 r <- build.pkg(file.path(pkgPath, p.))
77 cat("installing package", p., "using file", r, "...\n")
78 ## we could install the tar file ... (see build.pkg()'s definition)
79 install.packages(r, lib = "myLib", repos=NULL, type = "source")
80 stopifnot(require(p.,lib = "myLib", character.only=TRUE))
81 detach(pos = match(p., sub("^package:","", search())))
ff56dcb split up the slow reg-tests-1.R
ripley authored
82 }
812e5f1 do package tests on Windows
ripley authored
83 ## TODO: not just print, but check the "list":
607aa7e Pointless testing a package without a namespace
ripley authored
84 res <- installed.packages(lib.loc = "myLib", priority = "NA")
85 print(res)
e9fc47d there really should be warnings!
ripley authored
86 # options(op)
812e5f1 do package tests on Windows
ripley authored
87 unlink("myLib", recursive = TRUE)
88 unlink(file.path(pkgPath), recursive = TRUE)
ff56dcb split up the slow reg-tests-1.R
ripley authored
89 }
90 unlink("myTst", recursive=TRUE)
91
92
93 ## getPackageName() for "package:foo":
94 require('methods')
95 library(tools)
96 oo <- options(warn=2)
97 detach("package:tools", unload=TRUE)
98 options(oo)
99 ## gave warning (-> Error) about creating package name
100
Something went wrong with that request. Please try again.