Skip to content

Commit 0a4caf3

Browse files
committed
fix string expectedErrorMessage
1 parent a4eb276 commit 0a4caf3

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

test/coverlet.msbuild.tasks.tests/CoverageResultTaskTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public void Execute_StateUnderTest_WithInstrumentationState_ThresholdType()
111111
Assert.True(coverageResultTask.Log.HasLoggedErrors);
112112

113113
// Verify the error message
114-
string expectedErrorMessage = "The total line coverage is below the specified 50\r\n" +
115-
"The total branch coverage is below the specified 60\r\n" +
114+
string expectedErrorMessage = $"The total line coverage is below the specified 50{Environment.NewLine}" +
115+
$"The total branch coverage is below the specified 60{Environment.NewLine}" +
116116
"The total method coverage is below the specified 70";
117117

118118
Assert.Contains(expectedErrorMessage, _errors[0].Message);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Toni Solarin-Sodara
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Coverlet.Core.Abstractions;
5+
using Coverlet.Core.Helpers;
6+
using Coverlet.Core.Symbols;
7+
using Coverlet.MSbuild.Tasks;
8+
using Microsoft.Build.Framework;
9+
using Microsoft.Build.Utilities;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Moq;
12+
using Xunit;
13+
14+
namespace coverlet.msbuild.tasks.tests
15+
{
16+
public class InstrumentationTaskTests
17+
{
18+
private readonly Mock<IBuildEngine> _buildEngine;
19+
private readonly List<BuildErrorEventArgs> _errors;
20+
21+
public InstrumentationTaskTests()
22+
{
23+
_buildEngine = new Mock<IBuildEngine>();
24+
_errors = new List<BuildErrorEventArgs>();
25+
_buildEngine.Setup(x => x.LogErrorEvent(It.IsAny<BuildErrorEventArgs>())).Callback<BuildErrorEventArgs>(e => _errors.Add(e));
26+
}
27+
28+
[Fact]
29+
public void Execute_StateUnderTest_Failure()
30+
{
31+
// Arrange
32+
var mockFileSystem = new Mock<IFileSystem>();
33+
mockFileSystem.Setup(x => x.Exists(It.IsAny<string>())).Returns(false);
34+
35+
var log = new TaskLoggingHelper(_buildEngine.Object, "InstrumentationTask");
36+
37+
IServiceCollection serviceCollection = new ServiceCollection();
38+
serviceCollection.AddTransient<IFileSystem>(_ => mockFileSystem.Object);
39+
serviceCollection.AddTransient<IProcessExitHandler, ProcessExitHandler>();
40+
serviceCollection.AddTransient<IAssemblyAdapter, AssemblyAdapter>();
41+
serviceCollection.AddTransient<Coverlet.Core.Abstractions.ILogger, MSBuildLogger>(_ => new MSBuildLogger(log));
42+
serviceCollection.AddTransient<IRetryHelper, RetryHelper>();
43+
serviceCollection.AddSingleton<IInstrumentationHelper, InstrumentationHelper>();
44+
serviceCollection.AddSingleton<ISourceRootTranslator, SourceRootTranslator>(serviceProvider => new SourceRootTranslator("testPath", serviceProvider.GetRequiredService<Coverlet.Core.Abstractions.ILogger>(), mockFileSystem.Object, new Mock<IAssemblyAdapter>().Object));
45+
serviceCollection.AddSingleton<ICecilSymbolHelper, CecilSymbolHelper>();
46+
47+
ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
48+
BaseTask.ServiceProvider = serviceProvider;
49+
50+
var instrumentationTask = new InstrumentationTask
51+
{
52+
Path = "testPath",
53+
BuildEngine = _buildEngine.Object
54+
};
55+
56+
// Act
57+
bool success = instrumentationTask.Execute();
58+
59+
// Assert
60+
Assert.False(success);
61+
Assert.NotEmpty(_errors);
62+
Assert.Contains("Module test path 'testPath' not found", _errors[0].Message);
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)