diff options
| author | Rob Mensching <rob@firegiant.com> | 2018-08-11 01:12:28 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2018-08-11 01:12:28 -0700 |
| commit | f34941825894d44059a560d9f95016ac97803504 (patch) | |
| tree | 2d81fa80cefb53d8a41b335679196d046baff292 /src/test/WixToolsetTest.BuildTasks | |
| parent | c7d69b36789b6403f5b02a975afad80f6b23b48b (diff) | |
| download | wix-f34941825894d44059a560d9f95016ac97803504.tar.gz wix-f34941825894d44059a560d9f95016ac97803504.tar.bz2 wix-f34941825894d44059a560d9f95016ac97803504.zip | |
Fix Build and Clean targets
Diffstat (limited to 'src/test/WixToolsetTest.BuildTasks')
5 files changed, 149 insertions, 82 deletions
diff --git a/src/test/WixToolsetTest.BuildTasks/FakeBuildEngine.cs b/src/test/WixToolsetTest.BuildTasks/FakeBuildEngine.cs deleted file mode 100644 index 8fd69414..00000000 --- a/src/test/WixToolsetTest.BuildTasks/FakeBuildEngine.cs +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 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.BuildTasks | ||
| 4 | { | ||
| 5 | using System.Collections; | ||
| 6 | using System.Text; | ||
| 7 | using Microsoft.Build.Framework; | ||
| 8 | |||
| 9 | internal class FakeBuildEngine : IBuildEngine | ||
| 10 | { | ||
| 11 | private StringBuilder output = new StringBuilder(); | ||
| 12 | |||
| 13 | public int ColumnNumberOfTaskNode => 0; | ||
| 14 | |||
| 15 | public bool ContinueOnError => false; | ||
| 16 | |||
| 17 | public int LineNumberOfTaskNode => 0; | ||
| 18 | |||
| 19 | public string ProjectFileOfTaskNode => "fake_wix.targets"; | ||
| 20 | |||
| 21 | public string Output => this.output.ToString(); | ||
| 22 | |||
| 23 | public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs) => throw new System.NotImplementedException(); | ||
| 24 | |||
| 25 | public void LogCustomEvent(CustomBuildEventArgs e) => this.output.AppendLine(e.Message); | ||
| 26 | |||
| 27 | public void LogErrorEvent(BuildErrorEventArgs e) => this.output.AppendLine(e.Message); | ||
| 28 | |||
| 29 | public void LogMessageEvent(BuildMessageEventArgs e) => this.output.AppendLine(e.Message); | ||
| 30 | |||
| 31 | public void LogWarningEvent(BuildWarningEventArgs e) => this.output.AppendLine(e.Message); | ||
| 32 | } | ||
| 33 | } | ||
diff --git a/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs b/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs index a27928d5..95b727ad 100644 --- a/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs +++ b/src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs | |||
| @@ -2,62 +2,103 @@ | |||
| 2 | 2 | ||
| 3 | namespace WixToolsetTest.BuildTasks | 3 | namespace WixToolsetTest.BuildTasks |
| 4 | { | 4 | { |
| 5 | using System; | ||
| 5 | using System.IO; | 6 | using System.IO; |
| 6 | using System.Linq; | 7 | using System.Linq; |
| 7 | using Microsoft.Build.Utilities; | ||
| 8 | using WixBuildTools.TestSupport; | 8 | using WixBuildTools.TestSupport; |
| 9 | using WixToolset.BuildTasks; | 9 | using WixToolset.BuildTasks; |
| 10 | using WixToolset.Data; | ||
| 11 | using WixToolset.Data.Tuples; | ||
| 12 | using Xunit; | 10 | using Xunit; |
| 13 | 11 | ||
| 14 | public partial class MsbuildFixture | 12 | public class MsbuildFixture |
| 15 | { | 13 | { |
| 14 | private static readonly string WixTargetsPath = Path.Combine(Path.GetDirectoryName(new Uri(typeof(DoIt).Assembly.CodeBase).AbsolutePath), "wix.targets"); | ||
| 15 | |||
| 16 | public MsbuildFixture() | ||
| 17 | { | ||
| 18 | this.MsbuildRunner = new MsbuildRunner(); | ||
| 19 | } | ||
| 20 | |||
| 21 | private MsbuildRunner MsbuildRunner { get; } | ||
| 22 | |||
| 16 | [Fact] | 23 | [Fact] |
| 17 | public void CanBuildSimpleMsiPackage() | 24 | public void CanBuildSimpleMsiPackage() |
| 18 | { | 25 | { |
| 19 | var folder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage"); | 26 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); |
| 20 | 27 | ||
| 21 | using (var fs = new DisposableFileSystem()) | 28 | using (var fs = new DisposableFileSystem()) |
| 22 | { | 29 | { |
| 23 | var baseFolder = fs.GetFolder(); | 30 | var baseFolder = fs.GetFolder(); |
| 24 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | 31 | var binFolder = Path.Combine(baseFolder, @"bin\"); |
| 32 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); | ||
| 25 | 33 | ||
| 26 | var engine = new FakeBuildEngine(); | 34 | var result = this.MsbuildRunner.Execute(projectPath, new[] |
| 35 | { | ||
| 36 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 37 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 38 | $"-p:OutputPath={binFolder}" | ||
| 39 | }); | ||
| 40 | result.AssertSuccess(); | ||
| 27 | 41 | ||
| 28 | var task = new DoIt | 42 | var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) |
| 43 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 44 | .OrderBy(s => s) | ||
| 45 | .ToArray(); | ||
| 46 | Assert.Equal(new[] | ||
| 29 | { | 47 | { |
| 30 | BuildEngine = engine, | 48 | @"bin\en-US\cab1.cab", |
| 31 | SourceFiles = new[] | 49 | @"bin\en-US\MsiPackage.msi", |
| 32 | { | 50 | @"bin\en-US\MsiPackage.wixpdb", |
| 33 | new TaskItem(Path.Combine(folder, "Package.wxs")), | 51 | }, paths); |
| 34 | new TaskItem(Path.Combine(folder, "PackageComponents.wxs")), | 52 | } |
| 35 | }, | 53 | } |
| 36 | LocalizationFiles = new[] | 54 | |
| 37 | { | 55 | [Fact] |
| 38 | new TaskItem(Path.Combine(folder, "Package.en-us.wxl")), | 56 | public void CanBuildAndCleanSimpleMsiPackage() |
| 39 | }, | 57 | { |
| 40 | BindInputPaths = new[] | 58 | var projectPath = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj"); |
| 41 | { | 59 | |
| 42 | new TaskItem(Path.Combine(folder, "data")), | 60 | using (var fs = new DisposableFileSystem()) |
| 43 | }, | 61 | { |
| 44 | IntermediateDirectory = new TaskItem(intermediateFolder), | 62 | var baseFolder = fs.GetFolder(); |
| 45 | OutputFile = new TaskItem(Path.Combine(baseFolder, @"bin\test.msi")), | 63 | var binFolder = Path.Combine(baseFolder, @"bin\"); |
| 46 | }; | 64 | var intermediateFolder = Path.Combine(baseFolder, @"obj\"); |
| 47 | 65 | ||
| 48 | var result = task.Execute(); | 66 | // Build |
| 49 | Assert.True(result, $"MSBuild task failed unexpectedly. Output:\r\n{engine.Output}"); | 67 | var result = this.MsbuildRunner.Execute(projectPath, new[] |
| 50 | 68 | { | |
| 51 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.msi"))); | 69 | $"-p:WixTargetsPath={WixTargetsPath}", |
| 52 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.wixpdb"))); | 70 | $"-p:IntermediateOutputPath={intermediateFolder}", |
| 53 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\cab1.cab"))); | 71 | $"-p:OutputPath={binFolder}", |
| 54 | 72 | "-v:diag" | |
| 55 | var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wir")); | 73 | }); |
| 56 | var section = intermediate.Sections.Single(); | 74 | result.AssertSuccess(); |
| 57 | 75 | ||
| 58 | var wixFile = section.Tuples.OfType<WixFileTuple>().Single(); | 76 | var buildOutput = String.Join("\r\n", result.Output); |
| 59 | Assert.Equal(Path.Combine(folder, @"data\test.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path); | 77 | |
| 60 | Assert.Equal(@"test.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path); | 78 | var createdPaths = Directory.EnumerateFiles(baseFolder, @"*.*", SearchOption.AllDirectories) |
| 79 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 80 | .OrderBy(s => s) | ||
| 81 | .ToArray(); | ||
| 82 | Assert.NotEmpty(createdPaths); | ||
| 83 | |||
| 84 | // Clean | ||
| 85 | result = this.MsbuildRunner.Execute(projectPath, new[] | ||
| 86 | { | ||
| 87 | $"-p:WixTargetsPath={WixTargetsPath}", | ||
| 88 | $"-p:IntermediateOutputPath={intermediateFolder}", | ||
| 89 | $"-p:OutputPath={binFolder}", | ||
| 90 | "-t:Clean", | ||
| 91 | "-v:diag" | ||
| 92 | }); | ||
| 93 | result.AssertSuccess(); | ||
| 94 | |||
| 95 | var cleanOutput = String.Join("\r\n", result.Output); | ||
| 96 | |||
| 97 | var remainingPaths = Directory.EnumerateFiles(baseFolder, @"*.*", SearchOption.AllDirectories) | ||
| 98 | .Select(s => s.Substring(baseFolder.Length + 1)) | ||
| 99 | .OrderBy(s => s) | ||
| 100 | .ToArray(); | ||
| 101 | Assert.Empty(remainingPaths); | ||
| 61 | } | 102 | } |
| 62 | } | 103 | } |
| 63 | } | 104 | } |
diff --git a/src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/MsiPackage.wixproj b/src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/MsiPackage.wixproj index 31c3ec9c..d5cac8d8 100644 --- a/src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/MsiPackage.wixproj +++ b/src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/MsiPackage.wixproj | |||
| @@ -1,18 +1,12 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | 2 | <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 3 | <PropertyGroup> | 3 | <PropertyGroup> |
| 4 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | 4 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
| 5 | <Platform Condition=" '$(Platform)' == '' ">x86</Platform> | 5 | <Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
| 6 | <ProductVersion>0.9</ProductVersion> | ||
| 7 | <ProjectGuid>7fb77005-c6e0-454f-8c2d-0a4a79c918ba</ProjectGuid> | ||
| 8 | <OutputName>MsiPackage</OutputName> | ||
| 9 | <OutputType>Package</OutputType> | ||
| 10 | <Name>MsiPackage</Name> | ||
| 11 | <RootNamespace>MsiPackage</RootNamespace> | ||
| 12 | </PropertyGroup> | 6 | </PropertyGroup> |
| 13 | 7 | ||
| 14 | <PropertyGroup> | 8 | <PropertyGroup> |
| 15 | <WixTargetsPath>..\..\..\..\..\..\build\Release\publish\wix.targets</WixTargetsPath> | 9 | <ProjectGuid>7fb77005-c6e0-454f-8c2d-0a4a79c918ba</ProjectGuid> |
| 16 | </PropertyGroup> | 10 | </PropertyGroup> |
| 17 | 11 | ||
| 18 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | 12 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> |
| @@ -48,8 +42,8 @@ | |||
| 48 | </ItemGroup> | 42 | </ItemGroup> |
| 49 | 43 | ||
| 50 | <Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " /> | 44 | <Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " /> |
| 51 | <Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\wix.targets') " /> | 45 | <Import Project="$(MSBuildExtensionsPath32)\WixToolset\v4.x\wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\WixToolset\v4.x\wix.targets') " /> |
| 52 | <Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' "> | 46 | <Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' "> |
| 53 | <Error Text="WiX Toolset build tools (v3.11 or later) must be installed to build this project. To download the WiX Toolset, go to http://wixtoolset.org/releases/." /> | 47 | <Error Text="WiX Toolset build tools (v4.0 or later) must be installed to build this project. To download the WiX Toolset, go to http://wixtoolset.org/releases/." /> |
| 54 | </Target> | 48 | </Target> |
| 55 | </Project> \ No newline at end of file | 49 | </Project> \ No newline at end of file |
diff --git a/src/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs b/src/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs new file mode 100644 index 00000000..c4a69cdd --- /dev/null +++ b/src/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs | |||
| @@ -0,0 +1,64 @@ | |||
| 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.BuildTasks | ||
| 4 | { | ||
| 5 | using System.IO; | ||
| 6 | using System.Linq; | ||
| 7 | using Microsoft.Build.Utilities; | ||
| 8 | using WixBuildTools.TestSupport; | ||
| 9 | using WixToolset.BuildTasks; | ||
| 10 | using WixToolset.Data; | ||
| 11 | using WixToolset.Data.Tuples; | ||
| 12 | using Xunit; | ||
| 13 | |||
| 14 | public class WixBuildTaskFixture | ||
| 15 | { | ||
| 16 | [Fact] | ||
| 17 | public void CanBuildSimpleMsiPackage() | ||
| 18 | { | ||
| 19 | var folder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage"); | ||
| 20 | |||
| 21 | using (var fs = new DisposableFileSystem()) | ||
| 22 | { | ||
| 23 | var baseFolder = fs.GetFolder(); | ||
| 24 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | ||
| 25 | |||
| 26 | var engine = new FakeBuildEngine(); | ||
| 27 | |||
| 28 | var task = new DoIt | ||
| 29 | { | ||
| 30 | BuildEngine = engine, | ||
| 31 | SourceFiles = new[] | ||
| 32 | { | ||
| 33 | new TaskItem(Path.Combine(folder, "Package.wxs")), | ||
| 34 | new TaskItem(Path.Combine(folder, "PackageComponents.wxs")), | ||
| 35 | }, | ||
| 36 | LocalizationFiles = new[] | ||
| 37 | { | ||
| 38 | new TaskItem(Path.Combine(folder, "Package.en-us.wxl")), | ||
| 39 | }, | ||
| 40 | BindInputPaths = new[] | ||
| 41 | { | ||
| 42 | new TaskItem(Path.Combine(folder, "data")), | ||
| 43 | }, | ||
| 44 | IntermediateDirectory = new TaskItem(intermediateFolder), | ||
| 45 | OutputFile = new TaskItem(Path.Combine(baseFolder, @"bin\test.msi")), | ||
| 46 | }; | ||
| 47 | |||
| 48 | var result = task.Execute(); | ||
| 49 | Assert.True(result, $"MSBuild task failed unexpectedly. Output:\r\n{engine.Output}"); | ||
| 50 | |||
| 51 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.msi"))); | ||
| 52 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.wixpdb"))); | ||
| 53 | Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\cab1.cab"))); | ||
| 54 | |||
| 55 | var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"test.wir")); | ||
| 56 | var section = intermediate.Sections.Single(); | ||
| 57 | |||
| 58 | var wixFile = section.Tuples.OfType<WixFileTuple>().Single(); | ||
| 59 | Assert.Equal(Path.Combine(folder, @"data\test.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path); | ||
| 60 | Assert.Equal(@"test.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
diff --git a/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj b/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj index 99da83cd..edab8a67 100644 --- a/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj +++ b/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | </PropertyGroup> | 9 | </PropertyGroup> |
| 10 | 10 | ||
| 11 | <ItemGroup> | 11 | <ItemGroup> |
| 12 | <Content Include="TestData\SimpleMsiPackage\MsiPackage\MsiPackage.wixproj" CopyToOutputDirectory="PreserveNewest" /> | ||
| 12 | <Content Include="TestData\SimpleMsiPackage\MsiPackage\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> | 13 | <Content Include="TestData\SimpleMsiPackage\MsiPackage\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" /> |
| 13 | <Content Include="TestData\SimpleMsiPackage\MsiPackage\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> | 14 | <Content Include="TestData\SimpleMsiPackage\MsiPackage\Package.wxs" CopyToOutputDirectory="PreserveNewest" /> |
| 14 | <Content Include="TestData\SimpleMsiPackage\MsiPackage\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> | 15 | <Content Include="TestData\SimpleMsiPackage\MsiPackage\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" /> |
