Skip to content

Commit

Permalink
Merge branch 'master' of https://git01.codeplex.com/visualfsharp into…
Browse files Browse the repository at this point in the history
… master-cleanup-1
  • Loading branch information
dsyme committed Nov 29, 2014
2 parents 79b8293 + 4f94347 commit a27f527
Show file tree
Hide file tree
Showing 11 changed files with 676 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/fsharp/fsi/console.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module Utils =
type Cursor =
static member ResetTo(top,left) =
Utils.guard(fun () ->
Console.CursorTop <- top;
Console.CursorTop <- min top (Console.BufferHeight - 1);
Console.CursorLeft <- left)
static member Move(inset, delta) =
let position = Console.CursorTop * (Console.BufferWidth - inset) + (Console.CursorLeft - inset) + delta
Expand Down Expand Up @@ -216,6 +216,7 @@ type ReadLineConsole() =
if currLeft < x.Inset then
if currLeft = 0 then Console.Write (if prompt then x.Prompt2 else String(' ',x.Inset))
Utils.guard(fun () ->
Console.CursorTop <- min Console.CursorTop (Console.BufferHeight - 1);
Console.CursorLeft <- x.Inset);

// The caller writes the primary prompt. If we are reading the 2nd and subsequent lines of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"newVersion"="4.3.1.9055"
"codeBase"="$PackageFolder$\FSharp.Core.dll"

[$RootKey$\RuntimeConfiguration\dependentAssembly\bindingRedirection\{2DB67780-3B09-41E5-A8DC-92AF2E1665BD}}]
[$RootKey$\RuntimeConfiguration\dependentAssembly\bindingRedirection\{2DB67780-3B09-41E5-A8DC-92AF2E1665BD}]
"name"="FSharp.Editor"
"publicKeyToken"="b03f5f7f11d50a3a"
"culture"="neutral"
Expand Down
319 changes: 319 additions & 0 deletions vsintegration/src/unittests/Tests.ProjectSystem.UpToDate.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,319 @@
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace UnitTests.Tests.ProjectSystem

// System namespaces
open System
open System.Collections.Generic
open System.Globalization
open System.IO
open System.Text
open System.Text.RegularExpressions

// VS namespaces
open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio.Shell.Interop
open Microsoft.VisualStudio.FSharp.ProjectSystem

// Internal unittest namespaces
open NUnit.Framework
open Salsa
open UnitTests.TestLib.Utils.Asserts
open UnitTests.TestLib.Utils.FilesystemHelpers
open UnitTests.TestLib.ProjectSystem

[<TestFixture>]
type UpToDate() =
inherit TheTests()

[<Test>]
member public this.ItemInputs () =
this.MakeProjectAndDo(["file1.fs"], [], @"
<ItemGroup>
<Content Include=""content.txt"" />
<Resource Include=""resource.txt"" />
<EmbeddedResource Include=""embedresource.txt"" />
<None Include=""none.txt"" />
</ItemGroup>
", (fun project ->
let configNameDebug = ConfigCanonicalName("Debug", "x86")
let config = project.ConfigProvider.GetProjectConfiguration(configNameDebug)
let output = VsMocks.vsOutputWindowPane(ref [])
let logger = OutputWindowLogger.CreateUpToDateCheckLogger(output)

let sourcePath = Path.Combine(project.ProjectFolder, "file1.fs")
let contentPath = Path.Combine(project.ProjectFolder, "content.txt")
let resourcePath = Path.Combine(project.ProjectFolder, "resource.txt")
let nonePath = Path.Combine(project.ProjectFolder, "none.txt")
let embedPath = Path.Combine(project.ProjectFolder, "embedresource.txt")

let startTime = DateTime.Now

File.AppendAllText(sourcePath, "printfn \"hello\"")
File.AppendAllText(contentPath, "some content")
File.AppendAllText(resourcePath, "some resource")
File.AppendAllText(nonePath, "none")
File.AppendAllText(embedPath, "some embedded resource")

Assert.IsFalse(config.IsUpToDate(logger, true))
project.Build(configNameDebug, output, "Build") |> ignore
Assert.IsTrue(config.IsUpToDate(logger, true))

// None items should not affect up-to-date
File.SetLastWriteTime(nonePath, DateTime.Now.AddMinutes(5.))
Assert.IsTrue(config.IsUpToDate(logger, true))

for path in [sourcePath; contentPath; resourcePath; embedPath] do
printfn "Testing path %s" path

// touch file
File.SetLastWriteTime(path, DateTime.Now.AddMinutes(5.))
Assert.IsFalse(config.IsUpToDate(logger, true))

File.SetLastWriteTime(path, startTime)
Assert.IsTrue(config.IsUpToDate(logger, true))

// delete file
let originalContent = File.ReadAllText(path)
File.Delete(path)
Assert.IsFalse(config.IsUpToDate(logger, true))

File.AppendAllText(path, originalContent)
File.SetLastWriteTime(path, startTime)
Assert.IsTrue(config.IsUpToDate(logger, true))
))

