|
| 1 | +// 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. |
| 2 | + |
| 3 | +namespaceUnitTests.Tests.ProjectSystem |
| 4 | + |
| 5 | +// System namespaces |
| 6 | +openSystem |
| 7 | +openSystem.Collections.Generic |
| 8 | +openSystem.Globalization |
| 9 | +openSystem.IO |
| 10 | +openSystem.Text |
| 11 | +openSystem.Text.RegularExpressions |
| 12 | + |
| 13 | +// VS namespaces |
| 14 | +openMicrosoft.VisualStudio.Shell |
| 15 | +openMicrosoft.VisualStudio.Shell.Interop |
| 16 | +openMicrosoft.VisualStudio.FSharp.ProjectSystem |
| 17 | + |
| 18 | +// Internal unittest namespaces |
| 19 | +openNUnit.Framework |
| 20 | +openSalsa |
| 21 | +openUnitTests.TestLib.Utils.Asserts |
| 22 | +openUnitTests.TestLib.Utils.FilesystemHelpers |
| 23 | +openUnitTests.TestLib.ProjectSystem |
| 24 | + |
| 25 | +[<TestFixture>] |
| 26 | +typeUpToDate()= |
| 27 | +inherit TheTests() |
| 28 | + |
| 29 | +[<Test>] |
| 30 | +memberpublicthis.ItemInputs()= |
| 31 | + this.MakeProjectAndDo(["file1.fs"],[],@" |
| 32 | + <ItemGroup> |
| 33 | + <Content Include=""content.txt"" /> |
| 34 | + <Resource Include=""resource.txt"" /> |
| 35 | + <EmbeddedResource Include=""embedresource.txt"" /> |
| 36 | + <None Include=""none.txt"" /> |
| 37 | + </ItemGroup> |
| 38 | +",(fun project-> |
| 39 | +letconfigNameDebug= ConfigCanonicalName("Debug","x86") |
| 40 | +letconfig= project.ConfigProvider.GetProjectConfiguration(configNameDebug) |
| 41 | +letoutput= VsMocks.vsOutputWindowPane(ref[]) |
| 42 | +letlogger= OutputWindowLogger.CreateUpToDateCheckLogger(output) |
| 43 | + |
| 44 | +letsourcePath= Path.Combine(project.ProjectFolder,"file1.fs") |
| 45 | +letcontentPath= Path.Combine(project.ProjectFolder,"content.txt") |
| 46 | +letresourcePath= Path.Combine(project.ProjectFolder,"resource.txt") |
| 47 | +letnonePath= Path.Combine(project.ProjectFolder,"none.txt") |
| 48 | +letembedPath= Path.Combine(project.ProjectFolder,"embedresource.txt") |
| 49 | + |
| 50 | +letstartTime= DateTime.Now |
| 51 | + |
| 52 | + File.AppendAllText(sourcePath,"printfn\"hello\"") |
| 53 | + File.AppendAllText(contentPath,"some content") |
| 54 | + File.AppendAllText(resourcePath,"some resource") |
| 55 | + File.AppendAllText(nonePath,"none") |
| 56 | + File.AppendAllText(embedPath,"some embedded resource") |
| 57 | + |
| 58 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 59 | + project.Build(configNameDebug, output,"Build")|> ignore |
| 60 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 61 | + |
| 62 | +// None items should not affect up-to-date |
| 63 | + File.SetLastWriteTime(nonePath, DateTime.Now.AddMinutes(5.)) |
| 64 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 65 | + |
| 66 | +for pathin[sourcePath; contentPath; resourcePath; embedPath]do |
| 67 | + printfn"Testing path%s" path |
| 68 | + |
| 69 | +// touch file |
| 70 | + File.SetLastWriteTime(path, DateTime.Now.AddMinutes(5.)) |
| 71 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 72 | + |
| 73 | + File.SetLastWriteTime(path, startTime) |
| 74 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 75 | + |
| 76 | +// delete file |
| 77 | +letoriginalContent= File.ReadAllText(path) |
| 78 | + File.Delete(path) |
| 79 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 80 | + |
| 81 | + File.AppendAllText(path, originalContent) |
| 82 | + File.SetLastWriteTime(path, startTime) |
| 83 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 84 | +)) |
| 85 | + |
| 86 | +[<Test>] |
| 87 | +memberpublicthis.PropertyInputs()= |
| 88 | + this.MakeProjectAndDo(["file1.fs"],[],@" |
| 89 | + <PropertyGroup> |
| 90 | + <VersionFile>ver.txt</VersionFile> |
| 91 | + <AssemblyOriginatorKeyFile>key.txt</AssemblyOriginatorKeyFile> |
| 92 | + </PropertyGroup> |
| 93 | +",(fun project-> |
| 94 | +letconfigNameDebug= ConfigCanonicalName("Debug","x86") |
| 95 | +letconfig= project.ConfigProvider.GetProjectConfiguration(configNameDebug) |
| 96 | +letoutput= VsMocks.vsOutputWindowPane(ref[]) |
| 97 | +letlogger= OutputWindowLogger.CreateUpToDateCheckLogger(output) |
| 98 | + |
| 99 | +letsourcePath= Path.Combine(project.ProjectFolder,"file1.fs") |
| 100 | +letverPath= Path.Combine(project.ProjectFolder,"ver.txt") |
| 101 | +letkeyPath= Path.Combine(project.ProjectFolder,"key.txt") |
| 102 | + |
| 103 | +letstartTime= DateTime.Now |
| 104 | + |
| 105 | + File.AppendAllText(sourcePath,"printfn\"hello\"") |
| 106 | + File.AppendAllText(verPath,"1.2.3.4") |
| 107 | + File.AppendAllText(keyPath,"a key") |
| 108 | + |
| 109 | + project.SetConfiguration(config.ConfigCanonicalName); |
| 110 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 111 | + project.Build(configNameDebug, output,"Build")|> ignore |
| 112 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 113 | + |
| 114 | +for pathin[verPath; keyPath]do |
| 115 | + printfn"Testing path%s" path |
| 116 | + |
| 117 | +// touch file |
| 118 | + File.SetLastWriteTime(path, DateTime.Now.AddMinutes(5.)) |
| 119 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 120 | + |
| 121 | + File.SetLastWriteTime(path, startTime) |
| 122 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 123 | + |
| 124 | +// delete file |
| 125 | +letoriginalContent= File.ReadAllText(path) |
| 126 | + File.Delete(path) |
| 127 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 128 | + |
| 129 | + File.AppendAllText(path, originalContent) |
| 130 | + File.SetLastWriteTime(path, startTime) |
| 131 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 132 | +)) |
| 133 | + |
| 134 | +[<Test>] |
| 135 | +memberpublicthis.ProjectFile()= |
| 136 | + this.MakeProjectAndDoWithProjectFile(["file1.fs"],[],"",(fun project projFileName-> |
| 137 | +letconfigNameDebug= ConfigCanonicalName("Debug","x86") |
| 138 | +letconfig= project.ConfigProvider.GetProjectConfiguration(configNameDebug) |
| 139 | +letoutput= VsMocks.vsOutputWindowPane(ref[]) |
| 140 | +letlogger= OutputWindowLogger.CreateUpToDateCheckLogger(output) |
| 141 | +letabsFilePath= Path.Combine(project.ProjectFolder,"file1.fs") |
| 142 | +letstartTime= DateTime.Now |
| 143 | + File.AppendAllText(absFilePath,"printfn\"hello\"") |
| 144 | + |
| 145 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 146 | + project.Build(configNameDebug, output,"Build")|> ignore |
| 147 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 148 | + |
| 149 | +// touch proj file |
| 150 | + File.SetLastWriteTime(projFileName, DateTime.Now.AddMinutes(5.)) |
| 151 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 152 | + |
| 153 | + File.SetLastWriteTime(projFileName, startTime) |
| 154 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 155 | +)) |
| 156 | + |
| 157 | +[<Test>] |
| 158 | +memberpublicthis.References()= |
| 159 | +letconfigNameDebug= ConfigCanonicalName("Debug","x86") |
| 160 | +letoutput= VsMocks.vsOutputWindowPane(ref[]) |
| 161 | +letlogger= OutputWindowLogger.CreateUpToDateCheckLogger(output) |
| 162 | + |
| 163 | + DoWithTempFile"Proj1.fsproj"(fun proj1Path-> |
| 164 | + File.AppendAllText(proj1Path, TheTests.SimpleFsprojText( |
| 165 | +["File1.fs"],// <Compile> |
| 166 | +[],// <Reference> |
| 167 | +"<PropertyGroup><TargetFrameworkVersion>v4.5</TargetFrameworkVersion></PropertyGroup>"))// other stuff |
| 168 | +use project1= TheTests.CreateProject(proj1Path) |
| 169 | +letsourcePath1= Path.Combine(project1.ProjectFolder,"File1.fs") |
| 170 | + File.AppendAllText(sourcePath1,"namespace Proj1\r\n") |
| 171 | + File.AppendAllText(sourcePath1,"module Test =\r\n") |
| 172 | + File.AppendAllText(sourcePath1," let X = 5\r\n") |
| 173 | + |
| 174 | +letconfig1= project1.ConfigProvider.GetProjectConfiguration(configNameDebug) |
| 175 | + |
| 176 | + Assert.IsFalse(config1.IsUpToDate(logger,true)) |
| 177 | + project1.Build(configNameDebug, output,"Build")|> ignore |
| 178 | + Assert.IsTrue(config1.IsUpToDate(logger,true)) |
| 179 | + |
| 180 | +letoutput1= Path.Combine(project1.ProjectFolder,"bin\\debug", project1.OutputFileName) |
| 181 | + |
| 182 | + DoWithTempFile"Proj2.fsproj"(fun proj2Path-> |
| 183 | + File.AppendAllText(proj2Path, TheTests.SimpleFsprojText( |
| 184 | +["File2.fs"],// <Compile> |
| 185 | +[output1],// <Reference> |
| 186 | +"<PropertyGroup><TargetFrameworkVersion>v4.5</TargetFrameworkVersion></PropertyGroup>"))// other stuff |
| 187 | +use project2= TheTests.CreateProject(proj2Path) |
| 188 | +letsourcePath2= Path.Combine(project2.ProjectFolder,"File2.fs") |
| 189 | + File.AppendAllText(sourcePath2,"open Proj1\r\n") |
| 190 | + File.AppendAllText(sourcePath2,"let x = Test.X") |
| 191 | + |
| 192 | +letconfig2= project2.ConfigProvider.GetProjectConfiguration(configNameDebug) |
| 193 | +letstartTime= DateTime.Now |
| 194 | + |
| 195 | + Assert.IsFalse(config2.IsUpToDate(logger,true)) |
| 196 | + project2.Build(configNameDebug, output,"Build")|> ignore |
| 197 | + Assert.IsTrue(config2.IsUpToDate(logger,true)) |
| 198 | + |
| 199 | +// reference is updated |
| 200 | + File.SetLastWriteTime(output1, DateTime.Now.AddMinutes(5.)) |
| 201 | + Assert.IsFalse(config2.IsUpToDate(logger,true)) |
| 202 | + File.SetLastWriteTime(output1, startTime) |
| 203 | + Assert.IsTrue(config2.IsUpToDate(logger,true)) |
| 204 | + |
| 205 | +// reference is missing |
| 206 | + File.Delete(output1) |
| 207 | + Assert.IsFalse(config2.IsUpToDate(logger,true)) |
| 208 | +) |
| 209 | +) |
| 210 | + |
| 211 | +[<Test>] |
| 212 | +memberpublicthis.OutputFiles()= |
| 213 | + this.MakeProjectAndDo(["file1.fs"],[],@" |
| 214 | + <PropertyGroup> |
| 215 | + <DocumentationFile>bin\Debug\Test.XML</DocumentationFile> |
| 216 | + <DebugSymbols>true</DebugSymbols> |
| 217 | + <DebugType>full</DebugType> |
| 218 | + </PropertyGroup>",(fun project-> |
| 219 | +letconfigNameDebug= ConfigCanonicalName("Debug","x86") |
| 220 | +letconfig= project.ConfigProvider.GetProjectConfiguration(configNameDebug) |
| 221 | +letoutput= VsMocks.vsOutputWindowPane(ref[]) |
| 222 | +letlogger= OutputWindowLogger.CreateUpToDateCheckLogger(output) |
| 223 | +letsourcePath= Path.Combine(project.ProjectFolder,"file1.fs") |
| 224 | + |
| 225 | +letexeObjPath= Path.Combine(project.ProjectFolder,"obj\\x86\\debug", project.OutputFileName) |
| 226 | +letexeBinpath= Path.Combine(project.ProjectFolder,"bin\\debug\\", project.OutputFileName) |
| 227 | +letpdbObjPath= Regex.Replace(exeObjPath,"exe$","pdb") |
| 228 | +letpdbBinPath= Regex.Replace(exeBinpath,"exe$","pdb") |
| 229 | +letxmlDocPath= Regex.Replace(exeBinpath,"exe$","xml") |
| 230 | + |
| 231 | + File.AppendAllText(sourcePath,"printfn\"hello\"") |
| 232 | + |
| 233 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 234 | + project.Build(configNameDebug, output,"Build")|> ignore |
| 235 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 236 | + |
| 237 | +letstartTime= DateTime.Now |
| 238 | + |
| 239 | +for pathin[exeObjPath; exeBinpath; pdbObjPath; pdbBinPath; xmlDocPath]do |
| 240 | + printfn"Testing output%s" path |
| 241 | + |
| 242 | +// touch file |
| 243 | + File.SetLastWriteTime(path, DateTime.Now.AddMinutes(-5.)) |
| 244 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 245 | + |
| 246 | + File.SetLastWriteTime(path, startTime) |
| 247 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 248 | + |
| 249 | +// delete file |
| 250 | +letoriginalContent= File.ReadAllBytes(path) |
| 251 | + File.Delete(path) |
| 252 | + Assert.IsFalse(config.IsUpToDate(logger,true)) |
| 253 | + |
| 254 | + File.WriteAllBytes(path, originalContent) |
| 255 | + File.SetLastWriteTime(path, startTime) |
| 256 | + Assert.IsTrue(config.IsUpToDate(logger,true)) |
| 257 | +)) |
| 258 | + |
| 259 | +[<Test>] |
| 260 | +memberpublicthis.ConfigChanges()= |
| 261 | + this.MakeProjectAndDo(["file1.fs"],[],"",(fun project-> |
| 262 | +letconfigNameDebugx86= ConfigCanonicalName("Debug","x86") |
| 263 | +letconfigNameReleasex86= ConfigCanonicalName("Release","x86") |
| 264 | +letconfigNameDebugAnyCPU= ConfigCanonicalName("Debug","AnyCPU") |
| 265 | +letconfigNameReleaseAnyCPU= ConfigCanonicalName("Release","AnyCPU") |
| 266 | + |
| 267 | +letdebugConfigx86= project.ConfigProvider.GetProjectConfiguration(configNameDebugx86) |
| 268 | +letreleaseConfigx86= project.ConfigProvider.GetProjectConfiguration(configNameReleasex86) |
| 269 | +letdebugConfigAnyCPU= project.ConfigProvider.GetProjectConfiguration(configNameDebugAnyCPU) |
| 270 | +letreleaseConfigAnyCPU= project.ConfigProvider.GetProjectConfiguration(configNameReleaseAnyCPU) |
| 271 | + |
| 272 | +letoutput= VsMocks.vsOutputWindowPane(ref[]) |
| 273 | +letlogger= OutputWindowLogger.CreateUpToDateCheckLogger(output) |
| 274 | + |
| 275 | +letsourcePath= Path.Combine(project.ProjectFolder,"file1.fs") |
| 276 | + File.AppendAllText(sourcePath,"printfn\"hello\"") |
| 277 | + |
| 278 | + Assert.IsFalse(debugConfigx86.IsUpToDate(logger,true)) |
| 279 | + Assert.IsFalse(releaseConfigx86.IsUpToDate(logger,true)) |
| 280 | + Assert.IsFalse(debugConfigAnyCPU.IsUpToDate(logger,true)) |
| 281 | + Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger,true)) |
| 282 | + |
| 283 | + project.Build(configNameDebugx86, output,"Build")|> ignore |
| 284 | + Assert.IsTrue(debugConfigx86.IsUpToDate(logger,true)) |
| 285 | + Assert.IsFalse(releaseConfigx86.IsUpToDate(logger,true)) |
| 286 | + Assert.IsFalse(debugConfigAnyCPU.IsUpToDate(logger,true)) |
| 287 | + Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger,true)) |
| 288 | + |
| 289 | + project.Build(configNameReleasex86, output,"Build")|> ignore |
| 290 | + Assert.IsTrue(debugConfigx86.IsUpToDate(logger,true)) |
| 291 | + Assert.IsTrue(releaseConfigx86.IsUpToDate(logger,true)) |
| 292 | + Assert.IsFalse(debugConfigAnyCPU.IsUpToDate(logger,true)) |
| 293 | + Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger,true)) |
| 294 | + |
| 295 | + project.Build(configNameDebugAnyCPU, output,"Build")|> ignore |
| 296 | + Assert.IsTrue(debugConfigx86.IsUpToDate(logger,true)) |
| 297 | + Assert.IsTrue(releaseConfigx86.IsUpToDate(logger,true)) |
| 298 | + Assert.IsTrue(debugConfigAnyCPU.IsUpToDate(logger,true)) |
| 299 | + Assert.IsFalse(releaseConfigAnyCPU.IsUpToDate(logger,true)) |
| 300 | + |
| 301 | + project.Build(configNameReleaseAnyCPU, output,"Build")|> ignore |
| 302 | + Assert.IsTrue(debugConfigx86.IsUpToDate(logger,true)) |
| 303 | + Assert.IsTrue(releaseConfigx86.IsUpToDate(logger,true)) |
| 304 | + Assert.IsTrue(debugConfigAnyCPU.IsUpToDate(logger,true)) |
| 305 | + Assert.IsTrue(releaseConfigAnyCPU.IsUpToDate(logger,true)) |
| 306 | +)) |
| 307 | + |
| 308 | +[<Test>] |
| 309 | +memberpublicthis.UTDCheckEnabled()= |
| 310 | + this.MakeProjectAndDo(["file1.fs"],[],@" |
| 311 | + <PropertyGroup> |
| 312 | + <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> |
| 313 | + </PropertyGroup> |
| 314 | +",(fun project-> |
| 315 | +letconfigNameDebug= ConfigCanonicalName("Debug","x86") |
| 316 | +letconfig= project.ConfigProvider.GetProjectConfiguration(configNameDebug) |
| 317 | + |
| 318 | + Assert.IsFalse(config.IsFastUpToDateCheckEnabled()) |
| 319 | +)) |