aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.TestPackage/WixRunnerResult.cs
blob: f4870ae3c0ed4182e8bbc33106c58e8c1300f5a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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 WixToolset.Core.TestPackage
{
    using System;
    using System.Collections.Generic;
    using WixToolset.Data;
    using Xunit;

    public class WixRunnerResult
    {
        public int ExitCode { get; set; }

        public Message[] Messages { get; set; }

        public WixRunnerResult AssertSuccess()
        {
            Assert.True(0 == this.ExitCode, $"\r\n\r\nWixRunner failed with exit code: {this.ExitCode}\r\n   Output: {String.Join("\r\n           ", FormatMessages(this.Messages))}\r\n");
            return this;
        }

        private static IEnumerable<string> FormatMessages(IEnumerable<Message> messages)
        {
            foreach (var message in messages)
            {
                var filename = message.SourceLineNumbers?.FileName ?? "TEST";
                var line = message.SourceLineNumbers?.LineNumber ?? -1;
                var type = message.Level.ToString().ToLowerInvariant();
                var output = message.Level >= MessageLevel.Warning ? Console.Out : Console.Error;

                if (line > 0)
                {
                    filename = String.Concat(filename, "(", line, ")");
                }

                yield return String.Format("{0} : {1} {2}{3:0000}: {4}", filename, type, "TEST", message.Id, message.ToString());
            }
        }
    }
}