@joebigelow / wix-1 / commits / 6dd04531

Introduce integration test

Rob Mensching committed Oct 16, 2017 at 23:48 UTC 6dd045318f7ee405e92e76d311ad1424c20157c1
11 files changed +287 -3
src/WixToolset.Core/CommandLine/BuildCommand.cs
+12 -1
@@ -70,6 +70,11 @@ namespace WixToolset.Core
70 {
71 var intermediates = this.CompilePhase();
72
73 + if (!intermediates.Any())
74 + {
75 + return 1;
76 + }
77 +
78 var tableDefinitions = new TableDefinitionCollection(WindowsInstallerStandard.GetTableDefinitions());
79
80 if (this.OutputType == OutputType.Library)
@@ -162,6 +167,12 @@ namespace WixToolset.Core
167
168 var resolver = CreateWixResolverWithVariables(localizer, output);
169
170 + var intermediateFolder = this.IntermediateFolder;
171 + if (String.IsNullOrEmpty(intermediateFolder))
172 + {
173 + intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
174 + }
175 +
176 var context = new BindContext();
177 context.Messaging = Messaging.Instance;
178 context.ExtensionManager = this.ExtensionManager;
@@ -171,7 +182,7 @@ namespace WixToolset.Core
182 context.Codepage = localizer.Codepage;
183 //context.DefaultCompressionLevel = this.DefaultCompressionLevel;
184 //context.Ices = this.Ices;
174 - context.IntermediateFolder = this.IntermediateFolder;
185 + context.IntermediateFolder = intermediateFolder;
186 context.IntermediateRepresentation = output;
187 context.OutputPath = this.OutputPath;
188 context.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb");
src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs new
+32
@@ -0,0 +1,32 @@
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.CoreIntegrationFixture
4 +{
5 + using System.IO;
6 + using WixToolset.Core;
7 + using WixToolsetTest.CoreIntegrationFixture.Utility;
8 + using Xunit;
9 +
10 + public class ProgramFixture
11 + {
12 + [Fact]
13 + public void CanBuildSingleFile()
14 + {
15 + var folder = TestData.Get(@"TestData\SingleFile");
16 +
17 + using (var fs = new DisposableFileSystem())
18 + using (var pushd = new Pushd(folder))
19 + {
20 + var intermediateFolder = fs.GetFolder();
21 +
22 + var program = new Program();
23 + var result = program.Run(new[] { "build", "Package.wxs", "PackageComponents.wxs", "-loc", "Package.en-us.wxl", "-bindpath", "data", "-intermediateFolder", intermediateFolder, "-o", $@"{intermediateFolder}\bin\test.msi" });
24 +
25 + Assert.Equal(0, result);
26 + Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.msi")));
27 + Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.wixpdb")));
28 + Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\MsiPackage\test.txt")));
29 + }
30 + }
31 + }
32 +}
src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.en-us.wxl new
+11
@@ -0,0 +1,11 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +
3 +<!--
4 +This file contains the declaration of all the localizable strings.
5 +-->
6 +<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US">
7 +
8 + <String Id="DowngradeError">A newer version of [ProductName] is already installed.</String>
9 + <String Id="FeatureTitle">MsiPackage</String>
10 +
11 +</WixLocalization>
src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.wxs new
+21
@@ -0,0 +1,21 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 + <Product Id="*" Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
4 + <Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" />
5 +
6 + <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
7 + <MediaTemplate />
8 +
9 + <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)">
10 + <ComponentGroupRef Id="ProductComponents" />
11 + </Feature>
12 + </Product>
13 +
14 + <Fragment>
15 + <Directory Id="TARGETDIR" Name="SourceDir">
16 + <Directory Id="ProgramFilesFolder">
17 + <Directory Id="INSTALLFOLDER" Name="MsiPackage" />
18 + </Directory>
19 + </Directory>
20 + </Fragment>
21 +</Wix>
src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/PackageComponents.wxs new
+10
@@ -0,0 +1,10 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 + <Fragment>
4 + <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
5 + <Component>
6 + <File Source="test.txt" />
7 + </Component>
8 + </ComponentGroup>
9 + </Fragment>
10 +</Wix>
src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/data/test.txt new
+1
@@ -0,0 +1 @@
1 +This is test.txt.
\ No newline at end of file
src/test/WixToolsetTest.CoreIntegrationFixture/Utility/DisposableFileSystem.cs new
+86
@@ -0,0 +1,86 @@
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.CoreIntegrationFixture.Utility
4 +{
5 + using System;
6 + using System.Collections.Generic;
7 + using System.IO;
8 +
9 + public class DisposableFileSystem : IDisposable
10 + {
11 + protected bool Disposed { get; private set; }
12 +
13 + private List<string> CleanupPaths { get; } = new List<string>();
14 +
15 + protected string GetFile(bool create = false)
16 + {
17 + var path = Path.GetTempFileName();
18 +
19 + if (!create)
20 + {
21 + File.Delete(path);
22 + }
23 +
24 + this.CleanupPaths.Add(path);
25 +
26 + return path;
27 + }
28 +
29 + public string GetFolder(bool create = false)
30 + {
31 + var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
32 +
33 + if (create)
34 + {
35 + Directory.CreateDirectory(path);
36 + }
37 +
38 + this.CleanupPaths.Add(path);
39 +
40 + return path;
41 + }
42 +
43 +
44 + #region // IDisposable
45 +
46 + public void Dispose()
47 + {
48 + this.Dispose(true);
49 + GC.SuppressFinalize(this);
50 + }
51 +
52 + protected virtual void Dispose(bool disposing)
53 + {
54 + if (this.Disposed)
55 + {
56 + return;
57 + }
58 +
59 + if (disposing)
60 + {
61 + foreach (var path in this.CleanupPaths)
62 + {
63 + try
64 + {
65 + if (File.Exists(path))
66 + {
67 + File.Delete(path);
68 + }
69 + else if (Directory.Exists(path))
70 + {
71 + Directory.Delete(path, true);
72 + }
73 + }
74 + catch
75 + {
76 + // Best effort delete, so ignore any failures.
77 + }
78 + }
79 + }
80 +
81 + this.Disposed = true;
82 + }
83 +
84 + #endregion
85 + }
86 +}
src/test/WixToolsetTest.CoreIntegrationFixture/Utility/Pushd.cs new
+46
@@ -0,0 +1,46 @@
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.CoreIntegrationFixture.Utility
4 +{
5 + using System;
6 + using System.IO;
7 +
8 + public class Pushd : IDisposable
9 + {
10 + protected bool Disposed { get; private set; }
11 +
12 + public Pushd(string path)
13 + {
14 + this.PreviousDirectory = Directory.GetCurrentDirectory();
15 +
16 + Directory.SetCurrentDirectory(path);
17 + }
18 +
19 + public string PreviousDirectory { get; }
20 +
21 + #region // IDisposable
22 +
23 + public void Dispose()
24 + {
25 + this.Dispose(true);
26 + GC.SuppressFinalize(this);
27 + }
28 +
29 + protected virtual void Dispose(bool disposing)
30 + {
31 + if (this.Disposed)
32 + {
33 + return;
34 + }
35 +
36 + if (disposing)
37 + {
38 + Directory.SetCurrentDirectory(this.PreviousDirectory);
39 + }
40 +
41 + this.Disposed = true;
42 + }
43 +
44 + #endregion
45 + }
46 +}
src/test/WixToolsetTest.CoreIntegrationFixture/Utility/TestData.cs new
+17
@@ -0,0 +1,17 @@
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.CoreIntegrationFixture.Utility
4 +{
5 + using System;
6 + using System.IO;
7 +
8 + public class TestData
9 + {
10 + public static string LocalPath => Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);
11 +
12 + public static string Get(params string[] paths)
13 + {
14 + return Path.Combine(LocalPath, Path.Combine(paths));
15 + }
16 + }
17 +}
src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj new
+45
@@ -0,0 +1,45 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<!-- 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. -->
3 +
4 +<Project Sdk="Microsoft.NET.Sdk">
5 + <PropertyGroup>
6 + <TargetFramework>netcoreapp2.0</TargetFramework>
7 + <IsPackable>false</IsPackable>
8 + </PropertyGroup>
9 +
10 + <PropertyGroup>
11 + <NoWarn>NU1701</NoWarn>
12 + </PropertyGroup>
13 +
14 + <ItemGroup>
15 + <None Remove="TestData\SingleFile\data\test.txt" />
16 + <None Remove="TestData\SingleFile\Package.en-us.wxl" />
17 + <None Remove="TestData\SingleFile\Package.wxs" />
18 + <None Remove="TestData\SingleFile\PackageComponents.wxs" />
19 + </ItemGroup>
20 +
21 + <ItemGroup>
22 + <Content Include="TestData\SingleFile\data\test.txt">
23 + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24 + </Content>
25 + <Content Include="TestData\SingleFile\Package.en-us.wxl">
26 + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27 + </Content>
28 + <Content Include="TestData\SingleFile\Package.wxs">
29 + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30 + </Content>
31 + <Content Include="TestData\SingleFile\PackageComponents.wxs">
32 + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33 + </Content>
34 + </ItemGroup>
35 +
36 + <ItemGroup>
37 + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
38 + <PackageReference Include="xunit" Version="2.2.0" />
39 + <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
40 + </ItemGroup>
41 +
42 + <ItemGroup>
43 + <ProjectReference Include="..\..\wix\wix.csproj" />
44 + </ItemGroup>
45 +</Project>
src/wix/Program.cs
+6 -2
@@ -19,11 +19,15 @@ namespace WixToolset.Core
19 public static int Main(string[] args)
20 {
21 Messaging.Instance.InitializeAppName("WIX", "wix.exe");
22 -
22 Messaging.Instance.Display += DisplayMessage;
23
25 - var command = CommandLine.ParseStandardCommandLine(args);
24 + var program = new Program();
25 + return program.Run(args);
26 + }
27
28 + public int Run(string[] args)
29 + {
30 + var command = CommandLine.ParseStandardCommandLine(args);
31 return command?.Execute() ?? 1;
32 }
33