[<Test>]
member public this.PropertyInputs () =
this.MakeProjectAndDo(["file1.fs"], [], @"
<PropertyGroup>
<VersionFile>ver.txt</VersionFile>
<AssemblyOriginatorKeyFile>key.txt</AssemblyOriginatorKeyFile>
</PropertyGroup>
", (fun project ->
let configNameDebug = ConfigCanonicalName("Debug", "x86")
let config = project.ConfigProvider.GetProjectConfiguration(configNameDebug)
let output = VsMocks.vsOutputWindowPane(ref [])
let logger = OutputWindowLogger.CreateUpToDateCheckLogger(output)

let sourcePath = Path.Combine(project.ProjectFolder, "file1.fs")
let verPath = Path.Combine(project.ProjectFolder, "ver.txt")
let keyPath = Path.Combine(project.ProjectFolder, "key.txt")

let startTime = DateTime.Now

File.AppendAllText(sourcePath, "printfn \"hello\"")
File.AppendAllText(verPath, "1.2.3.4")
File.AppendAllText(keyPath, "a key")

project.SetConfiguration(config.ConfigCanonicalName);
Assert.IsFalse(config.IsUpToDate(logger, true))
project.Build(configNameDebug, output, "Build") |> ignore
Assert.IsTrue(config.IsUpToDate(logger, true))

for path in [verPath; keyPath] do
printfn "Testing path %s" path

// touch file
File.SetLastWriteTime(path, DateTime.Now.AddMinutes(5.))
Assert.IsFalse(config.IsUpToDate(logger, true))

File.SetLastWriteTime(path, startTime)
Assert.IsTrue(config.IsUpToDate(logger, true))

// delete file
let originalContent = File.ReadAllText(path)
File.Delete(path)
Assert.IsFalse(config.IsUpToDate(logger, true))

File.AppendAllText(path, originalContent)
File.SetLastWriteTime(path, startTime)
Assert.IsTrue(config.IsUpToDate(logger, true))
))

[<Test>]
member public this.ProjectFile () =
this.MakeProjectAndDoWithProjectFile(["file1.fs"], [], "", (fun project projFileName ->
let configNameDebug = ConfigCanonicalName("Debug", "x86")
let config = project.ConfigProvider.GetProjectConfiguration(configNameDebug)
let output = VsMocks.vsOutputWindowPane(ref [])
let logger = OutputWindowLogger.CreateUpToDateCheckLogger(output)
let absFilePath = Path.Combine(project.ProjectFolder, "file1.fs")
let startTime = DateTime.Now
File.AppendAllText(absFilePath, "printfn \"hello\"")

Assert.IsFalse(config.IsUpToDate(logger, true))
project.Build(configNameDebug, output, "Build") |> ignore
Assert.IsTrue(config.IsUpToDate(logger, true))

// touch proj file
File.SetLastWriteTime(projFileName, DateTime.Now.AddMinutes(5.))
Assert.IsFalse(config.IsUpToDate(logger, true))

File.SetLastWriteTime(projFileName, startTime)
Assert.IsTrue(config.IsUpToDate(logger, true))
))

[<Test>]
member public this.References () =
let configNameDebug = ConfigCanonicalName("Debug", "x86")
let output = VsMocks.vsOutputWindowPane(ref [])
let logger = OutputWindowLogger.CreateUpToDateCheckLogger(output)

DoWithTempFile "Proj1.fsproj" (fun proj1Path ->
File.AppendAllText(proj1Path, TheTests.SimpleFsprojText(
["File1.fs"], // <Compile>
[], // <Reference>
"<PropertyGroup><TargetFrameworkVersion>v4.5</TargetFrameworkVersion></PropertyGroup>")) // other stuff
use project1 = TheTests.CreateProject(proj1Path)
let sourcePath1 = Path.Combine(project1.ProjectFolder, "File1.fs")
File.AppendAllText(sourcePath1, "namespace Proj1\r\n")
File.AppendAllText(sourcePath1, "module Test =\r\n")
File.AppendAllText(sourcePath1, " let X = 5\r\n")

let config1 = project1.ConfigProvider.GetProjectConfiguration(configNameDebug)

Assert.IsFalse(config1.IsUpToDate(logger, true))
project1.Build(configNameDebug, output, "Build") |> ignore
Assert.IsTrue(config1.IsUpToDate(logger, true))

let output1 = Path.Combine(project1.ProjectFolder, "bin\\debug", project1.OutputFileName)

DoWithTempFile "Proj2.fsproj" (fun proj2Path ->
File.AppendAllText(proj2Path, TheTests.SimpleFsprojText(
["File2.fs"], // <Compile>
[output1], // <Reference>
"<PropertyGroup><TargetFrameworkVersion>v4.5</TargetFrameworkVersion></PropertyGroup>")) // other stuff
use project2 = TheTests.CreateProject(proj2Path)
let sourcePath2 = Path.Combine(project2.ProjectFolder, "File2.fs")
File.AppendAllText(sourcePath2, "open Proj1\r\n")
File.AppendAllText(sourcePath2, "let x = Test.X")

let config2 = project2.ConfigProvider.GetProjectConfiguration(configNameDebug)
let startTime = DateTime.Now

Assert.IsFalse(config2.IsUpToDate(logger, true))
project2.Build(configNameDebug, output, "Build") |> ignore
Assert.IsTrue(config2.IsUpToDate(logger, true))

// reference is updated
File.SetLastWriteTime(output1, DateTime.Now.AddMinutes(5.))
Assert.IsFalse(config2.IsUpToDate(logger, true))
File.SetLastWriteTime(output1, startTime)
Assert.IsTrue(config2.IsUpToDate(logger, true))

// reference is missing
File.Delete(output1)
Assert.IsFalse(config2.IsUpToDate(logger, true))
)
)

[<Test>]
member public this.OutputFiles () =
this.MakeProjectAndDo(["file1.fs"], [], @"
<PropertyGroup>
<DocumentationFile>bin\Debug\Test.XML</DocumentationFile>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
</PropertyGroup>", (fun project ->
let configNameDebug = ConfigCanonicalName("Debug", "x86")
let config = project.ConfigProvider.GetProjectConfiguration(configNameDebug)
let output = VsMocks.vsOutputWindowPane(ref [])
let logger = OutputWindowLogger.CreateUpToDateCheckLogger(output)
let sourcePath = Path.Combine(project.ProjectFolder, "file1.fs")

let exeObjPath = Path.Combine(project.ProjectFolder, "obj\\x86\\debug", project.OutputFileName)
let exeBinpath = Path.Combine(project.ProjectFolder, "bin\\debug\\", project.OutputFileName)
let pdbObjPath = Regex.Replace(exeObjPath, "exe$", "pdb")
let pdbBinPath = Regex.Replace(exeBinpath, "exe$", "pdb")
let xmlDocPath = Regex.Replace(exeBinpath, "exe$", "xml")

File.AppendAllText(sourcePath, "printfn \"hello\"")

Assert.IsFalse(config.IsUpToDate(logger, true))
project.Build(configNameDebug, output, "Build") |> ignore
Assert.IsTrue(config.IsUpToDate(logger, true))

let startTime = DateTime.Now

for path in [exeObjPath; exeBinpath; pdbObjPath; pdbBinPath; xmlDocPath] do
printfn "Testing output %s" path

// touch file
File.SetLastWriteTime(path, DateTime.Now.AddMinutes(-5.))
Assert.IsFalse(config.IsUpToDate(logger, true))

File.SetLastWriteTime(path, startTime)
Assert.IsTrue(config.IsUpToDate(logger, true))

// delete file
let originalContent = File.ReadAllBytes(path)
File.Delete(path)
Assert.IsFalse(config.IsUpToDate(logger, true))

File.WriteAllBytes(path, originalContent)
File.SetLastWriteTime(path, startTime)
Assert.IsTrue(config.IsUpToDate(logger, true))
))

