SCM

SCM Repository

[inlinedocs] Annotation of /pkg/inlinedocs/R/test.R
ViewVC logotype

Annotation of /pkg/inlinedocs/R/test.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 274 - (view) (download)

1 : tdhock 110 test.file <- function
2 :     ### Check an R code file with inlinedocs to see if the
3 :     ### extract.docs.file parser accurately extracts all the code inside!
4 :     ### The code file should contain a variable .result which is the
5 :     ### documentation list that you should get when you apply
6 :     ### extract.docs.file to the file. We check for identity of elements
7 :     ### of elements of the list, so the order of elements should not
8 :     ### matter, and thus this should be a good robust unit test.
9 : tdhock 113 (f,
10 : tdhock 110 ### File name of R code file with inlinedocs to parse and check.
11 : tdhock 113 verbose=TRUE
12 :     ### Show output?
13 : tdhock 110 ){
14 :     e <- new.env()
15 : tdhock 156 suppressWarnings(sys.source(f,e))
16 : tdhock 110 ## these are the items to check for, in no particular order
17 :     .result <- e$.result
18 : tdhock 239 parsers <- e$.parsers
19 :     result <- extract.docs.file(f,parsers)
20 : tdhock 113 for(FUN in names(.result)){
21 :     if(verbose)cat(FUN,"")
22 : tdhock 138 fun <- result[[FUN]]
23 :     .fun <- .result[[FUN]]
24 :     ## first check to make sure all the stored items are there
25 :     for(N in names(.fun)){
26 :     .res <- .fun[[N]]
27 :     res <- fun[[N]]
28 :     if(is.null(res) || is.na(res) || is.na(.res) || .res!=res){
29 : tdhock 113 stop(f,":\n\n",res,"\nin ",FUN,"$",N,", expected:\n\n",.res,"\n")
30 :     }
31 : tdhock 110 }
32 : tdhock 138 ## now check and see if there are no additional items!
33 :     additional <- !names(fun)%in%names(.fun)
34 :     show <- fun[additional] ##ignore NULL extracted items
35 :     show <- show[!sapply(show,is.null)]
36 :     if(length(show)){
37 :     cat("\n")
38 :     print(show)
39 :     stop("extracted some unexpected docs!")
40 :     }
41 : tdhock 110 }
42 : tdhock 202 ## make sure there are no unexpected outer lists
43 :     not.expected <- names(result)[!names(result)%in%names(.result)]
44 :     if(length(not.expected)){
45 :     print(not.expected)
46 :     stop("extracted some unexpected documentation objects!")
47 :     }
48 : tdhock 156 ## finally make a package using this file and see if it passes
49 :     ## without warnings
50 :     if(!is.null(e$.dontcheck))return()
51 : tdhock 247 make.package.and.check(f,parsers,verbose)
52 : tdhock 239 if(verbose)cat("\n")
53 :     }
54 :    
55 : tdhock 249 make.package.and.check <- function
56 :     ### Assemble some R code into a package and process it using R CMD
57 :     ### check, stopping with an error if the check resulted in any errors
58 :     ### or warnings.
59 :     (f, ##<< R code file name from which we will make a package
60 :     parsers=default.parsers,
61 :     ### Parsers to use to make the package documentation.
62 :     verbose=TRUE
63 :     ### print the check command line?
64 :     ){
65 : tdhock 274 print(f)
66 :     pkgname <- sub("[.][rR]$","",basename(f))
67 :     print(pkgname)
68 : tdhock 156 pkgdir <- file.path(tempdir(),pkgname)
69 : tdhock 274 print(pkgdir)
70 : tdhock 156 if(file.exists(pkgdir))unlink(pkgdir,recursive=TRUE)
71 :     rdir <- file.path(pkgdir,"R")
72 : tdhock 274 print(rdir)
73 : tdhock 156 dir.create(rdir,recursive=TRUE)
74 : tdhock 274 desc <- system.file(file.path("silly","DESCRIPTION"),package="inlinedocs")
75 : tdhock 156 file.copy(desc,pkgdir)
76 :     file.copy(f,rdir)
77 : tdhock 239 package.skeleton.dx(pkgdir,parsers)
78 : tdhock 156 cmd <- sprintf("%s CMD check %s",file.path(R.home("bin"), "R"),pkgdir)
79 :     if(verbose)cat(cmd,"\n")
80 :     checkLines <- system(cmd,intern=TRUE)
81 :     warnLines <- grep("WARNING",checkLines,value=TRUE)
82 :     if(length(warnLines)>0){
83 :     print(warnLines)
84 :     stop("WARNING encountered in package check!")
85 :     }
86 : tdhock 110 }
87 : tdhock 156
88 : tdhock 111 save.test.result <- function
89 :     ### For unit tests, this is an easy way of getting a text
90 :     ### representation of the list result of extract.docs.file.
91 :     (f
92 :     ### R code file with inlinedocs to process with extract.docs.file.
93 :     ){
94 : tdhock 113 .result <- extract.docs.file(f)
95 : tdhock 118 dump(".result",tmp <- tempfile(),control=NULL)
96 :     lines <- readLines(tmp)
97 : tdhock 113 cat(paste(lines,"\n"))
98 : tdhock 111 }

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge