Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d3c0ccc4
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d3c0ccc4
编写于
10月 07, 2015
作者:
J
Jared Parsons
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better diagnostics for test runner
上级
5641bf70
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
68 addition
and
61 deletion
+68
-61
src/Tools/Source/RunTests/TestRunner.cs
src/Tools/Source/RunTests/TestRunner.cs
+68
-61
未找到文件。
src/Tools/Source/RunTests/TestRunner.cs
浏览文件 @
d3c0ccc4
...
...
@@ -123,78 +123,85 @@ private void Print(List<TestResult> testResults)
private
async
Task
<
TestResult
>
RunTest
(
string
assemblyPath
,
CancellationToken
cancellationToken
)
{
var
assemblyName
=
Path
.
GetFileName
(
assemblyPath
);
var
extension
=
_useHtml
?
".TestResults.html"
:
".TestResults.xml"
;
var
resultsPath
=
Path
.
Combine
(
Path
.
GetDirectoryName
(
assemblyPath
),
Path
.
ChangeExtension
(
assemblyName
,
extension
));
DeleteFile
(
resultsPath
);
var
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
@"""{0}"""
,
assemblyPath
);
builder
.
AppendFormat
(
@" -{0} ""{1}"""
,
_useHtml
?
"html"
:
"xml"
,
resultsPath
);
builder
.
Append
(
" -noshadow"
);
var
errorOutput
=
new
StringBuilder
();
var
start
=
DateTime
.
UtcNow
;
var
xunitPath
=
UpgradedTests
.
Contains
(
assemblyName
)
?
Path
.
Combine
(
$"
{
Path
.
GetDirectoryName
(
_xunitConsolePath
)}
"
,
@"..\..\..\xunit.runner.console\2.1.0-beta4-build3109\tools"
,
$"
{
Path
.
GetFileName
(
_xunitConsolePath
)}
"
)
:
_xunitConsolePath
;
var
processOutput
=
await
ProcessRunner
.
RunProcessAsync
(
xunitPath
,
builder
.
ToString
(),
lowPriority
:
false
,
displayWindow
:
false
,
captureOutput
:
true
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
var
span
=
DateTime
.
UtcNow
-
start
;
if
(
processOutput
.
ExitCode
!=
0
)
{
// On occasion we get a non-0 output but no actual data in the result file. The could happen
// if xunit manages to crash when running a unit test (a stack overflow could cause this, for instance).
// To avoid losing information, write the process output to the console. In addition, delete the results
// file to avoid issues with any tool attempting to interpret the (potentially malformed) text.
var
all
=
string
.
Empty
;
try
{
all
=
File
.
ReadAllText
(
resultsPath
).
Trim
();
}
catch
try
{
var
assemblyName
=
Path
.
GetFileName
(
assemblyPath
);
var
extension
=
_useHtml
?
".TestResults.html"
:
".TestResults.xml"
;
var
resultsPath
=
Path
.
Combine
(
Path
.
GetDirectoryName
(
assemblyPath
),
Path
.
ChangeExtension
(
assemblyName
,
extension
));
DeleteFile
(
resultsPath
);
var
builder
=
new
StringBuilder
();
builder
.
AppendFormat
(
@"""{0}"""
,
assemblyPath
);
builder
.
AppendFormat
(
@" -{0} ""{1}"""
,
_useHtml
?
"html"
:
"xml"
,
resultsPath
);
builder
.
Append
(
" -noshadow"
);
var
errorOutput
=
new
StringBuilder
();
var
start
=
DateTime
.
UtcNow
;
var
xunitPath
=
UpgradedTests
.
Contains
(
assemblyName
)
?
Path
.
Combine
(
$"
{
Path
.
GetDirectoryName
(
_xunitConsolePath
)}
"
,
@"..\..\..\xunit.runner.console\2.1.0-beta4-build3109\tools"
,
$"
{
Path
.
GetFileName
(
_xunitConsolePath
)}
"
)
:
_xunitConsolePath
;
var
processOutput
=
await
ProcessRunner
.
RunProcessAsync
(
xunitPath
,
builder
.
ToString
(),
lowPriority
:
false
,
displayWindow
:
false
,
captureOutput
:
true
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
var
span
=
DateTime
.
UtcNow
-
start
;
if
(
processOutput
.
ExitCode
!=
0
)
{
// Happens if xunit didn't produce a log file
}
// On occasion we get a non-0 output but no actual data in the result file. The could happen
// if xunit manages to crash when running a unit test (a stack overflow could cause this, for instance).
// To avoid losing information, write the process output to the console. In addition, delete the results
// file to avoid issues with any tool attempting to interpret the (potentially malformed) text.
var
all
=
string
.
Empty
;
try
{
all
=
File
.
ReadAllText
(
resultsPath
).
Trim
();
}
catch
{
// Happens if xunit didn't produce a log file
}
bool
noResultsData
=
(
all
.
Length
==
0
);
if
(
noResultsData
)
{
var
output
=
processOutput
.
OutputLines
.
Concat
(
processOutput
.
ErrorLines
);
Console
.
Write
(
string
.
Join
(
Environment
.
NewLine
,
output
));
bool
noResultsData
=
(
all
.
Length
==
0
);
if
(
noResultsData
)
{
var
output
=
processOutput
.
OutputLines
.
Concat
(
processOutput
.
ErrorLines
);
Console
.
Write
(
string
.
Join
(
Environment
.
NewLine
,
output
));
// Delete the output file.
File
.
Delete
(
resultsPath
);
}
// Delete the output file.
File
.
Delete
(
resultsPath
);
}
errorOutput
.
AppendLine
(
$"Command:
{
_xunitConsolePath
}
{
builder
}
"
);
errorOutput
.
AppendLine
(
$"Command:
{
_xunitConsolePath
}
{
builder
}
"
);
if
(
processOutput
.
ErrorLines
.
Any
())
{
foreach
(
var
line
in
processOutput
.
ErrorLines
)
if
(
processOutput
.
ErrorLines
.
Any
())
{
errorOutput
.
AppendLine
(
line
);
foreach
(
var
line
in
processOutput
.
ErrorLines
)
{
errorOutput
.
AppendLine
(
line
);
}
}
else
{
errorOutput
.
AppendLine
(
$"xunit produced no error output but had exit code
{
processOutput
.
ExitCode
}
"
);
}
}
else
{
errorOutput
.
AppendLine
(
$"xunit produced no error output but had exit code
{
processOutput
.
ExitCode
}
"
);
}
// If the results are html, use Process.Start to open in the browser.
// If the results are html, use Process.Start to open in the browser.
if
(
_useHtml
&&
!
noResultsData
)
{
Process
.
Start
(
resultsPath
);
if
(
_useHtml
&&
!
noResultsData
)
{
Process
.
Start
(
resultsPath
);
}
}
}
return
new
TestResult
(
processOutput
.
ExitCode
==
0
,
assemblyName
,
span
,
errorOutput
.
ToString
());
return
new
TestResult
(
processOutput
.
ExitCode
==
0
,
assemblyName
,
span
,
errorOutput
.
ToString
());
}
catch
(
Exception
ex
)
{
throw
new
Exception
(
$"Unable to run
{
assemblyPath
}
"
,
ex
);
}
}
private
static
void
DeleteFile
(
string
filePath
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录