-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for analysis of simple C# code with FCS.
- Loading branch information
Showing
7 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
#if INTERACTIVE | ||
#r "../../bin/v4.5/FSharp.Compiler.Service.dll" | ||
#r "../../packages/NUnit.2.6.3/lib/nunit.framework.dll" | ||
#load "FsUnit.fs" | ||
#load "Common.fs" | ||
#else | ||
module FSharp.Compiler.Service.Tests.CSharpProjectAnalysis | ||
#endif | ||
|
||
|
||
open NUnit.Framework | ||
open FsUnit | ||
open System | ||
open System.IO | ||
open System.Collections.Generic | ||
|
||
open Microsoft.FSharp.Compiler | ||
open Microsoft.FSharp.Compiler.SourceCodeServices | ||
|
||
open FSharp.Compiler.Service.Tests.Common | ||
|
||
let getProjectReferences (dllFiles, libDirs, otherFlags) = | ||
let otherFlags = defaultArg otherFlags [] | ||
let libDirs = defaultArg libDirs [] | ||
let base1 = Path.GetTempFileName() | ||
let dllName = Path.ChangeExtension(base1, ".dll") | ||
let fileName1 = Path.ChangeExtension(base1, ".fs") | ||
let projFileName = Path.ChangeExtension(base1, ".fsproj") | ||
File.WriteAllText(fileName1, """module M""") | ||
let options = | ||
checker.GetProjectOptionsFromCommandLineArgs(projFileName, | ||
[| yield "--debug:full" | ||
yield "--define:DEBUG" | ||
yield "--optimize-" | ||
yield "--out:" + dllName | ||
yield "--doc:test.xml" | ||
yield "--warn:3" | ||
yield "--fullpaths" | ||
yield "--flaterrors" | ||
yield "--target:library" | ||
for dllFile in dllFiles do | ||
yield "-r:"+dllFile | ||
for libDir in libDirs do | ||
yield "-I:"+libDir | ||
yield! otherFlags | ||
yield fileName1 |]) | ||
let results = checker.ParseAndCheckProject(options) |> Async.RunSynchronously | ||
if results.HasCriticalErrors then | ||
let builder = new System.Text.StringBuilder() | ||
for err in results.Errors do | ||
builder.AppendLine(sprintf "**** %s: %s" (if err.Severity = Microsoft.FSharp.Compiler.Severity.Error then "error" else "warning") err.Message) | ||
|> ignore | ||
failwith (builder.ToString()) | ||
|
||
results.ProjectContext.GetReferencedAssemblies() | ||
|> List.map(fun x -> x.SimpleName, x) | ||
|> dict | ||
|
||
[<Test>] | ||
let ``Test that csharp references are recognized as such`` () = | ||
let csharpAssembly = typeof<CSharpClass>.Assembly.Location | ||
let table = getProjectReferences([csharpAssembly], None, None) | ||
let ass = table.["CSharp_Analysis"] | ||
match ass.Contents.Entities |> Seq.tryFind (fun e -> e.DisplayName = "CSharpClass") with | ||
| Some found -> | ||
// this is no F# thing | ||
found.IsFSharp |> shouldEqual false | ||
|
||
// Check that we have members | ||
let members = found.MembersFunctionsAndValues |> Seq.map (fun e -> e.CompiledName, e) |> dict | ||
members.ContainsKey ".ctor" |> shouldEqual true | ||
members.ContainsKey "Method" |> shouldEqual true | ||
members.ContainsKey "Property" |> shouldEqual true | ||
members.ContainsKey "Event" |> shouldEqual true | ||
members.ContainsKey "InterfaceMethod" |> shouldEqual true | ||
members.ContainsKey "InterfaceProperty" |> shouldEqual true | ||
members.ContainsKey "InterfaceEvent" |> shouldEqual true | ||
|
||
//// Check that we get xml docs | ||
//String.IsNullOrWhiteSpace(members.[".ctor"].XmlDocSig) |> shouldEqual false | ||
//String.IsNullOrWhiteSpace(members.["Method"].XmlDocSig) |> shouldEqual false | ||
//String.IsNullOrWhiteSpace(members.["Property"].XmlDocSig) |> shouldEqual false | ||
//String.IsNullOrWhiteSpace(members.["Event"].XmlDocSig) |> shouldEqual false | ||
//String.IsNullOrWhiteSpace(members.["InterfaceMethod"].XmlDocSig) |> shouldEqual false | ||
//String.IsNullOrWhiteSpace(members.["InterfaceProperty"].XmlDocSig) |> shouldEqual false | ||
//String.IsNullOrWhiteSpace(members.["InterfaceEvent"].XmlDocSig) |> shouldEqual false | ||
|
||
() | ||
| None -> () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.31101.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample_VS2013_CSharp_Library_net45", "Sample_VS2013_CSharp_Library_net45\Sample_VS2013_CSharp_Library_net45.csproj", "{887630A3-4B1D-40EA-B8B3-2D842E9C40DB}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{887630A3-4B1D-40EA-B8B3-2D842E9C40DB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
90 changes: 90 additions & 0 deletions
90
tests/service/CSharp_Analysis/CSharp_Analysis/CSharpClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FSharp.Compiler.Service.Tests | ||
{ | ||
/// <summary> | ||
/// Documentation | ||
/// </summary> | ||
public interface ICSharpInterface | ||
{ | ||
int InterfaceMethod(string parameter); | ||
bool InterfaceProperty { get; } | ||
|
||
event EventHandler InterfaceEvent; | ||
} | ||
|
||
public interface ICSharpExplicitInterface | ||
{ | ||
int ExplicitMethod(string parameter); | ||
bool ExplicitProperty { get; } | ||
|
||
event EventHandler ExplicitEvent; | ||
} | ||
|
||
public class CSharpClass : ICSharpInterface, ICSharpExplicitInterface | ||
{ | ||
/// <summary> | ||
/// Documentaton | ||
/// </summary> | ||
/// <param name="param"></param> | ||
public CSharpClass(int param) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Documentaton | ||
/// </summary> | ||
/// <param name="first"></param> | ||
/// <param name="param"></param> | ||
public CSharpClass(int first, string param) | ||
{ | ||
|
||
} | ||
|
||
public int Method(string parameter) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public bool Property | ||
{ | ||
get { throw new NotImplementedException(); } | ||
} | ||
|
||
public event EventHandler Event; | ||
|
||
|
||
public int InterfaceMethod(string parameter) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public bool InterfaceProperty | ||
{ | ||
get { throw new NotImplementedException(); } | ||
} | ||
|
||
public event EventHandler InterfaceEvent; | ||
|
||
int ICSharpExplicitInterface.ExplicitMethod(string parameter) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
bool ICSharpExplicitInterface.ExplicitProperty | ||
{ | ||
get { throw new NotImplementedException(); } | ||
} | ||
|
||
event EventHandler ICSharpExplicitInterface.ExplicitEvent | ||
{ | ||
add { throw new NotImplementedException(); } | ||
remove { throw new NotImplementedException(); } | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/service/CSharp_Analysis/CSharp_Analysis/CSharp_Analysis.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{887630A3-4B1D-40EA-B8B3-2D842E9C40DB}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>CSharp_Analysis</RootNamespace> | ||
<AssemblyName>CSharp_Analysis</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="CSharpClass.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
36 changes: 36 additions & 0 deletions
36
tests/service/CSharp_Analysis/CSharp_Analysis/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// Allgemeine Informationen über eine Assembly werden über die folgenden | ||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, | ||
// die mit einer Assembly verknüpft sind. | ||
[assembly: AssemblyTitle("CSharp_Analysis")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("CSharp_Analysis")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar | ||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von | ||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. | ||
[assembly: ComVisible(false)] | ||
|
||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird | ||
[assembly: Guid("e1b15939-475d-4134-a76c-20845e07be39")] | ||
|
||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: | ||
// | ||
// Hauptversion | ||
// Nebenversion | ||
// Buildnummer | ||
// Revision | ||
// | ||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern | ||
// übernehmen, indem Sie "*" eingeben: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters