forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://git01.codeplex.com/visualfsharp into…
… master-cleanup-1
- Loading branch information
Showing
11 changed files
with
676 additions
and
36 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
319 changes: 319 additions & 0 deletions
319
vsintegration/src/unittests/Tests.ProjectSystem.UpToDate.fs
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,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()) | ||
)) |
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
Oops, something went wrong.