From 6dd045318f7ee405e92e76d311ad1424c20157c1 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 16 Oct 2017 23:48:48 -0700 Subject: Introduce integration test --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 13 +++- .../ProgramFixture.cs | 32 ++++++++ .../TestData/SingleFile/Package.en-us.wxl | 11 +++ .../TestData/SingleFile/Package.wxs | 21 ++++++ .../TestData/SingleFile/PackageComponents.wxs | 10 +++ .../TestData/SingleFile/data/test.txt | 1 + .../Utility/DisposableFileSystem.cs | 86 ++++++++++++++++++++++ .../Utility/Pushd.cs | 46 ++++++++++++ .../Utility/TestData.cs | 17 +++++ .../WixToolsetTest.CoreIntegrationFixture.csproj | 45 +++++++++++ src/wix/Program.cs | 8 +- 11 files changed, 287 insertions(+), 3 deletions(-) create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.en-us.wxl create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/PackageComponents.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/data/test.txt create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/Utility/DisposableFileSystem.cs create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/Utility/Pushd.cs create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/Utility/TestData.cs create mode 100644 src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 32da5bcf..b3909451 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -70,6 +70,11 @@ namespace WixToolset.Core { var intermediates = this.CompilePhase(); + if (!intermediates.Any()) + { + return 1; + } + var tableDefinitions = new TableDefinitionCollection(WindowsInstallerStandard.GetTableDefinitions()); if (this.OutputType == OutputType.Library) @@ -162,6 +167,12 @@ namespace WixToolset.Core var resolver = CreateWixResolverWithVariables(localizer, output); + var intermediateFolder = this.IntermediateFolder; + if (String.IsNullOrEmpty(intermediateFolder)) + { + intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + } + var context = new BindContext(); context.Messaging = Messaging.Instance; context.ExtensionManager = this.ExtensionManager; @@ -171,7 +182,7 @@ namespace WixToolset.Core context.Codepage = localizer.Codepage; //context.DefaultCompressionLevel = this.DefaultCompressionLevel; //context.Ices = this.Ices; - context.IntermediateFolder = this.IntermediateFolder; + context.IntermediateFolder = intermediateFolder; context.IntermediateRepresentation = output; context.OutputPath = this.OutputPath; context.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb"); diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs b/src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs new file mode 100644 index 00000000..bc2786e9 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/ProgramFixture.cs @@ -0,0 +1,32 @@ +// 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. + +namespace WixToolsetTest.CoreIntegrationFixture +{ + using System.IO; + using WixToolset.Core; + using WixToolsetTest.CoreIntegrationFixture.Utility; + using Xunit; + + public class ProgramFixture + { + [Fact] + public void CanBuildSingleFile() + { + var folder = TestData.Get(@"TestData\SingleFile"); + + using (var fs = new DisposableFileSystem()) + using (var pushd = new Pushd(folder)) + { + var intermediateFolder = fs.GetFolder(); + + var program = new Program(); + var result = program.Run(new[] { "build", "Package.wxs", "PackageComponents.wxs", "-loc", "Package.en-us.wxl", "-bindpath", "data", "-intermediateFolder", intermediateFolder, "-o", $@"{intermediateFolder}\bin\test.msi" }); + + Assert.Equal(0, result); + Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.msi"))); + Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.wixpdb"))); + Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\MsiPackage\test.txt"))); + } + } + } +} diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.en-us.wxl b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.en-us.wxl new file mode 100644 index 00000000..38c12ac1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.en-us.wxl @@ -0,0 +1,11 @@ + + + + + + A newer version of [ProductName] is already installed. + MsiPackage + + diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.wxs b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.wxs new file mode 100644 index 00000000..cdc323ec --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/Package.wxs @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/PackageComponents.wxs b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/PackageComponents.wxs new file mode 100644 index 00000000..e26c4509 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/PackageComponents.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/data/test.txt b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/data/test.txt new file mode 100644 index 00000000..cd0db0e1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/TestData/SingleFile/data/test.txt @@ -0,0 +1 @@ +This is test.txt. \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/DisposableFileSystem.cs b/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/DisposableFileSystem.cs new file mode 100644 index 00000000..01c0b9fe --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/DisposableFileSystem.cs @@ -0,0 +1,86 @@ +// 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. + +namespace WixToolsetTest.CoreIntegrationFixture.Utility +{ + using System; + using System.Collections.Generic; + using System.IO; + + public class DisposableFileSystem : IDisposable + { + protected bool Disposed { get; private set; } + + private List CleanupPaths { get; } = new List(); + + protected string GetFile(bool create = false) + { + var path = Path.GetTempFileName(); + + if (!create) + { + File.Delete(path); + } + + this.CleanupPaths.Add(path); + + return path; + } + + public string GetFolder(bool create = false) + { + var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + + if (create) + { + Directory.CreateDirectory(path); + } + + this.CleanupPaths.Add(path); + + return path; + } + + + #region // IDisposable + + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (this.Disposed) + { + return; + } + + if (disposing) + { + foreach (var path in this.CleanupPaths) + { + try + { + if (File.Exists(path)) + { + File.Delete(path); + } + else if (Directory.Exists(path)) + { + Directory.Delete(path, true); + } + } + catch + { + // Best effort delete, so ignore any failures. + } + } + } + + this.Disposed = true; + } + + #endregion + } +} diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/Pushd.cs b/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/Pushd.cs new file mode 100644 index 00000000..8917e02c --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/Pushd.cs @@ -0,0 +1,46 @@ +// 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. + +namespace WixToolsetTest.CoreIntegrationFixture.Utility +{ + using System; + using System.IO; + + public class Pushd : IDisposable + { + protected bool Disposed { get; private set; } + + public Pushd(string path) + { + this.PreviousDirectory = Directory.GetCurrentDirectory(); + + Directory.SetCurrentDirectory(path); + } + + public string PreviousDirectory { get; } + + #region // IDisposable + + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (this.Disposed) + { + return; + } + + if (disposing) + { + Directory.SetCurrentDirectory(this.PreviousDirectory); + } + + this.Disposed = true; + } + + #endregion + } +} diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/TestData.cs b/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/TestData.cs new file mode 100644 index 00000000..90d56799 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/Utility/TestData.cs @@ -0,0 +1,17 @@ +// 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. + +namespace WixToolsetTest.CoreIntegrationFixture.Utility +{ + using System; + using System.IO; + + public class TestData + { + public static string LocalPath => Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); + + public static string Get(params string[] paths) + { + return Path.Combine(LocalPath, Path.Combine(paths)); + } + } +} diff --git a/src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj b/src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj new file mode 100644 index 00000000..86482a19 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegrationFixture/WixToolsetTest.CoreIntegrationFixture.csproj @@ -0,0 +1,45 @@ + + + + + + netcoreapp2.0 + false + + + + NU1701 + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + + + + + + + diff --git a/src/wix/Program.cs b/src/wix/Program.cs index c60831d0..03b11c78 100644 --- a/src/wix/Program.cs +++ b/src/wix/Program.cs @@ -19,11 +19,15 @@ namespace WixToolset.Core public static int Main(string[] args) { Messaging.Instance.InitializeAppName("WIX", "wix.exe"); - Messaging.Instance.Display += DisplayMessage; - var command = CommandLine.ParseStandardCommandLine(args); + var program = new Program(); + return program.Run(args); + } + public int Run(string[] args) + { + var command = CommandLine.ParseStandardCommandLine(args); return command?.Execute() ?? 1; } -- cgit v1.2.3-55-g6feb