Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
17736ac4
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,发现更多精彩内容 >>
提交
17736ac4
编写于
9月 09, 2020
作者:
N
Niko Schuessler
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix "copy" constructor and affected tests.
上级
f5684bb3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
14 deletion
+26
-14
src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticSuppressorTests.cs
...rp/Test/Semantic/Diagnostics/DiagnosticSuppressorTests.cs
+24
-12
src/Test/Utilities/Portable/Diagnostics/DiagnosticDescription.cs
...t/Utilities/Portable/Diagnostics/DiagnosticDescription.cs
+2
-2
未找到文件。
src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticSuppressorTests.cs
浏览文件 @
17736ac4
...
...
@@ -51,14 +51,14 @@ void M(int i)
compilation
.
VerifyDiagnostics
(
// (7,9): warning CS1522: Empty switch block
// {
Diagnostic
(
ErrorCode
.
WRN_EmptySwitch
,
"{"
).
WithLocation
(
7
,
9
));
Diagnostic
(
ErrorCode
.
WRN_EmptySwitch
,
"{"
,
isSuppressed
:
false
).
WithLocation
(
7
,
9
));
// Verify compiler syntax warning can be suppressed with a suppressor.
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
DiagnosticSuppressorForId
(
"CS1522"
)
};
VerifySuppressedDiagnostics
(
compilation
,
analyzers
,
// (7,9): warning CS1522: Empty switch block
// {
Diagnostic
(
"CS1522"
,
"{"
).
WithLocation
(
7
,
9
));
Diagnostic
(
"CS1522"
,
"{"
,
isSuppressed
:
true
).
WithLocation
(
7
,
9
));
}
[
Fact
,
WorkItem
(
20242
,
"https://github.com/dotnet/roslyn/issues/20242"
)]
...
...
@@ -74,14 +74,14 @@ class C
compilation
.
VerifyDiagnostics
(
// (5,26): warning CS0169: The field 'C.f' is never used
// private readonly int f;
Diagnostic
(
ErrorCode
.
WRN_UnreferencedField
,
"f"
).
WithArguments
(
"C.f"
).
WithLocation
(
5
,
26
));
Diagnostic
(
ErrorCode
.
WRN_UnreferencedField
,
"f"
,
isSuppressed
:
false
).
WithArguments
(
"C.f"
).
WithLocation
(
5
,
26
));
// Verify compiler semantic warning can be suppressed with a suppressor.
var
analyzers
=
new
DiagnosticAnalyzer
[]
{
new
DiagnosticSuppressorForId
(
"CS0169"
)
};
VerifySuppressedDiagnostics
(
compilation
,
analyzers
,
// (5,26): warning CS0169: The field 'C.f' is never used
// private readonly int f;
Diagnostic
(
"CS0169"
,
"f"
).
WithArguments
(
"C.f"
).
WithLocation
(
5
,
26
));
Diagnostic
(
"CS0169"
,
"f"
,
isSuppressed
:
true
).
WithArguments
(
"C.f"
).
WithLocation
(
5
,
26
));
}
[
Fact
,
WorkItem
(
20242
,
"https://github.com/dotnet/roslyn/issues/20242"
)]
...
...
@@ -133,12 +133,16 @@ public void TestSuppression_MultipleDiagnostics()
var
analyzer
=
new
CompilationAnalyzerWithSeverity
(
DiagnosticSeverity
.
Warning
,
configurable
:
true
);
var
expectedDiagnostics
=
new
DiagnosticDescription
[]
{
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source1
),
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source2
)
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source1
,
isSuppressed
:
false
).
WithLocation
(
1
,
1
),
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source2
,
isSuppressed
:
false
).
WithLocation
(
1
,
1
),
};
VerifyAnalyzerDiagnostics
(
compilation
,
new
DiagnosticAnalyzer
[]
{
analyzer
},
expectedDiagnostics
);
var
analyzersAndSuppressors
=
new
DiagnosticAnalyzer
[]
{
analyzer
,
new
DiagnosticSuppressorForId
(
analyzer
.
Descriptor
.
Id
)
};
expectedDiagnostics
=
new
DiagnosticDescription
[]
{
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source1
,
isSuppressed
:
true
).
WithLocation
(
1
,
1
),
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source2
,
isSuppressed
:
true
).
WithLocation
(
1
,
1
),
};
VerifySuppressedDiagnostics
(
compilation
,
analyzersAndSuppressors
,
expectedDiagnostics
);
}
...
...
@@ -150,10 +154,11 @@ public void TestSuppression_MultipleSuppressors_SameDiagnostic()
compilation
.
VerifyDiagnostics
();
var
analyzer
=
new
CompilationAnalyzerWithSeverity
(
DiagnosticSeverity
.
Warning
,
configurable
:
true
);
var
expectedDiagnostic
=
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
);
var
expectedDiagnostic
=
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
,
isSuppressed
:
false
).
WithLocation
(
1
,
1
);
VerifyAnalyzerDiagnostics
(
compilation
,
new
DiagnosticAnalyzer
[]
{
analyzer
},
expectedDiagnostic
);
// Multiple suppressors with same suppression ID.
expectedDiagnostic
=
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
,
isSuppressed
:
true
).
WithLocation
(
1
,
1
);
var
analyzersAndSuppressors
=
new
DiagnosticAnalyzer
[]
{
analyzer
,
new
DiagnosticSuppressorForId
(
analyzer
.
Descriptor
.
Id
),
new
DiagnosticSuppressorForId
(
analyzer
.
Descriptor
.
Id
)
};
VerifySuppressedDiagnostics
(
compilation
,
analyzersAndSuppressors
,
expectedDiagnostic
);
...
...
@@ -181,8 +186,8 @@ public void TestSuppression_MultipleSuppressors_DifferentDiagnostic()
var
analyzersAndSuppressors
=
new
DiagnosticAnalyzer
[]
{
analyzer
,
suppressor1
,
suppresor2
};
VerifySuppressedDiagnostics
(
compilation
,
analyzersAndSuppressors
,
Diagnostic
(
"CS0169"
,
"f"
).
WithArguments
(
"C1.f"
).
WithLocation
(
1
,
33
),
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
));
Diagnostic
(
"CS0169"
,
"f"
,
isSuppressed
:
true
).
WithArguments
(
"C1.f"
).
WithLocation
(
1
,
33
),
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
,
isSuppressed
:
true
));
}
[
Fact
,
WorkItem
(
20242
,
"https://github.com/dotnet/roslyn/issues/20242"
)]
...
...
@@ -193,11 +198,12 @@ public void TestNoSuppression_SpecificOptionsTurnsOffSuppressor()
compilation
.
VerifyDiagnostics
();
var
analyzer
=
new
CompilationAnalyzerWithSeverity
(
DiagnosticSeverity
.
Warning
,
configurable
:
true
);
var
expectedDiagnostic
=
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
);
var
expectedDiagnostic
=
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
,
isSuppressed
:
false
);
VerifyAnalyzerDiagnostics
(
compilation
,
new
DiagnosticAnalyzer
[]
{
analyzer
},
expectedDiagnostic
);
const
string
suppressionId
=
"SPR1001"
;
var
analyzersAndSuppressors
=
new
DiagnosticAnalyzer
[]
{
analyzer
,
new
DiagnosticSuppressorForId
(
analyzer
.
Descriptor
.
Id
,
suppressionId
)
};
expectedDiagnostic
=
Diagnostic
(
analyzer
.
Descriptor
.
Id
,
source
,
isSuppressed
:
true
);
VerifySuppressedDiagnostics
(
compilation
,
analyzersAndSuppressors
,
expectedDiagnostic
);
var
specificDiagnosticOptions
=
compilation
.
Options
.
SpecificDiagnosticOptions
.
Add
(
suppressionId
,
ReportDiagnostic
.
Suppress
);
...
...
@@ -223,16 +229,22 @@ class C { }";
{
foreach
(
DiagnosticSeverity
effectiveSeverity
in
severities
)
{
var
diagnostic
=
Diagnostic
(
"ID1000"
,
"class C { }"
)
var
diagnostic
=
Diagnostic
(
"ID1000"
,
"class C { }"
,
isSuppressed
:
true
)
.
WithLocation
(
2
,
1
)
.
WithDefaultSeverity
(
defaultSeverity
)
.
WithEffectiveSeverity
(
configurable
?
effectiveSeverity
:
defaultSeverity
);
var
diagnosticNoSuppressor
=
Diagnostic
(
"ID1000"
,
"class C { }"
,
isSuppressed
:
false
)
.
WithLocation
(
2
,
1
)
.
WithDefaultSeverity
(
defaultSeverity
)
.
WithEffectiveSeverity
(
configurable
?
effectiveSeverity
:
defaultSeverity
);
if
(
defaultSeverity
==
DiagnosticSeverity
.
Warning
&&
effectiveSeverity
==
DiagnosticSeverity
.
Error
&&
configurable
)
{
diagnostic
=
diagnostic
.
WithWarningAsError
(
true
);
diagnosticNoSuppressor
=
diagnosticNoSuppressor
.
WithWarningAsError
(
true
);
}
var
analyzer
=
new
CompilationAnalyzerWithSeverity
(
defaultSeverity
,
configurable
);
...
...
@@ -246,7 +258,7 @@ class C { }";
compilation
=
compilation
.
WithOptions
(
compilation
.
Options
.
WithSpecificDiagnosticOptions
(
specificDiagnosticOptions
));
// Verify analyzer diagnostic without suppressor, also verify no suppressions.
VerifyAnalyzerDiagnostics
(
compilation
,
analyzersWithoutSuppressor
,
diagnostic
);
VerifyAnalyzerDiagnostics
(
compilation
,
analyzersWithoutSuppressor
,
diagnostic
NoSuppressor
);
VerifySuppressedDiagnostics
(
compilation
,
analyzersWithoutSuppressor
);
// Verify suppressed analyzer diagnostic, except when default severity is Error or diagnostic is not-configurable.
...
...
src/Test/Utilities/Portable/Diagnostics/DiagnosticDescription.cs
浏览文件 @
17736ac4
...
...
@@ -113,14 +113,14 @@ private IEnumerable<string> GetArgumentsAsStrings()
_isSuppressed
=
isSuppressed
;
}
public
DiagnosticDescription
(
Diagnostic
d
,
bool
errorCodeOnly
,
bool
includeDefaultSeverity
=
false
,
bool
includeEffectiveSeverity
=
false
,
bool
isSuppressed
=
false
)
public
DiagnosticDescription
(
Diagnostic
d
,
bool
errorCodeOnly
,
bool
includeDefaultSeverity
=
false
,
bool
includeEffectiveSeverity
=
false
)
{
_code
=
d
.
Code
;
_isWarningAsError
=
d
.
IsWarningAsError
;
_isSuppressed
=
d
.
IsSuppressed
;
_location
=
d
.
Location
;
_defaultSeverityOpt
=
includeDefaultSeverity
?
d
.
DefaultSeverity
:
(
DiagnosticSeverity
?)
null
;
_effectiveSeverityOpt
=
includeEffectiveSeverity
?
d
.
Severity
:
(
DiagnosticSeverity
?)
null
;
_isSuppressed
=
isSuppressed
;
DiagnosticWithInfo
dinfo
=
null
;
if
(
d
.
Code
==
0
||
d
.
Descriptor
.
CustomTags
.
Contains
(
WellKnownDiagnosticTags
.
CustomObsolete
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录