Skip to content

Commit 3b398f5

Browse files
authored
Create tests that detect failing builds (Buildalyzer#308)
1 parent b8ce333 commit 3b398f5

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

src/Buildalyzer.Logger/BuildalyzerLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class BuildalyzerLogger : PipeLogger
1313
public override void Initialize(IEventSource eventSource)
1414
{
1515
// Parse the parameters
16-
string[] parameters = Parameters.Split(';').Select(x => x.Trim()).ToArray();
16+
string[] parameters = [..(Parameters?.Split(';').Select(x => x.Trim())).OfType<string>()];
1717
if (parameters.Length != 2)
1818
{
1919
throw new LoggerException("Unexpected number of parameters");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Buildalyzer.Environment;
2+
using Buildalyzer.TestTools;
3+
using FluentAssertions;
4+
5+
namespace Failing_builds;
6+
7+
public class Analyzer_Build
8+
{
9+
[Test]
10+
public void Detects_failing_build_on_single_target()
11+
{
12+
using var ctx = Context.ForProject(@"BuildWithError\BuildWithError.csproj");
13+
var results = ctx.Analyzer.Build(new EnvironmentOptions() { DesignTime = false });
14+
15+
Console.WriteLine(ctx.Log);
16+
17+
results.OverallSuccess.Should().BeFalse();
18+
results.Should().AllSatisfy(r => r.Succeeded.Should().BeFalse());
19+
}
20+
21+
[Test]
22+
public void Detects_failing_build_on_multi_targets()
23+
{
24+
using var ctx = Context.ForProject(@"BuildWithError\BuildWithError.MultiTarget.csproj");
25+
var results = ctx.Analyzer.Build(new EnvironmentOptions() { DesignTime = false });
26+
27+
Console.WriteLine(ctx.Log);
28+
29+
results.OverallSuccess.Should().BeFalse();
30+
results.Should().AllSatisfy(r => r.Succeeded.Should().BeFalse());
31+
}
32+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Buildalyzer.TestTools;
2+
using Buildalyzer.Workspaces;
3+
using FluentAssertions;
4+
using NUnit.Framework;
5+
6+
namespace Failing_builds;
7+
8+
public class Analyzer_Build
9+
{
10+
[Test]
11+
public void Detects_failing_build()
12+
{
13+
using var ctx = Context.ForProject(@"BuildWithError\BuildWithError.csproj");
14+
15+
ctx.Invoking(c => ctx.Analyzer.GetWorkspace()).Should().NotThrow();
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BuildWithError;
2+
3+
public class MissingSemiColon
4+
{
5+
public string Name { get; set }
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace BuildWithError;
2+
3+
public class UnclosedClass

0 commit comments

Comments
 (0)