diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-05-30 18:55:10 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-05-31 15:11:21 +1000 |
| commit | 64fe8bccc329ac5dc0d510bfbd73054d478ddc37 (patch) | |
| tree | 21cc3d21b3b3a689e434f5a387ad98551eb3486c /src/test/WixToolsetTest.MSBuild/MsbuildFixture.cs | |
| parent | 2b9f1c20452b582af1962449e0b662d6ec942728 (diff) | |
| download | wix-64fe8bccc329ac5dc0d510bfbd73054d478ddc37.tar.gz wix-64fe8bccc329ac5dc0d510bfbd73054d478ddc37.tar.bz2 wix-64fe8bccc329ac5dc0d510bfbd73054d478ddc37.zip | |
Move most tests into the new WixToolsetTest.MSBuild project.
This project relies on all of the projects being published in order to properly test wix.targets.
Diffstat (limited to 'src/test/WixToolsetTest.MSBuild/MsbuildFixture.cs')
| -rw-r--r-- | src/test/WixToolsetTest.MSBuild/MsbuildFixture.cs | 293 |
1 files changed, 293 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.MSBuild/MsbuildFixture.cs b/src/test/WixToolsetTest.MSBuild/MsbuildFixture.cs new file mode 100644 index 00000000..85f111a9 --- /dev/null +++ b/src/test/WixToolsetTest.MSBuild/MsbuildFixture.cs | |||
| @@ -0,0 +1,293 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolsetTest.MSBuild | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.IO; | ||
| 7 | using System.Linq; | ||
| 8 | using WixBuildTools.TestSupport; | ||
| 9 | using Xunit; | ||
| 10 | |||
| 11 | public class MsbuildFixture | ||
| 12 | { | ||
| 13 | private static readonly string WixTargetsPath = Path.Combine(new Uri(typeof(MsbuildFixture).Assembly.CodeBase).AbsolutePath, "..", "..", "publish", "WixToolset.MSBuild", "tools", "wix.targets"); | ||
| 14 | |||
| 15 | [Fact] | ||
| 16 | public void CanBuildSimpleBundle() | ||
| 17 | { | ||
| 18 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\SimpleBundle\SimpleBundle.wixproj"); | ||
| 19 | |||
| 20 | using (var fs = new DisposableFileSystem()) | ||
| 21 | { | ||
| 22 | var baseFolder = fs.GetFolder(); | ||
| 23 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 24 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 25 | |||
| 26 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 27 | { | ||
| 28 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 29 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 30 | $"-p:OutputPath={binFolder}" | ||
| 31 | }); | ||
| 32 | result.AssertSuccess(); | ||
| 33 | |||
| 34 | var platformSwitches = result.Output.Where(line => line.TrimStart().StartsWith("wix.exe build -platform x86")); | ||
| 35 | Assert.Single(platformSwitches); | ||
| 36 | |||
| 37 | var warnings = result.Output.Where(line => line.Contains(": warning")); | ||
| 38 | Assert.Empty(warnings); | ||
| 39 | |||
| 40 | var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) | ||
| 41 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 42 | .OrderBy(s => s) | ||
| 43 | .ToArray(); | ||
| 44 | Assert.Equal(new[] | ||
| 45 | { | ||
| 46 | @"bin\SimpleBundle.exe", | ||
| 47 | @"bin\SimpleBundle.wixpdb", | ||
| 48 | }, paths); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | [Fact] | ||
| 53 | public void CanBuildSimpleMsiPackage() | ||
| 54 | { | ||
| 55 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); | ||
| 56 | |||
| 57 | using (var fs = new DisposableFileSystem()) | ||
| 58 | { | ||
| 59 | var baseFolder = fs.GetFolder(); | ||
| 60 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 61 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 62 | |||
| 63 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 64 | { | ||
| 65 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 66 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 67 | $"-p:OutputPath={binFolder}" | ||
| 68 | }); | ||
| 69 | result.AssertSuccess(); | ||
| 70 | |||
| 71 | var platformSwitches = result.Output.Where(line => line.TrimStart().StartsWith("wix.exe build -platform x86")); | ||
| 72 | Assert.Single(platformSwitches); | ||
| 73 | |||
| 74 | var warnings = result.Output.Where(line => line.Contains(": warning")); | ||
| 75 | Assert.Equal(4, warnings.Count()); | ||
| 76 | |||
| 77 | var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) | ||
| 78 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 79 | .OrderBy(s => s) | ||
| 80 | .ToArray(); | ||
| 81 | Assert.Equal(new[] | ||
| 82 | { | ||
| 83 | @"bin\en-US\cab1.cab", | ||
| 84 | @"bin\en-US\MsiPackage.msi", | ||
| 85 | @"bin\en-US\MsiPackage.wixpdb", | ||
| 86 | }, paths); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | [Fact] | ||
| 91 | public void CanBuildWithDefaultAndExplicitlyFullWixpdbs() | ||
| 92 | { | ||
| 93 | var expectedOutputs = new[] | ||
| 94 | { | ||
| 95 | @"bin\en-US\cab1.cab", | ||
| 96 | @"bin\en-US\MsiPackage.msi", | ||
| 97 | @"bin\en-US\MsiPackage.wixpdb", | ||
| 98 | }; | ||
| 99 | |||
| 100 | this.AssertWixpdb(null, expectedOutputs); | ||
| 101 | this.AssertWixpdb("Full", expectedOutputs); | ||
| 102 | } | ||
| 103 | |||
| 104 | [Fact] | ||
| 105 | public void CanBuildWithNoWixpdb() | ||
| 106 | { | ||
| 107 | this.AssertWixpdb("NONE", new[] | ||
| 108 | { | ||
| 109 | @"bin\en-US\cab1.cab", | ||
| 110 | @"bin\en-US\MsiPackage.msi", | ||
| 111 | }); | ||
| 112 | } | ||
| 113 | |||
| 114 | private void AssertWixpdb(string wixpdbType, string[] expectedOutputFiles) | ||
| 115 | { | ||
| 116 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); | ||
| 117 | |||
| 118 | using (var fs = new DisposableFileSystem()) | ||
| 119 | { | ||
| 120 | var baseFolder = fs.GetFolder(); | ||
| 121 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 122 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 123 | |||
| 124 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 125 | { | ||
| 126 | wixpdbType == null ? String.Empty : $"-p:WixPdbType={wixpdbType}", | ||
| 127 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 128 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 129 | $"-p:OutputPath={binFolder}", | ||
| 130 | }); | ||
| 131 | result.AssertSuccess(); | ||
| 132 | |||
| 133 | var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) | ||
| 134 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 135 | .OrderBy(s => s) | ||
| 136 | .ToArray(); | ||
| 137 | Assert.Equal(expectedOutputFiles, paths); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | [Fact] | ||
| 142 | public void CanBuild64BitMsiPackage() | ||
| 143 | { | ||
| 144 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); | ||
| 145 | |||
| 146 | using (var fs = new DisposableFileSystem()) | ||
| 147 | { | ||
| 148 | var baseFolder = fs.GetFolder(); | ||
| 149 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 150 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 151 | |||
| 152 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 153 | { | ||
| 154 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 155 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 156 | $"-p:OutputPath={binFolder}", | ||
| 157 | $"-p:InstallerPlatform=x64", | ||
| 158 | }); | ||
| 159 | result.AssertSuccess(); | ||
| 160 | |||
| 161 | var platformSwitches = result.Output.Where(line => line.TrimStart().StartsWith("wix.exe build -platform x64")); | ||
| 162 | Assert.Single(platformSwitches); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | [Fact(Skip = "Currently fails")] | ||
| 167 | public void CanBuildSimpleMsiPackageWithIceSuppressions() | ||
| 168 | { | ||
| 169 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); | ||
| 170 | |||
| 171 | using (var fs = new DisposableFileSystem()) | ||
| 172 | { | ||
| 173 | var baseFolder = fs.GetFolder(); | ||
| 174 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 175 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 176 | |||
| 177 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 178 | { | ||
| 179 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 180 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 181 | $"-p:OutputPath={binFolder}", | ||
| 182 | "-p:SuppressIces=\"ICE45;ICE46\"" | ||
| 183 | }); | ||
| 184 | result.AssertSuccess(); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | [Fact] | ||
| 189 | public void CanBuildSimpleMsiPackageWithWarningSuppressions() | ||
| 190 | { | ||
| 191 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); | ||
| 192 | |||
| 193 | using (var fs = new DisposableFileSystem()) | ||
| 194 | { | ||
| 195 | var baseFolder = fs.GetFolder(); | ||
| 196 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 197 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 198 | |||
| 199 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 200 | { | ||
| 201 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 202 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 203 | $"-p:OutputPath={binFolder}", | ||
| 204 | "-p:SuppressSpecificWarnings=\"1118;1102\"" | ||
| 205 | }); | ||
| 206 | result.AssertSuccess(); | ||
| 207 | |||
| 208 | var warnings = result.Output.Where(line => line.Contains(": warning")); | ||
| 209 | Assert.Empty(warnings); | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 | [Fact] | ||
| 214 | public void CanBuildSimpleMsiPackageAsWixipl() | ||
| 215 | { | ||
| 216 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); | ||
| 217 | |||
| 218 | using (var fs = new DisposableFileSystem()) | ||
| 219 | { | ||
| 220 | var baseFolder = fs.GetFolder(); | ||
| 221 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 222 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 223 | |||
| 224 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 225 | { | ||
| 226 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 227 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 228 | $"-p:OutputPath={binFolder}", | ||
| 229 | "-p:OutputType=IntermediatePostLink" | ||
| 230 | }); | ||
| 231 | result.AssertSuccess(); | ||
| 232 | |||
| 233 | var path = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) | ||
| 234 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 235 | .Single(); | ||
| 236 | Assert.Equal(@"bin\MsiPackage.wixipl", path); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | [Fact] | ||
| 241 | public void CanBuildAndCleanSimpleMsiPackage() | ||
| 242 | { | ||
| 243 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); | ||
| 244 | |||
| 245 | using (var fs = new DisposableFileSystem()) | ||
| 246 | { | ||
| 247 | var baseFolder = fs.GetFolder(); | ||
| 248 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 249 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 250 | |||
| 251 | // Build | ||
| 252 | var result = MsbuildRunner.Execute(projectPath, new[] | ||
| 253 | { | ||
| 254 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 255 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 256 | $"-p:OutputPath={binFolder}", | ||
| 257 | "-v:diag" | ||
| 258 | }); | ||
| 259 | result.AssertSuccess(); | ||
| 260 | |||
| 261 | var buildOutput = String.Join("\r\n", result.Output); | ||
| 262 | |||
| 263 | var createdPaths = Directory.EnumerateFiles(baseFolder, @"*.*", SearchOption.AllDirectories) | ||
| 264 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 265 | .OrderBy(s => s) | ||
| 266 | .ToArray(); | ||
| 267 | Assert.NotEmpty(createdPaths); | ||
| 268 | |||
| 269 | // Clean | ||
| 270 | result = MsbuildRunner.Execute(projectPath, new[] | ||
| 271 | { | ||
| 272 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 273 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 274 | $"-p:OutputPath={binFolder}", | ||
| 275 | "-t:Clean", | ||
| 276 | "-v:diag" | ||
| 277 | }); | ||
| 278 | result.AssertSuccess(); | ||
| 279 | |||
| 280 | var cleanOutput = String.Join("\r\n", result.Output); | ||
| 281 | |||
| 282 | // Clean is only expected to delete the files listed in {Project}.FileListAbsolute.txt, | ||
| 283 | // so this is not quite right but close enough. | ||
| 284 | var remainingPaths = Directory.EnumerateFiles(baseFolder, @"*.*", SearchOption.AllDirectories) | ||
| 285 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 286 | .Where(s => s != "obj\\MsiPackage.wixproj.FileListAbsolute.txt") | ||
| 287 | .OrderBy(s => s) | ||
| 288 | .ToArray(); | ||
| 289 | Assert.Empty(remainingPaths); | ||
| 290 | } | ||
| 291 | } | ||
| 292 | } | ||
| 293 | } | ||
