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 155 - (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 :     result <- extract.docs.file(f)
15 :     e <- new.env()
16 :     sys.source(f,e)
17 :     ## these are the items to check for, in no particular order
18 :     .result <- e$.result
19 : tdhock 113 for(FUN in names(.result)){
20 :     if(verbose)cat(FUN,"")
21 : tdhock 138 fun <- result[[FUN]]
22 :     .fun <- .result[[FUN]]
23 :     ## first check to make sure all the stored items are there
24 :     for(N in names(.fun)){
25 :     .res <- .fun[[N]]
26 :     res <- fun[[N]]
27 :     if(is.null(res) || is.na(res) || is.na(.res) || .res!=res){
28 : tdhock 113 stop(f,":\n\n",res,"\nin ",FUN,"$",N,", expected:\n\n",.res,"\n")
29 :     }
30 : tdhock 110 }
31 : tdhock 138 ## now check and see if there are no additional items!
32 :     additional <- !names(fun)%in%names(.fun)
33 :     show <- fun[additional] ##ignore NULL extracted items
34 :     show <- show[!sapply(show,is.null)]
35 :     if(length(show)){
36 :     cat("\n")
37 :     print(show)
38 :     stop("extracted some unexpected docs!")
39 :     }
40 : tdhock 110 }
41 : tdhock 113 if(verbose)cat("\n")
42 : tdhock 110 }
43 : tdhock 111 save.test.result <- function
44 :     ### For unit tests, this is an easy way of getting a text
45 :     ### representation of the list result of extract.docs.file.
46 :     (f
47 :     ### R code file with inlinedocs to process with extract.docs.file.
48 :     ){
49 : tdhock 113 .result <- extract.docs.file(f)
50 : tdhock 118 dump(".result",tmp <- tempfile(),control=NULL)
51 :     lines <- readLines(tmp)
52 : tdhock 113 cat(paste(lines,"\n"))
53 : 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