Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4a7d283e
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,发现更多精彩内容 >>
提交
4a7d283e
编写于
2月 14, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement analyzer and fix verifiers
上级
edd063a0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
283 addition
and
2 deletion
+283
-2
eng/Versions.props
eng/Versions.props
+2
-2
src/EditorFeatures/TestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
...TestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
+73
-0
src/EditorFeatures/TestUtilities/CodeActions/CSharpCodeFixVerifier`2.cs
...ures/TestUtilities/CodeActions/CSharpCodeFixVerifier`2.cs
+56
-0
src/EditorFeatures/TestUtilities/CodeActions/OptionsCollection.cs
...orFeatures/TestUtilities/CodeActions/OptionsCollection.cs
+43
-0
src/EditorFeatures/TestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
...tilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
+51
-0
src/EditorFeatures/TestUtilities/CodeActions/VisualBasicCodeFixVerifier`2.cs
...TestUtilities/CodeActions/VisualBasicCodeFixVerifier`2.cs
+56
-0
src/EditorFeatures/TestUtilities/Roslyn.Services.Test.Utilities.csproj
...tures/TestUtilities/Roslyn.Services.Test.Utilities.csproj
+2
-0
未找到文件。
eng/Versions.props
浏览文件 @
4a7d283e
...
...
@@ -28,7 +28,7 @@
<!-- Versions used by several individual references below -->
<RoslynDiagnosticsNugetPackageVersion>
3.0.0-beta2.20059.3+77df2220
</RoslynDiagnosticsNugetPackageVersion>
<CodeStyleLayerCodeAnalysisVersion>
3.3.1
</CodeStyleLayerCodeAnalysisVersion>
<MicrosoftCodeAnalysisTestingVersion>
1.0.1-beta1.20
067.1
</MicrosoftCodeAnalysisTestingVersion>
<MicrosoftCodeAnalysisTestingVersion>
1.0.1-beta1.20
114.4
</MicrosoftCodeAnalysisTestingVersion>
<CodeStyleAnalyzerVersion>
3.5.0-beta3-20078-04
</CodeStyleAnalyzerVersion>
<VisualStudioEditorPackagesVersion>
16.4.248
</VisualStudioEditorPackagesVersion>
<ILToolsPackageVersion>
5.0.0-alpha1.19409.1
</ILToolsPackageVersion>
...
...
@@ -97,7 +97,7 @@
<MicrosoftVisualStudioCodeAnalysisSdkUIVersion>
15.8.27812-alpha
</MicrosoftVisualStudioCodeAnalysisSdkUIVersion>
<MicrosoftVisualStudioCodingConventionsVersion>
1.1.20180503.2
</MicrosoftVisualStudioCodingConventionsVersion>
<MicrosoftVisualStudioComponentModelHostVersion>
16.0.198-g52de9c2988
</MicrosoftVisualStudioComponentModelHostVersion>
<MicrosoftVisualStudioCompositionVersion>
15.
5.23
</MicrosoftVisualStudioCompositionVersion>
<MicrosoftVisualStudioCompositionVersion>
15.
6.36
</MicrosoftVisualStudioCompositionVersion>
<MicrosoftVisualStudioCoreUtilityVersion>
$(VisualStudioEditorPackagesVersion)
</MicrosoftVisualStudioCoreUtilityVersion>
<MicrosoftVisualStudioDebuggerUIInterfacesVersion>
16.0.29431.108
</MicrosoftVisualStudioDebuggerUIInterfacesVersion>
<MicrosoftVisualStudioDebuggerEngineimplementationVersion>
16.4.1091102-preview
</MicrosoftVisualStudioDebuggerEngineimplementationVersion>
...
...
src/EditorFeatures/TestUtilities/CodeActions/CSharpCodeFixVerifier`2+Test.cs
0 → 100644
浏览文件 @
4a7d283e
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Collections.Immutable
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.Testing
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Testing.Verifiers
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
public
static
partial
class
CSharpCodeFixVerifier
<
TAnalyzer
,
TCodeFix
>
where
TAnalyzer
:
DiagnosticAnalyzer
,
new
()
where
TCodeFix
:
CodeFixProvider
,
new
()
{
public
class
Test
:
CSharpCodeFixTest
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>
{
private
static
readonly
ImmutableDictionary
<
string
,
ReportDiagnostic
>
NullableWarnings
=
GetNullableWarningsFromCompiler
();
public
Test
()
{
MarkupOptions
=
Testing
.
MarkupOptions
.
UseFirstDescriptor
;
SolutionTransforms
.
Add
((
solution
,
projectId
)
=>
{
var
parseOptions
=
(
CSharpParseOptions
)
solution
.
GetProject
(
projectId
).
ParseOptions
;
solution
=
solution
.
WithProjectParseOptions
(
projectId
,
parseOptions
.
WithLanguageVersion
(
LanguageVersion
));
var
compilationOptions
=
solution
.
GetProject
(
projectId
).
CompilationOptions
;
compilationOptions
=
compilationOptions
.
WithSpecificDiagnosticOptions
(
compilationOptions
.
SpecificDiagnosticOptions
.
SetItems
(
NullableWarnings
));
solution
=
solution
.
WithProjectCompilationOptions
(
projectId
,
compilationOptions
);
var
options
=
solution
.
Options
;
foreach
(
var
(
key
,
value
)
in
Options
)
{
options
=
options
.
WithChangedOption
(
key
,
value
);
}
solution
=
solution
.
WithOptions
(
options
);
return
solution
;
});
}
private
static
ImmutableDictionary
<
string
,
ReportDiagnostic
>
GetNullableWarningsFromCompiler
()
{
string
[]
args
=
{
"/warnaserror:nullable"
};
var
commandLineArguments
=
CSharpCommandLineParser
.
Default
.
Parse
(
args
,
baseDirectory
:
Environment
.
CurrentDirectory
,
sdkDirectory
:
Environment
.
CurrentDirectory
);
var
nullableWarnings
=
commandLineArguments
.
CompilationOptions
.
SpecificDiagnosticOptions
;
// Workaround for https://github.com/dotnet/roslyn/issues/41610
nullableWarnings
=
nullableWarnings
.
SetItem
(
"CS8632"
,
ReportDiagnostic
.
Error
)
.
SetItem
(
"CS8669"
,
ReportDiagnostic
.
Error
);
return
nullableWarnings
;
}
public
LanguageVersion
LanguageVersion
{
get
;
set
;
}
=
LanguageVersion
.
CSharp8
;
public
OptionsCollection
Options
{
get
;
}
=
new
OptionsCollection
(
LanguageNames
.
CSharp
);
protected
override
AnalyzerOptions
GetAnalyzerOptions
(
Project
project
)
{
return
new
WorkspaceAnalyzerOptions
(
base
.
GetAnalyzerOptions
(
project
),
project
.
Solution
);
}
}
}
}
src/EditorFeatures/TestUtilities/CodeActions/CSharpCodeFixVerifier`2.cs
0 → 100644
浏览文件 @
4a7d283e
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CSharp.Testing
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Testing
;
using
Microsoft.CodeAnalysis.Testing.Verifiers
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
public
static
partial
class
CSharpCodeFixVerifier
<
TAnalyzer
,
TCodeFix
>
where
TAnalyzer
:
DiagnosticAnalyzer
,
new
()
where
TCodeFix
:
CodeFixProvider
,
new
()
{
public
static
DiagnosticResult
Diagnostic
()
=>
CSharpCodeFixVerifier
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>.
Diagnostic
();
public
static
DiagnosticResult
Diagnostic
(
string
diagnosticId
)
=>
CSharpCodeFixVerifier
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>.
Diagnostic
(
diagnosticId
);
public
static
DiagnosticResult
Diagnostic
(
DiagnosticDescriptor
descriptor
)
=>
CSharpCodeFixVerifier
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>.
Diagnostic
(
descriptor
);
public
static
async
Task
VerifyAnalyzerAsync
(
string
source
,
params
DiagnosticResult
[]
expected
)
{
var
test
=
new
Test
{
TestCode
=
source
,
};
test
.
ExpectedDiagnostics
.
AddRange
(
expected
);
await
test
.
RunAsync
();
}
public
static
async
Task
VerifyCodeFixAsync
(
string
source
,
string
fixedSource
)
=>
await
VerifyCodeFixAsync
(
source
,
DiagnosticResult
.
EmptyDiagnosticResults
,
fixedSource
);
public
static
async
Task
VerifyCodeFixAsync
(
string
source
,
DiagnosticResult
expected
,
string
fixedSource
)
=>
await
VerifyCodeFixAsync
(
source
,
new
[]
{
expected
},
fixedSource
);
public
static
async
Task
VerifyCodeFixAsync
(
string
source
,
DiagnosticResult
[]
expected
,
string
fixedSource
)
{
var
test
=
new
Test
{
TestCode
=
source
,
FixedCode
=
fixedSource
,
};
test
.
ExpectedDiagnostics
.
AddRange
(
expected
);
await
test
.
RunAsync
();
}
}
}
src/EditorFeatures/TestUtilities/CodeActions/OptionsCollection.cs
0 → 100644
浏览文件 @
4a7d283e
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System.Collections
;
using
System.Collections.Generic
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.Options
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
public
sealed
class
OptionsCollection
:
IEnumerable
<
KeyValuePair
<
OptionKey
,
object
>>
{
private
readonly
Dictionary
<
OptionKey
,
object
>
_options
=
new
Dictionary
<
OptionKey
,
object
>();
private
readonly
string
_languageName
;
public
OptionsCollection
(
string
languageName
)
{
_languageName
=
languageName
;
}
public
void
Add
<
T
>(
Option
<
T
>
option
,
T
value
)
=>
_options
.
Add
(
new
OptionKey
(
option
),
value
);
public
void
Add
<
T
>(
Option
<
CodeStyleOption
<
T
>>
option
,
T
value
,
NotificationOption
notification
)
=>
_options
.
Add
(
new
OptionKey
(
option
),
new
CodeStyleOption
<
T
>(
value
,
notification
));
public
void
Add
<
T
>(
PerLanguageOption
<
T
>
option
,
T
value
)
=>
_options
.
Add
(
new
OptionKey
(
option
,
_languageName
),
value
);
public
void
Add
<
T
>(
PerLanguageOption
<
CodeStyleOption
<
T
>>
option
,
T
value
)
=>
Add
(
option
,
value
,
option
.
DefaultValue
.
Notification
);
public
void
Add
<
T
>(
PerLanguageOption
<
CodeStyleOption
<
T
>>
option
,
T
value
,
NotificationOption
notification
)
=>
_options
.
Add
(
new
OptionKey
(
option
,
_languageName
),
new
CodeStyleOption
<
T
>(
value
,
notification
));
public
IEnumerator
<
KeyValuePair
<
OptionKey
,
object
>>
GetEnumerator
()
=>
_options
.
GetEnumerator
();
IEnumerator
IEnumerable
.
GetEnumerator
()
=>
GetEnumerator
();
}
}
src/EditorFeatures/TestUtilities/CodeActions/VisualBasicCodeFixVerifier`2+Test.cs
0 → 100644
浏览文件 @
4a7d283e
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Testing.Verifiers
;
using
Microsoft.CodeAnalysis.VisualBasic
;
using
Microsoft.CodeAnalysis.VisualBasic.Testing
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
public
static
partial
class
VisualBasicCodeFixVerifier
<
TAnalyzer
,
TCodeFix
>
where
TAnalyzer
:
DiagnosticAnalyzer
,
new
()
where
TCodeFix
:
CodeFixProvider
,
new
()
{
public
class
Test
:
VisualBasicCodeFixTest
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>
{
public
Test
()
{
MarkupOptions
=
Testing
.
MarkupOptions
.
UseFirstDescriptor
;
SolutionTransforms
.
Add
((
solution
,
projectId
)
=>
{
var
parseOptions
=
(
VisualBasicParseOptions
)
solution
.
GetProject
(
projectId
).
ParseOptions
;
solution
=
solution
.
WithProjectParseOptions
(
projectId
,
parseOptions
.
WithLanguageVersion
(
LanguageVersion
));
var
options
=
solution
.
Options
;
foreach
(
var
(
key
,
value
)
in
Options
)
{
options
=
options
.
WithChangedOption
(
key
,
value
);
}
solution
=
solution
.
WithOptions
(
options
);
return
solution
;
});
}
public
LanguageVersion
LanguageVersion
{
get
;
set
;
}
=
LanguageVersion
.
VisualBasic16
;
public
OptionsCollection
Options
{
get
;
}
=
new
OptionsCollection
(
LanguageNames
.
CSharp
);
protected
override
AnalyzerOptions
GetAnalyzerOptions
(
Project
project
)
{
return
new
WorkspaceAnalyzerOptions
(
base
.
GetAnalyzerOptions
(
project
),
project
.
Solution
);
}
}
}
}
src/EditorFeatures/TestUtilities/CodeActions/VisualBasicCodeFixVerifier`2.cs
0 → 100644
浏览文件 @
4a7d283e
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Testing
;
using
Microsoft.CodeAnalysis.Testing.Verifiers
;
using
Microsoft.CodeAnalysis.VisualBasic.Testing
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
public
static
partial
class
VisualBasicCodeFixVerifier
<
TAnalyzer
,
TCodeFix
>
where
TAnalyzer
:
DiagnosticAnalyzer
,
new
()
where
TCodeFix
:
CodeFixProvider
,
new
()
{
public
static
DiagnosticResult
Diagnostic
()
=>
VisualBasicCodeFixVerifier
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>.
Diagnostic
();
public
static
DiagnosticResult
Diagnostic
(
string
diagnosticId
)
=>
VisualBasicCodeFixVerifier
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>.
Diagnostic
(
diagnosticId
);
public
static
DiagnosticResult
Diagnostic
(
DiagnosticDescriptor
descriptor
)
=>
VisualBasicCodeFixVerifier
<
TAnalyzer
,
TCodeFix
,
XUnitVerifier
>.
Diagnostic
(
descriptor
);
public
static
async
Task
VerifyAnalyzerAsync
(
string
source
,
params
DiagnosticResult
[]
expected
)
{
var
test
=
new
Test
{
TestCode
=
source
,
};
test
.
ExpectedDiagnostics
.
AddRange
(
expected
);
await
test
.
RunAsync
();
}
public
static
async
Task
VerifyCodeFixAsync
(
string
source
,
string
fixedSource
)
=>
await
VerifyCodeFixAsync
(
source
,
DiagnosticResult
.
EmptyDiagnosticResults
,
fixedSource
);
public
static
async
Task
VerifyCodeFixAsync
(
string
source
,
DiagnosticResult
expected
,
string
fixedSource
)
=>
await
VerifyCodeFixAsync
(
source
,
new
[]
{
expected
},
fixedSource
);
public
static
async
Task
VerifyCodeFixAsync
(
string
source
,
DiagnosticResult
[]
expected
,
string
fixedSource
)
{
var
test
=
new
Test
{
TestCode
=
source
,
FixedCode
=
fixedSource
,
};
test
.
ExpectedDiagnostics
.
AddRange
(
expected
);
await
test
.
RunAsync
();
}
}
}
src/EditorFeatures/TestUtilities/Roslyn.Services.Test.Utilities.csproj
浏览文件 @
4a7d283e
...
...
@@ -57,6 +57,8 @@
<PackageReference
Include=
"Microsoft.VisualStudio.Utilities"
Version=
"$(MicrosoftVisualStudioUtilitiesVersion)"
/>
<PackageReference
Include=
"Microsoft.VisualStudio.Validation"
Version=
"$(MicrosoftVisualStudioValidationVersion)"
/>
<PackageReference
Include=
"System.Threading.Tasks.Dataflow"
Version=
"$(SystemThreadingTasksDataflowVersion)"
/>
<PackageReference
Include=
"Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit"
Version=
"$(MicrosoftCodeAnalysisCSharpCodeFixTestingXUnitVersion)"
/>
<PackageReference
Include=
"Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit"
Version=
"$(MicrosoftCodeAnalysisVisualBasicCodeFixTestingXUnitVersion)"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"..\..\VisualStudio\Core\Def\Implementation\Remote\JsonRpcConnection.cs"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录