Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions samples/EditorService/EditorService.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
<Private>False</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
Expand All @@ -59,12 +59,12 @@
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0' OR '$(VisualStudioVersion)' == '11.0'">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0' OR '$(VisualStudioVersion)' == '11.0'">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
<!-- 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.
Expand Down
14 changes: 7 additions & 7 deletions samples/Tokenizer/Tokenizer.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
<Private>False</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
Expand All @@ -59,12 +59,12 @@
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0' OR '$(VisualStudioVersion)' == '11.0'">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0' OR '$(VisualStudioVersion)' == '11.0'">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
<!-- 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.
Expand Down
14 changes: 7 additions & 7 deletions samples/UntypedTree/UntypedTree.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
<Private>False</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
Expand All @@ -59,12 +59,12 @@
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0' OR '$(VisualStudioVersion)' == '11.0'">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0' OR '$(VisualStudioVersion)' == '11.0'">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
<!-- 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.
Expand Down
2 changes: 2 additions & 0 deletions tests/service/FSharp.Compiler.Service.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="Common.fs" />
<Compile Include="EditorTests.fs" />
<Compile Include="FsiTests.fs" />
<Compile Include="FscTests.fs" />
<Compile Include="TokenizerTests.fs" />
<Compile Include="FileSystemTests.fs" />
<Compile Include="ProjectAnalysisTests.fs" />
Expand All @@ -64,6 +65,7 @@
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="mscorlib" />
<Reference Include="nunit.framework">
<HintPath>..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
Expand Down
135 changes: 135 additions & 0 deletions tests/service/FscTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
module FSharp.Compiler.Service.Tests.FscTests

open System
open System.Diagnostics
open System.IO

open Microsoft.Build.Utilities
open Microsoft.FSharp.Compiler

open NUnit.Framework

exception VerificationException of (*assembly:*)string * (*errorCode:*)int * (*output:*)string
with
override e.Message = sprintf "Verification of '%s' failed with code %d." e.Data0 e.Data1

exception CompilationError of (*assembly:*)string * (*errorCode:*)int * (*info:*)ErrorInfo []
with
override e.Message = sprintf "Compilation of '%s' failed with code %d (%A)" e.Data0 e.Data1 e.Data2

type PEVerifier () =

static let expectedExitCode = 0

let runsOnMono = try System.Type.GetType("Mono.Runtime") <> null with _ -> false
let verifierPath, switches =
if runsOnMono then
"pedump", "--verify all"
else
let path = ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("peverify.exe", TargetDotNetFrameworkVersion.VersionLatest)
path, "/UNIQUE /IL /NOLOGO"

static let execute (fileName : string, arguments : string) =
let psi = new ProcessStartInfo(fileName, arguments)
psi.UseShellExecute <- false
psi.ErrorDialog <- false
psi.CreateNoWindow <- true
psi.RedirectStandardOutput <- true
psi.RedirectStandardError <- true

use proc = Process.Start(psi)
let stdOut = proc.StandardOutput.ReadToEnd()
let stdErr = proc.StandardError.ReadToEnd()
while not proc.HasExited do ()
proc.ExitCode, stdOut, stdErr

member __.Verify(assemblyPath : string) =
let id,stdOut,stdErr = execute(verifierPath, sprintf "%s \"%s\"" switches assemblyPath)
if id = expectedExitCode && String.IsNullOrWhiteSpace stdErr then ()
else
raise <| VerificationException(assemblyPath, id, stdOut + "\n" + stdErr)


type DebugMode =
| Off
| PdbOnly
| Full

let compileAndVerify isDll debugMode (assemblyName : string) (code : string) (dependencies : string list) =
let scs = new Microsoft.FSharp.Compiler.SimpleSourceCodeServices.SimpleSourceCodeServices()
let verifier = new PEVerifier ()
let tmp = Path.GetTempPath()
let sourceFile = Path.Combine(tmp, assemblyName + ".fs")
let outFile = Path.Combine(tmp, assemblyName + if isDll then ".dll" else ".exe")
let pdbFile = Path.Combine(tmp, assemblyName + ".pdb")
do File.WriteAllText(sourceFile, code)
let args =
[|
// fsc parser skips the first argument by default;
// perhaps this shouldn't happen in library code.
yield "fsc.exe"

if isDll then yield "--target:library"

match debugMode with
| Off -> () // might need to include some switches here
| PdbOnly ->
yield "--debug:pdbonly"
yield sprintf "--pdb:%s" pdbFile
| Full ->
yield "--debug:full"
yield sprintf "--pdb:%s" pdbFile

for d in dependencies do
yield sprintf "-r:%s" d

yield sprintf "--out:%s" outFile

yield sourceFile
|]

let errorInfo, id = scs.Compile args
if id <> 0 then raise <| CompilationError(assemblyName, id, errorInfo)
verifier.Verify outFile
outFile


[<Test>]
let ``1. PEVerifier sanity check`` () =
let verifier = new PEVerifier()

let fscorlib = typeof<int option>.Assembly
verifier.Verify fscorlib.Location

let nonAssembly = Path.Combine(Directory.GetCurrentDirectory(), typeof<PEVerifier>.Assembly.GetName().Name + ".pdb")
Assert.Throws<VerificationException>(fun () -> verifier.Verify nonAssembly |> ignore) |> ignore


[<Test>]
let ``2. Simple FSC library test`` () =
let code = """
module Foo

let f x = (x,x)

type Foo = class end

exception E of int * string
"""

compileAndVerify true PdbOnly "Foo" code [] |> ignore

[<Test>]
let ``3. Simple FSC executable test`` () =
let code = """
module Bar

[<EntryPoint>]
let main _ = printfn "Hello, World!" ; 42

"""
let outFile = compileAndVerify false PdbOnly "Bar" code []

use proc = Process.Start(outFile, "")
while not proc.HasExited do ()
Assert.AreEqual(proc.ExitCode, 42)