[<Test>]
member public this.ConfigChanges () =
this.MakeProjectAndDo(["file1.fs"], [], "", (fun project ->
let configNameDebugx86 = ConfigCanonicalName("Debug", "x86")
let configNameReleasex86 = ConfigCanonicalName("Release", "x86")
let configNameDebugAnyCPU = ConfigCanonicalName("Debug", "AnyCPU")
let configNameReleaseAnyCPU = ConfigCanonicalName("Release", "AnyCPU")

let debugConfigx86 = project.ConfigProvider.GetProjectConfiguration(configNameDebugx86)
let releaseConfigx86 = project.ConfigProvider.GetProjectConfiguration(configNameReleasex86)
let debugConfigAnyCPU = project.ConfigProvider.GetProjectConfiguration(configNameDebugAnyCPU)
let releaseConfigAnyCPU = project.ConfigProvider.GetProjectConfiguration(configNameReleaseAnyCPU)

let output = VsMocks.vsOutputWindowPane(ref [])
let logger = OutputWindowLogger.CreateUpToDateCheckLogger(output)

let sourcePath = Path.Combine(project.ProjectFolder, "file1.fs")
File.AppendAllText(sourcePath, "printfn \"hello\"")

Assert.IsFalse(debugConfigx86.IsUpToDate(logger, true))
Assert.IsFalse(releaseConfigx86.IsUpToDate(logger, true))
Assert.IsFalse(debugConfigAnyCPU.IsUpToDate(logger, true))
Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger, true))

project.Build(configNameDebugx86, output, "Build") |> ignore
Assert.IsTrue(debugConfigx86.IsUpToDate(logger, true))
Assert.IsFalse(releaseConfigx86.IsUpToDate(logger, true))
Assert.IsFalse(debugConfigAnyCPU.IsUpToDate(logger, true))
Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger, true))

project.Build(configNameReleasex86, output, "Build") |> ignore
Assert.IsTrue(debugConfigx86.IsUpToDate(logger, true))
Assert.IsTrue(releaseConfigx86.IsUpToDate(logger, true))
Assert.IsFalse(debugConfigAnyCPU.IsUpToDate(logger, true))
Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger, true))

project.Build(configNameDebugAnyCPU, output, "Build") |> ignore
Assert.IsTrue(debugConfigx86.IsUpToDate(logger, true))
Assert.IsTrue(releaseConfigx86.IsUpToDate(logger, true))
Assert.IsTrue(debugConfigAnyCPU.IsUpToDate(logger, true))
Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger, true))

project.Build(configNameReleaseAnyCPU, output, "Build") |> ignore
Assert.IsTrue(debugConfigx86.IsUpToDate(logger, true))
Assert.IsTrue(releaseConfigx86.IsUpToDate(logger, true))
Assert.IsTrue(debugConfigAnyCPU.IsUpToDate(logger, true))
Assert.IsTrue(releaseConfigAnyCPU.IsUpToDate(logger, true))
))

[<Test>]
member public this.UTDCheckEnabled () =
this.MakeProjectAndDo(["file1.fs"], [], @"
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
", (fun project ->
let configNameDebug = ConfigCanonicalName("Debug", "x86")
let config = project.ConfigProvider.GetProjectConfiguration(configNameDebug)

Assert.IsFalse(config.IsFastUpToDateCheckEnabled())
))
1 change: 1 addition & 0 deletions vsintegration/src/unittests/Unittests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="Tests.ProjectSystem.Project.fs" />
<Compile Include="Tests.ProjectSystem.References.fs" />
<Compile Include="Tests.ProjectSystem.RoundTrip.fs" />
<Compile Include="Tests.ProjectSystem.UpToDate.fs" />
<CustomCopyLocal Include="Unittests.dll.config">
<TargetFilename>Unittests.dll.config</TargetFilename>
</CustomCopyLocal>
Expand Down
Loading

0 comments on commit a27f527

Please sign in to comment.