Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 测试脚本如何通知R CMD check它应该发出自定义消息?_Unit Testing_R_Cran - Fatal编程技术网

Unit testing 测试脚本如何通知R CMD check它应该发出自定义消息?

Unit testing 测试脚本如何通知R CMD check它应该发出自定义消息?,unit-testing,r,cran,Unit Testing,R,Cran,我正在办公室写一个R包()。我们正在使用它进行单元测试 我们描述新功能的过程:我们定义新的单元测试,最初标记为停用;我们一次激活一个测试块,并实现测试描述的功能。几乎所有的时间我们都有少量的停用测试,相对于可能被删除或将被实现的功能 我的问题是:如果有停用的测试,我是否可以更改以使R CMD check pkg发出注释(即自定义消息“NOTE”而不是“OK”) 到目前为止,我们只看到活动测试没有给出错误: . . * checking for unstated dependencies in t

我正在办公室写一个R包()。我们正在使用它进行单元测试

我们描述新功能的过程:我们定义新的单元测试,最初标记为
停用
;我们一次激活一个测试块,并实现测试描述的功能。几乎所有的时间我们都有少量的停用测试,相对于可能被删除或将被实现的功能

我的问题是:如果有停用的测试,我是否可以更改以使
R CMD check pkg
发出注释(即自定义消息“NOTE”而不是“OK”)

到目前为止,我们只看到活动测试没有给出错误:

.
.
* checking for unstated dependencies in tests ... OK
* checking tests ...
  Running ‘doSvUnit.R’
 OK
* checking PDF version of manual ... OK
如果所有的测试都成功了,这是可以的,但是如果有跳过的测试,这就不太好了,如果有失败的测试,这肯定是错误的。在这种情况下,我希望看到一个注释或警告,如下所示:

.
.
* checking for unstated dependencies in tests ... OK
* checking tests ...
  Running ‘doSvUnit.R’
 NOTE
6 test(s) were skipped.
 WARNING
1 test(s) are failing.
* checking PDF version of manual ... OK
现在,我们必须打开
doSvUnit.Rout
来检查实际的测试结果



我联系了r-forge和CRAN的两名维护人员,他们向我指出了问题所在,特别是脚本

如果我理解正确,要回答这个问题,我们需要修补
工具
包:

  • 使用
    系统调用调用tests目录中的脚本
  • 输出(stdout和stderr)转到单个文件
  • 有两种可能的结果:正常不正常
所以我在R上打开了一个,提出了一些类似于对返回状态进行位编码的建议,0位表示错误(现在是这样),1位表示警告,2位表示注释

通过我的修改,可以轻松生成以下输出:

.
.
* checking for unstated dependencies in tests ... OK
* checking tests ...
  Running ‘doSvUnit.R’
 NOTE - please check doSvUnit.Rout.
 WARNING - please check doSvUnit.Rout.
* checking PDF version of manual ... OK

BrianRipley回答说:“但是有几个包都有正确编写的单元测试 请把这个讨论带到别处:R-bugs不是问问题的地方 并关闭了更改请求



有人有什么提示吗?

我联系了r-forge和CRAN的两位维护人员,他们向我指出了,特别是脚本

如果我理解正确:

  • 使用
    系统调用调用tests目录中的脚本
  • 输出(stdout和stderr)转到单个文件
  • 有两种可能的结果:正常不正常
  • 要回答这个问题,我们需要修补库/工具包

我在R上打开了a,我的第一个猜测类似于对返回状态进行位编码,0位表示错误(现在是这样),1位表示警告,2位表示注释

在doSvUnit.R中,如果失败,我将退出
状态为
,如果跳过测试,我将退出

该修补程序如下所示:

Index: src/library/tools/R/testing.R
===================================================================
--- src/library/tools/R/testing.R   (revision 57214)
+++ src/library/tools/R/testing.R   (working copy)
@@ -352,10 +352,16 @@
         } else
             cmd <- paste("LANGUAGE=C", "R_TESTS=startup.Rs", cmd)
         res <- system(cmd)
