未验证 提交 af82a715 编写于 作者: J Jared Parsons 提交者: GitHub

Merge pull request #30311 from jaredpar/fix-cl

Enable C# CommandLine and WinRT tests on Linux
......@@ -51,14 +51,9 @@ elif [[ "${runtime}" =~ ^(mono|mono-debug)$ ]]; then
'Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests.dll'
# PortablePdb and lots of other problems
'Microsoft.CodeAnalysis.VisualBasic.Scripting.UnitTests.dll'
# GetSystemInfo is missing, and other problems
# See https://github.com/mono/mono/issues/10678
'Microsoft.CodeAnalysis.CSharp.WinRT.UnitTests.dll'
# Many test failures
'Microsoft.CodeAnalysis.UnitTests.dll'
# Multiple test failures
'Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests.dll'
# Multiple test failures
'Microsoft.Build.Tasks.CodeAnalysis.UnitTests.dll'
# Disabling on assumption
'Microsoft.CodeAnalysis.VisualBasic.Emit.UnitTests.dll'
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests
{
public abstract class CommandLineTestBase : CSharpTestBase
{
public string WorkingDirectory { get; }
public string SdkDirectory { get; }
public string MscorlibFullPath { get; }
public CommandLineTestBase()
{
WorkingDirectory = TempRoot.Root;
SdkDirectory = getSdkDirectory(Temp);
MscorlibFullPath = Path.Combine(SdkDirectory, "mscorlib.dll");
// This will return a directory which contains mscorlib for use in the compiler instances created for
// this set of tests
string getSdkDirectory(TempRoot temp)
{
if (ExecutionConditionUtil.IsCoreClr)
{
var dir = temp.CreateDirectory();
File.WriteAllBytes(Path.Combine(dir.Path, "mscorlib.dll"), TestResources.NetFX.net461.mscorlib);
return dir.Path;
}
return RuntimeEnvironment.GetRuntimeDirectory();
}
}
internal CSharpCommandLineArguments DefaultParse(IEnumerable<string> args, string baseDirectory, string sdkDirectory = null, string additionalReferenceDirectories = null)
{
sdkDirectory = sdkDirectory ?? SdkDirectory;
return CSharpCommandLineParser.Default.Parse(args, baseDirectory, sdkDirectory, additionalReferenceDirectories);
}
internal MockCSharpCompiler CreateCSharpCompiler(string[] args, ImmutableArray<DiagnosticAnalyzer> analyzers = default, AnalyzerAssemblyLoader loader = null)
{
return CreateCSharpCompiler(null, WorkingDirectory, args, analyzers, loader);
}
internal MockCSharpCompiler CreateCSharpCompiler(string responseFile, string workingDirectory, string[] args, ImmutableArray<DiagnosticAnalyzer> analyzers = default, AnalyzerAssemblyLoader loader = null)
{
var buildPaths = RuntimeUtilities.CreateBuildPaths(workingDirectory, sdkDirectory: SdkDirectory);
return new MockCSharpCompiler(responseFile, buildPaths, args, analyzers, loader);
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class CommandLineTestResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal CommandLineTestResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests.CommandLineTestResources", typeof(CommandLineTestResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] csc_rsp {
get {
object obj = ResourceManager.GetObject("csc_rsp", resourceCulture);
return ((byte[])(obj));
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="csc_rsp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>../../csc/csc.rsp;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using static Microsoft.CodeAnalysis.CommonDiagnosticAnalyzers;
......@@ -16,11 +17,9 @@
namespace Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests
{
public class ErrorLoggerTests : CSharpTestBase
public class ErrorLoggerTests : CommandLineTestBase
{
private readonly string _baseDirectory = TempRoot.Root;
[Fact]
[ConditionalFact(typeof(WindowsOnly), Reason = "https://github.com/dotnet/roslyn/issues/30289")]
public void NoDiagnostics()
{
var helloWorldCS = @"using System;
......@@ -36,8 +35,7 @@ public static void Main(string[] args)
var errorLogDir = Temp.CreateDirectory();
var errorLogFile = Path.Combine(errorLogDir.Path, "ErrorLog.txt");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", hello,
$"/errorlog:{errorLogFile}" });
var cmd = CreateCSharpCompiler(new[] { "/nologo", hello, $"/errorlog:{errorLogFile}" });
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var exitCode = cmd.Run(outWriter);
......@@ -61,7 +59,7 @@ public static void Main(string[] args)
CleanupAllGeneratedFiles(errorLogFile);
}
[Fact]
[ConditionalFact(typeof(WindowsOnly), Reason = "https://github.com/dotnet/roslyn/issues/30289")]
public void SimpleCompilerDiagnostics()
{
var source = @"
......@@ -73,7 +71,7 @@ public class C
var errorLogDir = Temp.CreateDirectory();
var errorLogFile = Path.Combine(errorLogDir.Path, "ErrorLog.txt");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] {
var cmd = CreateCSharpCompiler(null, WorkingDirectory, new[] {
"/nologo", sourceFile, "/preferreduilang:en", $"/errorlog:{errorLogFile}" });
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
......@@ -155,7 +153,7 @@ public class C
CleanupAllGeneratedFiles(errorLogFile);
}
[Fact]
[ConditionalFact(typeof(WindowsOnly), Reason = "https://github.com/dotnet/roslyn/issues/30289")]
public void SimpleCompilerDiagnostics_Suppressed()
{
var source = @"
......@@ -169,7 +167,7 @@ public class C
var errorLogDir = Temp.CreateDirectory();
var errorLogFile = Path.Combine(errorLogDir.Path, "ErrorLog.txt");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] {
var cmd = CreateCSharpCompiler(null, WorkingDirectory, new[] {
"/nologo", sourceFile, "/preferreduilang:en", $"/errorlog:{errorLogFile}" });
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
......@@ -255,7 +253,7 @@ public class C
CleanupAllGeneratedFiles(errorLogFile);
}
[Fact]
[ConditionalFact(typeof(WindowsOnly), Reason = "https://github.com/dotnet/roslyn/issues/30289")]
public void AnalyzerDiagnosticsWithAndWithoutLocation()
{
var source = @"
......@@ -267,10 +265,9 @@ public class C
var errorLogFile = Path.Combine(outputDir.Path, "ErrorLog.txt");
var outputFilePath = Path.Combine(outputDir.Path, "test.dll");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] {
var cmd = CreateCSharpCompiler(null, WorkingDirectory, new[] {
"/nologo", "/t:library", $"/out:{outputFilePath}", sourceFile, "/preferreduilang:en", $"/errorlog:{errorLogFile}" },
analyzers: ImmutableArray.Create<DiagnosticAnalyzer>(new AnalyzerForErrorLogTest()),
loader: new DesktopAnalyzerAssemblyLoader());
analyzers: ImmutableArray.Create<DiagnosticAnalyzer>(new AnalyzerForErrorLogTest()));
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
......
......@@ -6,11 +6,13 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests</RootNamespace>
<TargetFramework>net46</TargetFramework>
<RuntimeIdentifier>$(RoslynDesktopRuntimeIdentifier)</RuntimeIdentifier>
<RoslynProjectType>UnitTest</RoslynProjectType>
<TargetFrameworks>$(RoslynPortableTargetFrameworks)</TargetFrameworks>
<RoslynProjectType>UnitTestPortable</RoslynProjectType>
<GenerateMicrosoftCodeAnalysisCommitHashAttribute>true</GenerateMicrosoftCodeAnalysisCommitHashAttribute>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Test\Resources\Core\ResourceLoader.cs" Link="ResourceLoader.cs" />
</ItemGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\..\..\Test\Utilities\Portable\Roslyn.Test.Utilities.csproj" />
<ProjectReference Include="..\..\..\Test\Utilities\CSharp\Microsoft.CodeAnalysis.CSharp.Test.Utilities.csproj" />
......@@ -24,26 +26,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Update="CommandLineTestResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CommandLineTestResources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="..\..\csc\csc.rsp" LogicalName="csc.rsp" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="CommandLineTestResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CommandLineTestResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -15,10 +15,9 @@
namespace Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests
{
public class TouchedFileLoggingTests : CSharpTestBase
public class TouchedFileLoggingTests : CommandLineTestBase
{
private static readonly string s_libDirectory = Environment.GetEnvironmentVariable("LIB");
private readonly string _baseDirectory = TempRoot.Root;
private const string helloWorldCS = @"using System;
class C
......@@ -36,7 +35,7 @@ public void TrivialSourceFileOnlyCsc()
var touchedDir = Temp.CreateDirectory();
var touchedBase = Path.Combine(touchedDir.Path, "touched");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[] { "/nologo", hello,
var cmd = CreateCSharpCompiler(new[] { "/nologo", hello,
string.Format(@"/touchedfiles:""{0}""", touchedBase) });
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
......@@ -77,7 +76,7 @@ public void AppConfigCsc()
var net4_0dll = Temp.CreateFile().WriteAllBytes(TestResources.NetFX.v4_0_30319.System).Path;
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var cmd = new MockCSharpCompiler(null, _baseDirectory,
var cmd = CreateCSharpCompiler(
new[] { "/nologo",
"/r:" + silverlight,
"/r:" + net4_0dll,
......@@ -112,7 +111,7 @@ public void StrongNameKeyCsc()
var touchedBase = Path.Combine(touchedDir.Path, "touched");
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
var cmd = new MockCSharpCompiler(null, _baseDirectory,
var cmd = CreateCSharpCompiler(
new[] { "/nologo",
"/touchedfiles:" + touchedBase,
"/keyfile:" + snkPath,
......@@ -150,7 +149,7 @@ public class C { }").Path;
var touchedDir = Temp.CreateDirectory();
var touchedBase = Path.Combine(touchedDir.Path, "touched");
var cmd = new MockCSharpCompiler(null, _baseDirectory, new[]
var cmd = CreateCSharpCompiler(new[]
{
"/nologo",
"/target:library",
......
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18010
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
......@@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
......
......@@ -140,7 +140,7 @@ public void WinMdColorType()
/// Ensure that a simple program that uses projected types can compile
/// and run.
/// </summary>
[ConditionalFact(typeof(OSVersionWin8))]
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = ConditionalSkipReason.TestExecutionNeedsDesktopTypes)]
public void WinMdColorTest()
{
var text = @"using Windows.UI;
......
......@@ -6,9 +6,8 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen</RootNamespace>
<TargetFramework>net46</TargetFramework>
<RuntimeIdentifier>$(RoslynDesktopRuntimeIdentifier)</RuntimeIdentifier>
<RoslynProjectType>UnitTest</RoslynProjectType>
<TargetFrameworks>$(RoslynPortableTargetFrameworks)</TargetFrameworks>
<RoslynProjectType>UnitTestPortable</RoslynProjectType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
......@@ -21,10 +20,7 @@
<ProjectReference Include="..\..\..\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<ProjectReference Include="..\..\..\..\Test\PdbUtilities\Roslyn.Test.PdbUtilities.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -6,13 +6,13 @@
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Test.Utilities.Desktop;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Symbols
{
public class PEParameterSymbolTests : CSharpTestBase
{
#if !NETCOREAPP2_1
[Fact]
public void NoParameterNames()
{
......@@ -21,7 +21,7 @@ public void NoParameterNames()
// {
// void M(object, object);
// }
var reference = DesktopRuntimeUtil.CreateReflectionEmitAssembly(moduleBuilder =>
var reference = Roslyn.Test.Utilities.Desktop.DesktopRuntimeUtil.CreateReflectionEmitAssembly(moduleBuilder =>
{
var typeBuilder = moduleBuilder.DefineType(
"I",
......@@ -48,6 +48,7 @@ static void M(I o)
// (5,16): error CS1744: Named argument 'value' specifies a parameter for which a positional argument has already been given
Diagnostic(ErrorCode.ERR_NamedArgumentUsedInPositional, "value").WithArguments("value").WithLocation(5, 16));
}
#endif
[Fact]
[WorkItem(8018, "https://github.com/dotnet/roslyn/issues/8018")]
......
......@@ -74,7 +74,7 @@ public void EmitToBoundedStreams()
r.Diagnostics.Verify();
}
[ClrOnlyFact(ClrOnlyReason.Pdb)]
[ConditionalFact(typeof(WindowsOnly), Reason = ConditionalSkipReason.NativePdbRequiresDesktop)]
public void EmitToStreamWithNonZeroPosition()
{
var pdbStream = new MemoryStream();
......
......@@ -22,7 +22,7 @@ private static Stream GetResourceStream(string name)
return stream;
}
private static byte[] GetResourceBlob(string name)
public static byte[] GetResourceBlob(string name)
{
using (var stream = GetResourceStream(name))
{
......@@ -50,16 +50,21 @@ public static string GetOrCreateResource(ref string resource, string name)
{
if (resource == null)
{
using (var stream = GetResourceStream(name))
{
using (var streamReader = new StreamReader(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true))
{
resource = streamReader.ReadToEnd();
}
}
resource = GetResource(name);
}
return resource;
}
public static string GetResource(string name)
{
using (var stream = GetResourceStream(name))
{
using (var streamReader = new StreamReader(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true))
{
return streamReader.ReadToEnd();
}
}
}
}
}
......@@ -12,31 +12,21 @@ namespace Microsoft.CodeAnalysis.CSharp.Test.Utilities
{
internal class MockCSharpCompiler : CSharpCompiler
{
protected readonly ImmutableArray<DiagnosticAnalyzer> _analyzers;
private readonly ImmutableArray<DiagnosticAnalyzer> _analyzers;
internal Compilation Compilation;
public MockCSharpCompiler(string responseFile, string baseDirectory, string[] args)
: this(responseFile, baseDirectory, args, ImmutableArray<DiagnosticAnalyzer>.Empty, RuntimeUtilities.CreateAnalyzerAssemblyLoader())
{
}
public MockCSharpCompiler(string responseFile, BuildPaths buildPaths, string[] args)
: this(responseFile, buildPaths, args, ImmutableArray<DiagnosticAnalyzer>.Empty, RuntimeUtilities.CreateAnalyzerAssemblyLoader())
{
}
public MockCSharpCompiler(string responseFile, string workingDirectory, string[] args, ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerAssemblyLoader loader)
public MockCSharpCompiler(string responseFile, string workingDirectory, string[] args, ImmutableArray<DiagnosticAnalyzer> analyzers = default, AnalyzerAssemblyLoader loader = null)
: this(responseFile, CreateBuildPaths(workingDirectory), args, analyzers, loader)
{
}
public MockCSharpCompiler(string responseFile, BuildPaths buildPaths, string[] args, ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerAssemblyLoader loader)
: base(CSharpCommandLineParser.Default, responseFile, args, buildPaths, Environment.GetEnvironmentVariable("LIB"), loader)
public MockCSharpCompiler(string responseFile, BuildPaths buildPaths, string[] args, ImmutableArray<DiagnosticAnalyzer> analyzers = default, AnalyzerAssemblyLoader loader = null)
: base(CSharpCommandLineParser.Default, responseFile, args, buildPaths, Environment.GetEnvironmentVariable("LIB"), loader ?? RuntimeUtilities.CreateAnalyzerAssemblyLoader())
{
_analyzers = analyzers;
_analyzers = analyzers.NullToEmpty();
}
private static BuildPaths CreateBuildPaths(string workingDirectory) => RuntimeUtilities.CreateBuildPaths(workingDirectory);
private static BuildPaths CreateBuildPaths(string workingDirectory, string sdkDirectory = null) => RuntimeUtilities.CreateBuildPaths(workingDirectory, sdkDirectory);
protected override ImmutableArray<DiagnosticAnalyzer> ResolveAnalyzersFromArguments(
List<DiagnosticInfo> diagnostics,
......
......@@ -35,7 +35,7 @@ Friend Class MockVisualBasicCompiler
End Sub
Private Shared Function CreateBuildPaths(workingDirectory As String, tempDirectory As String) As BuildPaths
Return RuntimeUtilities.CreateBuildPaths(workingDirectory, tempDirectory)
Return RuntimeUtilities.CreateBuildPaths(workingDirectory, tempDirectory:=tempDirectory)
End Function
Protected Overrides Function ResolveAnalyzersFromArguments(
......
......@@ -13,20 +13,20 @@ namespace Microsoft.CodeAnalysis.Test.Utilities
/// </summary>
public static partial class RuntimeUtilities
{
internal static BuildPaths CreateBuildPaths(string workingDirectory, string tempDirectory = null)
internal static BuildPaths CreateBuildPaths(string workingDirectory, string sdkDirectory = null, string tempDirectory = null)
{
tempDirectory = tempDirectory ?? Path.GetTempPath();
#if NET46
return new BuildPaths(
clientDir: Path.GetDirectoryName(typeof(BuildPathsUtil).Assembly.Location),
workingDir: workingDirectory,
sdkDir: RuntimeEnvironment.GetRuntimeDirectory(),
sdkDir: sdkDirectory ?? RuntimeEnvironment.GetRuntimeDirectory(),
tempDir: tempDirectory);
#else
return new BuildPaths(
clientDir: AppContext.BaseDirectory,
workingDir: workingDirectory,
sdkDir: null,
sdkDir: sdkDirectory,
tempDir: tempDirectory);
#endif
}
......@@ -48,8 +48,12 @@ internal static AnalyzerAssemblyLoader CreateAnalyzerAssemblyLoader()
{
#if NET46
return new DesktopAnalyzerAssemblyLoader();
#else
#elif NETCOREAPP2_1
return new CoreClrAnalyzerAssemblyLoader();
#elif NETSTANDARD1_3
return new ThrowingAnalyzerAssemblyLoader();
#else
#error Unsupported configuration
#endif
}
......
......@@ -72,6 +72,7 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Workspaces.UnitTests" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Compilers\Shared\CoreClrAnalyzerAssemblyLoader.cs" Link="CoreClrAnalyzerAssemblyLoader.cs" />
<Compile Include="..\..\..\Compilers\Shared\DesktopAnalyzerAssemblyLoader.cs">
<Link>DesktopAnalyzerAssemblyLoader.cs</Link>
</Compile>
......
......@@ -51,7 +51,9 @@ private static bool MainCore(string[] args)
if (string.IsNullOrEmpty(repositoryDirectory))
{
repositoryDirectory = AppContext.BaseDirectory;
repositoryDirectory = solutionFiles.Count > 0
? Path.GetDirectoryName(solutionFiles[0])
: AppContext.BaseDirectory;
}
return Go(repositoryDirectory, isRelease, solutionFiles);
......
......@@ -110,8 +110,9 @@ private bool ParseRoslynProjectData(TextWriter textWriter, out RoslynProjectData
}
catch (Exception ex)
{
data = default(RoslynProjectData);
textWriter.WriteLine("Unable to parse Roslyn project properties");
textWriter.WriteLine(ex.Message);
data = default;
return false;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册