Skip to content

Commit c398782

Browse files
committed
Added test coverage on exceptions. (#18)
Signed-off-by: AraHaan <seandhunt_7@yahoo.com>
1 parent db3b5b6 commit c398782

File tree

3 files changed

+7
-36
lines changed

3 files changed

+7
-36
lines changed

src/GenerationFailedException.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Generator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static Generator Create(string optionsText, string gitInfoText)
7878
};
7979
if (string.IsNullOrEmpty(generator.options!.AssemblyType))
8080
{
81-
throw new GenerationFailedException("AssemblyType should not be null or an empty string.");
81+
throw new InvalidOperationException("AssemblyType should not be null or an empty string.");
8282
}
8383

8484
return generator;
@@ -150,4 +150,4 @@ private SyntaxNodeOrToken[] MakeAttributeArgumentList(string[] args, string type
150150
return lst;
151151
}
152152
}
153-
}
153+
}

tests/GeneratorTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitBuildInfo.SourceGenerator.Tests
22
{
3+
using System;
34
using GitBuildInfo.SourceGenerator;
45
using Xunit;
56

@@ -8,7 +9,7 @@ public class GeneratorTests
89
[Fact]
910
public void TestGeneratingNonGeneric()
1011
{
11-
var result = this.DoTest("TestNamespace.Test", false);
12+
var result = DoTest("TestNamespace.Test", false);
1213
Assert.Equal($@"// <autogenerated/>
1314
using Elskom.Generic.Libs;
1415
using TestNamespace;
@@ -20,7 +21,7 @@ public void TestGeneratingNonGeneric()
2021
[Fact]
2122
public void TestGeneratingGeneric()
2223
{
23-
var result = this.DoTest("TestNamespace.Test", true);
24+
var result = DoTest("TestNamespace.Test", true);
2425
Assert.Equal($@"// <autogenerated/>
2526
using Elskom.Generic.Libs;
2627
using TestNamespace;
@@ -31,13 +32,11 @@ public void TestGeneratingGeneric()
3132

3233
[Fact]
3334
public void TestGeneratingFailure()
34-
{
35-
Assert.Throws<GenerationFailedException>(() => this.DoTest(string.Empty, false));
36-
}
35+
=> Assert.Throws<InvalidOperationException>(() => DoTest(string.Empty, false));
3736

3837
// the values on GitInfo are not valid in terms of results
3938
// that would normally be from git.
40-
private string DoTest(string assemblyType, bool generic)
39+
private static string DoTest(string assemblyType, bool generic)
4140
=> Generator.CreateAndGenerateCode(
4241
$@"{{
4342
""$schema"": ""https://raw.githubusercontent.com/Elskom/GitBuildInfo.SourceGenerator/main/settings.schema.json"",

0 commit comments

Comments
 (0)