// 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.Heat
{
using System.Collections.Generic;
using System.Threading.Tasks;
using WixToolset.Core;
using WixInternal.Core.MSTestPackage;
using WixToolset.Data;
using WixToolset.Extensibility.Services;
using WixToolset.Tools.Heat;
///
/// Utility class to emulate heat.exe.
///
public static class HeatRunner
{
///
/// Emulates calling heat.exe.
///
///
///
///
///
public static int Execute(string[] args, out List messages, bool warningsAsErrors = true)
{
var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
var task = Execute(args, serviceProvider, out messages, warningsAsErrors: warningsAsErrors);
return task.Result;
}
///
/// Emulates calling wix.exe with standard backends.
/// This overload always treats warnings as errors.
///
///
///
public static WixRunnerResult Execute(params string[] args)
{
return Execute(warningsAsErrors: false, args);
}
///
/// Emulates calling wix.exe with standard backends.
///
///
///
///
public static WixRunnerResult Execute(bool warningsAsErrors, params string[] args)
{
var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
var exitCode = Execute(args, serviceProvider, out var messages, warningsAsErrors: warningsAsErrors);
return new WixRunnerResult { ExitCode = exitCode.Result, Messages = messages.ToArray() };
}
///
/// Emulates calling wix.exe with standard backends.
///
///
///
///
///
///
public static Task Execute(string[] args, IWixToolsetCoreServiceProvider coreProvider, out List messages, bool warningsAsErrors = true)
{
var listener = new TestMessageListener();
messages = listener.Messages;
var messaging = coreProvider.GetService();
messaging.SetListener(listener);
if (warningsAsErrors)
{
messaging.WarningsAsError = true;
}
var program = new Program();
return program.Run(coreProvider, listener, args);
}
}
}