Skip to content

Commit 43e4d4e

Browse files
authored
Merge pull request #1 from pBouillon/add-flag-to-skip-tests
Allows for a puzzle's tests to be skipped
2 parents b9524b0 + 8f4e42c commit 43e4d4e

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

src/AdventOfCode.Commons/AdventOfCode.Commons.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
<IsPackable>false</IsPackable>
99
</PropertyGroup>
1010

11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
12+
<LangVersion>preview</LangVersion>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
16+
<LangVersion>preview</LangVersion>
17+
</PropertyGroup>
18+
1119
<ItemGroup>
1220
<PackageReference Include="FluentAssertions" Version="6.8.0" />
1321
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
@@ -20,6 +28,7 @@
2028
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2129
<PrivateAssets>all</PrivateAssets>
2230
</PackageReference>
31+
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
2332
</ItemGroup>
2433

2534
</Project>

src/AdventOfCode.Commons/TestEngine.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public record Example
4747
/// </summary>
4848
public record Puzzle
4949
{
50+
/// <summary>
51+
/// If set to <c>true</c>, the tests for this puzzle will be skipped
52+
/// </summary>
53+
/// <remarks>
54+
/// Default is <c>false</c>
55+
/// </remarks>
56+
public bool ShouldSkipTests { get; init; } = false;
57+
5058
/// <summary>
5159
/// The <see cref="Example"/> to use to test <see cref="Solver{TInput, TResult}"/>
5260
/// </summary>
@@ -70,23 +78,33 @@ protected TestEngine()
7078

7179
public abstract Puzzle PartOne { get; }
7280

73-
[Fact(DisplayName = "Part One - Example")]
81+
[SkippableFact(DisplayName = "Part One - Example")]
7482
public void PartOneExampleTest()
7583
{
84+
Skip.If(PartOne.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
85+
86+
// Arrange
7687
var input = PartOne.Example.Input;
7788

89+
// Act
7890
var result = _solver.PartOne(input);
7991

92+
// Assert
8093
result.Should().Be(PartOne.Example.Result);
8194
}
8295

83-
[Fact(DisplayName = "Part One - Solution")]
96+
[SkippableFact(DisplayName = "Part One - Solution")]
8497
public void PartOneSolutionTest()
8598
{
86-
var input = _solver.Input;
99+
Skip.If(PartOne.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
87100

101+
// Arrange
102+
var input = _solver.Input;
103+
104+
// Act
88105
var result = _solver.PartOne(input);
89106

107+
// Assert
90108
result.Should().Be(PartOne.Solution);
91109
}
92110

@@ -96,23 +114,33 @@ public void PartOneSolutionTest()
96114

97115
public abstract Puzzle PartTwo { get; }
98116

99-
[Fact(DisplayName = "Part Two - Example")]
117+
[SkippableFact(DisplayName = "Part Two - Example")]
100118
public void PartTwoExampleTest()
101119
{
120+
Skip.If(PartTwo.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
121+
122+
// Arrange
102123
var input = PartTwo.Example.Input;
103124

125+
// Act
104126
var result = _solver.PartTwo(input);
105127

128+
// Assert
106129
result.Should().Be(PartTwo.Example.Result);
107130
}
108131

109-
[Fact(DisplayName = "Part Two - Solution")]
132+
[SkippableFact(DisplayName = "Part Two - Solution")]
110133
public void PartTwoSolutionTest()
111134
{
135+
Skip.If(PartTwo.ShouldSkipTests, "Puzzle.ShouldSkipTests has been set to true, test skipped");
136+
137+
// Arrange
112138
var input = _solver.Input;
113139

140+
// Act
114141
var result = _solver.PartTwo(input);
115142

143+
// Assert
116144
result.Should().Be(PartTwo.Solution);
117145
}
118146

src/AdventOfCode.Usage/SolverTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class SolverTest : TestEngine<Solver, int[], int>
1717
Input = new[] { 1, 2, 3 },
1818
Result = 3,
1919
},
20-
2120
Solution = 5,
2221
};
2322

@@ -28,7 +27,6 @@ public class SolverTest : TestEngine<Solver, int[], int>
2827
Input = new[] { 1, 2, 3 },
2928
Result = 6,
3029
},
31-
3230
Solution = 15,
3331
};
3432
}

0 commit comments

Comments
 (0)