Ant*_*ean 4 msbuild msbuild-task
我有一个带有单个被忽略测试的小型NUnit测试套件。我现在正在编写一个简单的MSBuild脚本来还原和发布等。我试图让dotnet test任务正常工作
<Target Name="test" DependsOnTargets="restore">
<Exec Command="dotnet test"
WorkingDirectory="test\Example.Tests" />
</Target>
Run Code Online (Sandbox Code Playgroud)
但是,每次都以代码-1退出!
PS> dotnet msbuild /t:test build.xml
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 50.88 ms for C:\...\src\Example\Example.csproj.
Restore completed in 57.18 ms for C:\...\test\Example.Tests\Example.Tests.csproj.
Build started, please wait...
Build completed.
Test run for C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll
NUnit3TestExecutor converted 26 of 26 NUnit test cases
Skipped FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
EXEC : error Message: [C:\...\build.xml]
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog
NUnit Adapter 3.8.0.0: Test execution complete
Total tests: 26. Passed: 25. Failed: 0. Skipped: 1.
Test Run Successful.
Test execution time: 2.8322 Seconds
C:\...\build.xml(16,9): error MSB3073: The command "dotnet test" exited with code -1.
Run Code Online (Sandbox Code Playgroud)
如果我直接在控制台中运行命令,就可以了。
PS> dotnet test
Build started, please wait...
Build completed.
Test run for C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll
NUnit3TestExecutor converted 26 of 26 NUnit test cases
Skipped FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog
NUnit Adapter 3.8.0.0: Test execution complete
Total tests: 26. Passed: 25. Failed: 0. Skipped: 1.
Test Run Successful.
Test execution time: 3.6485 Seconds
Run Code Online (Sandbox Code Playgroud)
我四处寻找帮助,但没有发现任何明确的内容。我得到的印象是,Exec任务在 STDOUT中搜索某种错误消息,可能只是单词“ error”,以便设置退出代码/状态。
这确实出现在我的控制台上(出于某些原因,NUnit为忽略/跳过的测试打印“错误消息”)。
Skipped FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog
Run Code Online (Sandbox Code Playgroud)
如果我注释掉此测试,则运行通过(通过msbuild)。
我对Exec任务是否正确?我会通过覆盖CustomErrorRegularExpression参数来“解决”问题吗?我找不到有关此参数的任何好信息...我可以将其设置为空字符串吗?
如果提供了,请先针对和Exec 检查输出。如果不匹配或未提供,则使用以下RegEx:CustomErrorRegularExpressionCustomWarningRegularExpressionExec
new Regex
(
// Beginning of line and any amount of whitespace.
@"^\s*"
// Match a [optional project number prefix 'ddd>'], single letter + colon + remaining filename, or
// string with no colon followed by a colon.
+ @"(((?<ORIGIN>(((\d+>)?[a-zA-Z]?:[^:]*)|([^:]*))):)"
// Origin may also be empty. In this case there's no trailing colon.
+ "|())"
// Match the empty string or a string without a colon that ends with a space
+ "(?<SUBCATEGORY>(()|([^:]*? )))"
// Match 'error' or 'warning'.
+ @"(?<CATEGORY>(error|warning))"
// Match anything starting with a space that's not a colon/space, followed by a colon.
// Error code is optional in which case "error"/"warning" can be followed immediately by a colon.
+ @"( \s*(?<CODE>[^: ]*))?\s*:"
// Whatever's left on this line, including colons.
+ "(?<TEXT>.*)$",
RegexOptions.IgnoreCase | RegexOptions.Compiled
)
Run Code Online (Sandbox Code Playgroud)
得出以下示例格式的行将被解释为错误或警告(取决于这两个单词中的哪一个在“目录”部分中)。
Main.cs(17,20):命令行警告CS0168:声明了变量'foo',但从未使用过 -------------- ------------ ------- ------ ----------- ----------------------------------- 起源子类别 代码文字
我将通过重写CustomErrorRegularExpression参数来“解决”问题吗?
编辑
(对我自己的问题:当我的第二句话直接与之相反时,为什么我最初在地球上说“是”?)
不。:)设置IgnoreStandardErrorWarningFormat为true。从您在问题中链接的文档:
IgnoreStandardErrorWarningFormat:可选Boolean参数。
- 如果为
false,则在输出中选择与标准错误/警告格式匹配的行,并将其记录为错误/警告。- 如果为
true,请禁用此行为。默认值为
false。
| 归档时间: |
|
| 查看次数: |
393 次 |
| 最近记录: |