-        if (res) {
+        if (res%/%4 %% 2) {
+            message("NOTE")
+        }
+        if (res%/%2 %% 2) {
+            message("WARNING")
+        }
+        if (res %% 2) {
             file.rename(outfile, paste(outfile, "fail", sep="."))
             return(1L)
         }
         savefile <- paste(outfile, "save", sep = "." )
         if (file.exists(savefile)) {
             message("  Comparing ", sQuote(outfile), " to ",
索引:src/library/tools/R/testing.R
===================================================================
---src/library/tools/R/testing.R(修订版57214)
+++src/library/tools/R/testing.R(工作副本)
@@ -352,10 +352,16 @@
}否则

cmd您应该能够更改doSvUnit.R脚本,以至少发出您描述的警告和错误。您要做的是运行测试,然后检查测试运行程序的返回值,并让R代码调用warning()或stop()

有关如何使用RUnit完成此操作的示例,请查看Bioconductor存储库中的codetoolsBioC包。相关代码在inst/模板中,复制如下:

.test <- function(dir, pattern = ".*_test\\.R$")
{
    .failure_details <- function(result) {
        res <- result[[1L]]
        if (res$nFail > 0 || res$nErr > 0) {
            Filter(function(x) length(x) > 0,
                   lapply(res$sourceFileResults,
                          function(fileRes) {
                              names(Filter(function(x) x$kind != "success",
                                           fileRes))
                          }))
        } else list()
    }

    if (missing(dir)) {
        dir <- system.file("unitTests", package="@PKG@")
        if (!nzchar(dir)) {
            dir <- system.file("UnitTests", package="@PKG@")
            if (!nzchar(dir))
                stop("unable to find unit tests, no 'unitTests' dir")
        }
    }

    ## Run unit tests from the directory containing the test files.
    ## This allows tests to refer to data files with relative paths
    cwd <- getwd()
    on.exit(setwd(cwd))
    setwd(dir)

    require("RUnit", quietly=TRUE) || stop("RUnit package not found")
    RUnit_opts <- getOption("RUnit", list())
    RUnit_opts$verbose <- 0L
    RUnit_opts$silent <- TRUE
    RUnit_opts$verbose_fail_msg <- TRUE
    options(RUnit = RUnit_opts)
    suite <- defineTestSuite(name="@PKG@ RUnit Tests", dirs=getwd(),
                             testFileRegexp=pattern,
                             rngKind="default",
                             rngNormalKind="default")
    result <- runTestSuite(suite)
    cat("\n\n")
    printTextProtocol(result, showDetails=FALSE)
    if (length(details <- .failure_details(result)) >0) {
        cat("\nTest files with failing tests\n")
        for (i in seq_along(details)) {
            cat("\n  ", basename(names(details)[[i]]), "\n")
            for (j in seq_along(details[[i]])) {
                cat("    ", details[[i]][[j]], "\n")
            }
        }
        cat("\n\n")
        stop("unit tests failed for package @PKG@")
    }
    result
}
。测试0,
lapply(res$sourceFileResults,
函数(fileRes){
名称(过滤器(函数(x)x$kind!=“成功”,
(文件)
}))
}else列表()
}
如果(缺失(目录)){

dir你所说的注释是什么意思?就像电脑扬声器发出的声音一样?编辑问题来解释注释,与OK相反,但没有警告那么糟糕。只是一个注释:我已经实现了一个解决方案,解决了一个稍微相反的问题,即,在手册页面中的示例的单元测试中有所意识。这是svUnit的一部分。Brian Ripley可能是指有道理,我可能会这么做。如果20位投票人中的一些人支持这个改变请求(或者在这里提供更多反馈),那就太好了。好的,我已经向svUnit添加了代码,允许它生成测试用例的完整xml报告,但我认为您无法在不更改检查的情况下提供我描述的反馈。R.如果您说我应该能够这样做,请抓取
delftfews
项目,它当前包含两个
测试和测试这不是你的主意,我不是从你提供的例子中得到的。但是谢谢你的努力。赛斯,你测试了你的建议吗?据我所说,这个的输出只是进入
out
日志,而不是控制台。