使用dotCover进行代码覆盖会引发错误-FAKE F#MAKE [英] Code coverage using dotCover throws an error - FAKE F#MAKE

查看:107
本文介绍了使用dotCover进行代码覆盖会引发错误-FAKE F#MAKE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在FAKE中使用DotCover,但是它会引发一些错误,因为我对FAKE和F#还是陌生的,这使我越来越难以理解问题的根本原因.这是代码:

 #r "D:/FAKEProject/Fake/packages/FAKE/tools/FakeLib.dll"
    open Fake
    open Fake.DotCover
    let testDir = "D:/FAKEProject/Fake/test/"
    let filters = ""
    Target "Clean" (fun _ ->
        CleanDirs [testDir]
    )
    Target "TestCoverage" (fun _ ->
        !! ("D:/FAKEProject/Fake/UnitTest/UnitTest.dll")
            |> DotCoverNUnit
                (fun p -> { p with Output = testDir @@ "NUnitDotCover.snapshot"
                                   ToolPath = "D:/tools/dotCover/dotCover.exe"
                                   Filters = filters })                              
                (fun nunitOptions -> nunitOptions)
    )
    "Clean"
        ==> "TestCoverage"
    RunTargetOrDefault "TestCoverage"`

出现此错误

System.Exception: Error running D:/tools/dotCover/dotCover.exe with exitcode -1
   at Fake.DotCover.buildParamsAndExecute@124-6.Invoke(String message) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 124
   at Fake.DotCover.buildParamsAndExecute[a](a parameters, FSharpFunc`2 buildArguments, String toolPath, String workingDir, Boolean failBuild) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 124
   at Fake.DotCover.DotCoverNUnit(FSharpFunc`2 setDotCoverParams, FSharpFunc`2 setNUnitParams, IEnumerable`1 assemblies) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 190
   at FSI_0005.DotCover.clo@16-2.Invoke(Unit _arg2) in D:\FAKEProject\Fake\DotCover.fsx:line 17
   at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 492`

我不明白为什么要在C:\ code \ fake \ src \ app \ fakelib \ dotcover.fs中搜索 而它正在寻找的dotcover.fs是什么 如何解决这个问题,因为我一直陷在这个错误中,如果有人可以在这方面帮助我,那将非常有帮助.

谢谢

解决方案

神秘的C:\code\fake\src\app\FakeLib\DotCover.fs行只是告诉您引发错误的源文件的文件名(和行号).不是您的系统上的文件名,而是构建您的FAKE.exe文件的系统上的文件名.换句话说,它只是在告诉您从何处引发了异常.

查看FAKE源代码,我发现第124行位于以下代码块的结尾附近:

let buildParamsAndExecute parameters buildArguments toolPath workingDir failBuild =
    let args = buildArguments parameters
    trace (toolPath + " " + args)
    let result = ExecProcess (fun info ->  
              info.FileName <- toolPath
              info.WorkingDirectory <- getWorkingDir workingDir
              info.Arguments <- args) TimeSpan.MaxValue
    let ExitCodeForFailedTests = -3
    if (result = ExitCodeForFailedTests && not failBuild) then 
        trace (sprintf "DotCover %s exited with errorcode %d" toolPath result)
    else if (result = ExitCodeForFailedTests && failBuild) then 
        failwithf "Failing tests, use ErrorLevel.DontFailBuild to ignore failing tests. Exited %s with errorcode %d" toolPath result
    else if (result <> 0) then 
        failwithf "Error running %s with exitcode %d" toolPath result
    else 
        trace (sprintf "DotCover exited successfully")

failwithf函数与F#等效于"throw new Exception()",但是它允许您指定一条消息(使用printfn样式的格式代码,如%s)与该异常一起发送.因此,F#中没有什么神秘的事情发生,只是您的D:/tools/dotCover/dotCover.exe程序返回了-1返回码.返回代码-1通常表示一般错误",因此对找出原因没有太大帮助.

您的下一个故障排除步骤是手动运行您的dotCover.exe程序,并为其赋予与FAKE相同的参数(不应该太难弄清,因为FAKE选项记录通常用很好的名字命名)和相同的输入.然后查看dotCover.exe在失败之前会打印出什么错误消息(如果有).

I am trying to use DotCover in FAKE , but it is throwing some error , as I am new to FAKE as well as F# , it's becoming difficult for me to understand the root cause of the problem . Here is the code :

 #r "D:/FAKEProject/Fake/packages/FAKE/tools/FakeLib.dll"
    open Fake
    open Fake.DotCover
    let testDir = "D:/FAKEProject/Fake/test/"
    let filters = ""
    Target "Clean" (fun _ ->
        CleanDirs [testDir]
    )
    Target "TestCoverage" (fun _ ->
        !! ("D:/FAKEProject/Fake/UnitTest/UnitTest.dll")
            |> DotCoverNUnit
                (fun p -> { p with Output = testDir @@ "NUnitDotCover.snapshot"
                                   ToolPath = "D:/tools/dotCover/dotCover.exe"
                                   Filters = filters })                              
                (fun nunitOptions -> nunitOptions)
    )
    "Clean"
        ==> "TestCoverage"
    RunTargetOrDefault "TestCoverage"`

It is giving this error

System.Exception: Error running D:/tools/dotCover/dotCover.exe with exitcode -1
   at Fake.DotCover.buildParamsAndExecute@124-6.Invoke(String message) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 124
   at Fake.DotCover.buildParamsAndExecute[a](a parameters, FSharpFunc`2 buildArguments, String toolPath, String workingDir, Boolean failBuild) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 124
   at Fake.DotCover.DotCoverNUnit(FSharpFunc`2 setDotCoverParams, FSharpFunc`2 setNUnitParams, IEnumerable`1 assemblies) in C:\code\fake\src\app\FakeLib\DotCover.fs:line 190
   at FSI_0005.DotCover.clo@16-2.Invoke(Unit _arg2) in D:\FAKEProject\Fake\DotCover.fsx:line 17
   at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 492`

I am not able to understand why it is searching in C:\code\fake\src\app\fakelib\dotcover.fs and what is dotcover.fs it is looking for How to solve this problem , as I am stuck at this error , If anyone can help me regarding this , it would be very helpful .

Thank You

解决方案

The mysterious C:\code\fake\src\app\FakeLib\DotCover.fs line is simply telling you the filename (and line number) of the source file that threw the error. Not the filename on your system, but the filename on the system where your FAKE.exe file was built. In other words, it's just telling you where the exception was thrown from.

Looking at the FAKE source code, I see that line 124 is near the end of the following block of code:

let buildParamsAndExecute parameters buildArguments toolPath workingDir failBuild =
    let args = buildArguments parameters
    trace (toolPath + " " + args)
    let result = ExecProcess (fun info ->  
              info.FileName <- toolPath
              info.WorkingDirectory <- getWorkingDir workingDir
              info.Arguments <- args) TimeSpan.MaxValue
    let ExitCodeForFailedTests = -3
    if (result = ExitCodeForFailedTests && not failBuild) then 
        trace (sprintf "DotCover %s exited with errorcode %d" toolPath result)
    else if (result = ExitCodeForFailedTests && failBuild) then 
        failwithf "Failing tests, use ErrorLevel.DontFailBuild to ignore failing tests. Exited %s with errorcode %d" toolPath result
    else if (result <> 0) then 
        failwithf "Error running %s with exitcode %d" toolPath result
    else 
        trace (sprintf "DotCover exited successfully")

The failwithf function is F#'s equivalent of "throw new Exception()", but it lets you specify a message (using printfn-style format codes like %s) to go with the exception. So there's nothing mysterious going on here in F#, it's just that your D:/tools/dotCover/dotCover.exe program has returned a -1 return code. Return codes of -1 usually mean "generic error", so that's not much help in figuring out the cause.

Your next troubleshooting step is to run your dotCover.exe program manually, giving it the same arguments that FAKE is giving it (shouldn't be too hard to figure out, since the FAKE option records are usually pretty well-named) and the same input. Then see what error messages, if any, dotCover.exe is printing out before it fails.

这篇关于使用dotCover进行代码覆盖会引发错误-FAKE F#MAKE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