未验证 提交 d9535629 编写于 作者: V Vlad Zarytovskii 提交者: GitHub

Add tests for consuming statics in interfaces (#13097)

* Upgraded Roslyn and VS packages + added tests for consuming statics in interfaces

* Skip abstract statics test on non-netcore

* Fix path to csc

* Reverted roslyn version to 4.2.*
上级 2eb7dc7c
......@@ -509,7 +509,7 @@ try {
Create-Directory $resultsRoot
UpdatePath
$env:HOSTED_COMPILER = 1
$env:CSC_PIPE = "$nugetPackages\Microsoft.Net.Compilers\2.7.0\tools\csc.exe"
$env:CSC_PIPE = "$nugetPackages\Microsoft.Net.Compilers\4.3.0-1.22220.8\tools\csc.exe"
$env:FSCOREDLLPATH = "$ArtifactsDir\bin\fsc\$configuration\net472\FSharp.Core.dll"
$env:LINK_EXE = "$RepoRoot\tests\fsharpqa\testenv\bin\link\link.exe"
$env:OSARCH = $env:PROCESSOR_ARCHITECTURE
......
......@@ -113,8 +113,8 @@
<SystemRuntimeCompilerServicesUnsafeVersion>6.0.0</SystemRuntimeCompilerServicesUnsafeVersion>
<SystemValueTupleVersion>4.5.0</SystemValueTupleVersion>
<!-- VisualStudio package versions -->
<VisualStudioImplementationPackagesVersion>17.0.391-preview-g5e248c9073</VisualStudioImplementationPackagesVersion>
<VisualStudioContractPackagesVersion>17.0.0-previews-4-31709-430</VisualStudioContractPackagesVersion>
<VisualStudioImplementationPackagesVersion>17.2.178-preview</VisualStudioImplementationPackagesVersion>
<VisualStudioContractPackagesVersion>17.2.0-preview-1-32131-009</VisualStudioContractPackagesVersion>
<VisualStudioProjectSystemPackagesVersion>17.0.77-pre-g62a6cb5699</VisualStudioProjectSystemPackagesVersion>
<MicrosoftVisualStudioInteropVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioInteropVersion>
<MicrosoftInternalVisualStudioInteropVersion>$(VisualStudioContractPackagesVersion)</MicrosoftInternalVisualStudioInteropVersion>
......@@ -135,7 +135,7 @@
<EnvDTEVersion>$(VisualStudioContractPackagesVersion)</EnvDTEVersion>
<EnvDTE80Version>$(VisualStudioContractPackagesVersion)</EnvDTE80Version>
<!-- Roslyn packages -->
<RoslynVersion>4.1.0-1.21511.14</RoslynVersion>
<RoslynVersion>4.2.0-2.22103.11</RoslynVersion>
<MicrosoftCodeAnalysisEditorFeaturesVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesTextVersion>
<MicrosoftCodeAnalysisEditorFeaturesWpfVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesWpfVersion>
......@@ -169,7 +169,7 @@
<MicrosoftVisualStudioShellFrameworkVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioShellFrameworkVersion>
<MicrosoftVisualStudioPackageLanguageService150Version>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioPackageLanguageService150Version>
<!-- Misc. Visual Studio packages -->
<MicrosoftVisualStudioRpcContractsVersion>17.0.50-preview-0002-0025</MicrosoftVisualStudioRpcContractsVersion>
<MicrosoftVisualStudioRpcContractsVersion>17.2.22-alpha</MicrosoftVisualStudioRpcContractsVersion>
<MicrosoftVisualStudioComponentModelHostVersion>$(VisualStudioImplementationPackagesVersion)</MicrosoftVisualStudioComponentModelHostVersion>
<MicrosoftVisualFSharpMicrosoftVisualStudioShellUIInternalVersion>17.0.0</MicrosoftVisualFSharpMicrosoftVisualStudioShellUIInternalVersion>
<MicrosoftVisualStudioDesignerInterfacesVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioDesignerInterfacesVersion>
......@@ -185,9 +185,9 @@
<MicrosoftVisualStudioShellImmutable150Version>15.0.25123-Dev15Preview</MicrosoftVisualStudioShellImmutable150Version>
<MicrosoftVisualStudioShellInterop160DesignTimeVersion>16.0.1</MicrosoftVisualStudioShellInterop160DesignTimeVersion>
<MicrosoftVisualStudioShellInterop16DesignTimeVersion>16.0.28924.11111</MicrosoftVisualStudioShellInterop16DesignTimeVersion>
<MicrosoftVisualStudioThreadingVersion>17.0.46-alpha</MicrosoftVisualStudioThreadingVersion>
<MicrosoftVisualStudioThreadingVersion>17.2.10-alpha</MicrosoftVisualStudioThreadingVersion>
<MicrosoftVisualStudioUtilitiesVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioUtilitiesVersion>
<MicrosoftVisualStudioValidationVersion>17.0.23-alpha</MicrosoftVisualStudioValidationVersion>
<MicrosoftVisualStudioValidationVersion>17.0.46</MicrosoftVisualStudioValidationVersion>
<MicrosoftVisualStudioWCFReferenceInteropVersion>9.0.30729</MicrosoftVisualStudioWCFReferenceInteropVersion>
<VSSDKDebuggerVisualizersVersion>12.0.4</VSSDKDebuggerVisualizersVersion>
<VSSDKVSLangProjVersion>7.0.4</VSSDKVSLangProjVersion>
......@@ -203,7 +203,7 @@
<FSharpDataTypeProvidersVersion>4.3.0.0</FSharpDataTypeProvidersVersion>
<MicrosoftCompositionVersion>1.0.30</MicrosoftCompositionVersion>
<MicrosoftMSXMLVersion>8.0.0</MicrosoftMSXMLVersion>
<MicrosoftNetCompilersVersion>2.7.0</MicrosoftNetCompilersVersion>
<MicrosoftNetCompilersVersion>4.3.0-1.22220.8</MicrosoftNetCompilersVersion>
<MicrosoftNETCoreAppRefVersion>3.1.0</MicrosoftNETCoreAppRefVersion>
<MicrosoftNETCoreILDAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILDAsmVersion>
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILAsmVersion>
......@@ -214,8 +214,8 @@
<NUnit3TestAdapterVersion>4.1.0</NUnit3TestAdapterVersion>
<NunitXmlTestLoggerVersion>2.1.80</NunitXmlTestLoggerVersion>
<RoslynToolsSignToolVersion>1.0.0-beta2-dev3</RoslynToolsSignToolVersion>
<StreamJsonRpcVersion>2.8.21</StreamJsonRpcVersion>
<NerdbankStreamsVersion>2.7.74</NerdbankStreamsVersion>
<StreamJsonRpcVersion>2.11.34</StreamJsonRpcVersion>
<NerdbankStreamsVersion>2.8.57</NerdbankStreamsVersion>
<XUnitVersion>2.4.1</XUnitVersion>
<XUnitRunnerVersion>2.4.2</XUnitRunnerVersion>
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
......
......@@ -18,12 +18,12 @@
</PropertyGroup>
<ItemGroup>
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi;" Exclude="@(Compile)">
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
</None>
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
</None>
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi;" Exclude="@(Compile)">
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
</None>
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
</None>
<Compile Include="Conformance\BasicGrammarElements\OperatorNames\OperatorNames.fs" />
<Compile Include="Conformance\BasicGrammarElements\PrecedenceAndOperators\PrecedenceAndOperators.fs" />
<Compile Include="Conformance\BasicTypeAndModuleDefinitions\ExceptionDefinitions\ExceptionDefinitions.fs" />
......@@ -161,7 +161,8 @@
<Compile Include="Language\CastingTests.fs" />
<Compile Include="ConstraintSolver\PrimitiveConstraints.fs" />
<Compile Include="ConstraintSolver\MemberConstraints.fs" />
<Compile Include="Interop\SimpleInteropTests.fs" />
<Compile Include="Interop\SimpleInteropTests.fs" />
<Compile Include="Interop\StaticsInInterfaces.fs" />
<Compile Include="Interop\VisibilityTests.fs" />
<Compile Include="Scripting\Interactive.fs" />
<Compile Include="TypeChecks\CheckDeclarationsTests.fs" />
......
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.ComponentTests.Interop
open Xunit
open FSharp.Test.Compiler
open FSharp.Test
module ``Static Methods In Interfaces`` =
let withCSharpLanguageVersion (ver: CSharpLanguageVersion) (cUnit: CompilationUnit) : CompilationUnit =
match cUnit with
| CS cs -> CS { cs with LangVersion = ver }
| _ -> failwith "Only supported in C#"
let csharpBaseClass =
CSharp """
namespace StaticsInInterfaces
{
public interface IGetNext<T> where T : IGetNext<T>
{
static abstract T Next(T other);
}
public record RepeatSequence : IGetNext<RepeatSequence>
{
private const char Ch = 'A';
public string Text = new string(Ch, 1);
public static RepeatSequence Next(RepeatSequence other) => other with { Text = other.Text + Ch };
public override string ToString() => Text;
}
}""" |> withCSharpLanguageVersion CSharpLanguageVersion.Preview |> withName "csLib"
#if !NETCOREAPP
[<Fact(Skip = "NET472 is unsupported runtime for this kind of test.")>]
#else
[<Fact>]
#endif
let ``F# can call static methods declared in interfaces from C#`` () =
let csharpLib = csharpBaseClass
let fsharpSource =
"""
open System
open StaticsInInterfaces
[<EntryPoint>]
let main _ =
let mutable str = RepeatSequence ()
let res = [ for i in 0..10 do
yield string(str)
str <- RepeatSequence.Next(str) ]
if res <> ["A"; "AA"; "AAA"; "AAAA"; "AAAAA"; "AAAAAA"; "AAAAAAA"; "AAAAAAAA"; "AAAAAAAAA"; "AAAAAAAAAA"; "AAAAAAAAAAA"] then
failwith $"Unexpected result: %A{res}"
if string(str) <> "AAAAAAAAAAAA" then
failwith $"Unexpected result %s{string(str)}"
0
"""
FSharp fsharpSource
|> asExe
|> withLangVersionPreview
|> withReferences [csharpLib]
|> compileAndRun
|> shouldSucceed
// TODO: test operators, test implementing statics.
\ No newline at end of file
......@@ -580,6 +580,8 @@ module rec Compiler =
let lv =
match csSource.LangVersion with
| CSharpLanguageVersion.CSharp8 -> LanguageVersion.CSharp8
| CSharpLanguageVersion.CSharp9 -> LanguageVersion.CSharp9
| CSharpLanguageVersion.Preview -> LanguageVersion.Preview
| _ -> LanguageVersion.Default
let cmpl =
......
......@@ -130,6 +130,7 @@ type TestCompilation =
type CSharpLanguageVersion =
| CSharp8 = 0
| CSharp9 = 1
| Preview = 99
[<AbstractClass; Sealed>]
type CompilationUtil private () =
......@@ -139,6 +140,7 @@ type CompilationUtil private () =
match lv with
| CSharpLanguageVersion.CSharp8 -> LanguageVersion.CSharp8
| CSharpLanguageVersion.CSharp9 -> LanguageVersion.CSharp9
| CSharpLanguageVersion.Preview -> LanguageVersion.Preview
| _ -> LanguageVersion.Default
let tf = defaultArg tf TargetFramework.NetStandard20
......
......@@ -316,8 +316,8 @@ let config configurationName envVars =
let packagesDir = getPackagesDir ()
let requirePackage = requireFile packagesDir
let requireArtifact = requireFile artifactsBinPath
let CSC = requirePackage ("Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "csc.exe")
let VBC = requirePackage ("Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "vbc.exe")
let CSC = requirePackage ("Microsoft.Net.Compilers" ++ "4.3.0-1.22220.8" ++ "tools" ++ "csc.exe")
let VBC = requirePackage ("Microsoft.Net.Compilers" ++ "4.3.0-1.22220.8" ++ "tools" ++ "vbc.exe")
let ILDASM_EXE = if operatingSystem = "win" then "ildasm.exe" else "ildasm"
let ILDASM = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ ILDASM_EXE)
let ILASM_EXE = if operatingSystem = "win" then "ilasm.exe" else "ilasm"
......
......@@ -23,7 +23,7 @@ let nugetCache =
| path -> path
let rootFolder = Path.Combine(__SOURCE_DIRECTORY__, "..", "..")
let compilerBinFolder = Path.Combine(rootFolder, "artifacts", "bin", "fsc", releaseOrDebug, "net472")
setEnvVar "CSC_PIPE" (Path.Combine(nugetCache, "Microsoft.Net.Compilers", "2.7.0", "tools", "csc.exe"))
setEnvVar "CSC_PIPE" (Path.Combine(nugetCache, "Microsoft.Net.Compilers", "4.3.0-1.22220.8", "tools", "csc.exe"))
setEnvVar "FSC" (Path.Combine(compilerBinFolder, "fsc.exe"))
setEnvVar "FSCOREDLLPATH" (Path.Combine(compilerBinFolder, "FSharp.Core.dll"))
addToPath compilerBinFolder
......
......@@ -52,7 +52,6 @@
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="$(MicrosoftVisualStudioShell150Version)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="$(MicrosoftVisualStudioThreadingVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
</ItemGroup>
<ItemGroup>
......
......@@ -194,7 +194,6 @@
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" />
<PackageReference Include="Nerdbank.Streams" Version="$(NerdbankStreamsVersion)" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="StreamJsonRpc" Version="$(StreamJsonRpcVersion)" />
</ItemGroup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册