SCM

SCM Repository

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

Diff of /pkg/inlinedocs/R/test.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 111, Mon Jun 7 12:33:37 2010 UTC revision 138, Tue Oct 19 22:51:59 2010 UTC
# Line 6  Line 6 
6  ### extract.docs.file to the file. We check for identity of elements  ### 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  ### of elements of the list, so the order of elements should not
8  ### matter, and thus this should be a good robust unit test.  ### matter, and thus this should be a good robust unit test.
9  (f  (f,
10  ### File name of R code file with inlinedocs to parse and check.  ### File name of R code file with inlinedocs to parse and check.
11     verbose=TRUE
12    ### Show output?
13   ){   ){
14    result <- extract.docs.file(f)    result <- extract.docs.file(f)
15    e <- new.env()    e <- new.env()
16    sys.source(f,e)    sys.source(f,e)
17    ## these are the items to check for, in no particular order    ## these are the items to check for, in no particular order
18    .result <- e$.result    .result <- e$.result
19    for(FUN in names(.result))for(N in names(.result[[FUN]])){    for(FUN in names(.result)){
20      .res <- .result[[FUN]][[N]]      if(verbose)cat(FUN,"")
21      res <- result[[FUN]][[N]]      fun <- result[[FUN]]
22      if(is.null(res) || .res!=res){      .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        stop(f,":\n\n",res,"\nin ",FUN,"$",N,", expected:\n\n",.res,"\n")        stop(f,":\n\n",res,"\nin ",FUN,"$",N,", expected:\n\n",.res,"\n")
29      }      }
30    }    }
31        ## 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      }
41      if(verbose)cat("\n")
42  }  }
43  save.test.result <- function  save.test.result <- function
44  ### For unit tests, this is an easy way of getting a text  ### For unit tests, this is an easy way of getting a text
# Line 28  Line 46 
46  (f  (f
47  ### R code file with inlinedocs to process with extract.docs.file.  ### R code file with inlinedocs to process with extract.docs.file.
48   ){   ){
49    L <- extract.docs.file(f)    .result <- extract.docs.file(f)
50    dump("L",control=NULL)    dump(".result",tmp <- tempfile(),control=NULL)
51    lines <- readLines("dumpdata.R")    lines <- readLines(tmp)
52    cat(lines)    cat(paste(lines,"\n"))
53  }  }

Legend:
Removed from v.111  
changed lines
  Added in v.138

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