Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduction of Qowaiv.Diagnostics.Contracts package (#375)
- Loading branch information
Showing
38 changed files
with
349 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
using Qowaiv; | ||
using Qowaiv.Identifiers; | ||
using Qowaiv.TestTools; | ||
|
||
namespace Benchmarks; | ||
|
||
|
22 changes: 22 additions & 0 deletions
22
specs/Qowaiv.Specs/Diagnostics/Contracts/Conditional_specs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Diagnostics.Contracts.Conditional_specs; | ||
|
||
public class Is_decorated_with | ||
{ | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.CollectionMutationAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.FluentSyntaxAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.ImpureAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.InheritableAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.MutableAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyTypeAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyClassAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyEnumAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyInterfaceAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyStructAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyTestClassAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyTestEnumAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyTestInterfaceAttribute))] | ||
[TestCase(typeof(Qowaiv.Diagnostics.Contracts.EmptyTestStructAttribute))] | ||
public void condtional_CONTRACTS_FULL(Type attribute) | ||
=> attribute.Should().BeDecoratedWith<ConditionalAttribute>() | ||
.Which.ConditionString.Should().Be("CONTRACTS_FULL"); | ||
} |
32 changes: 32 additions & 0 deletions
32
specs/Qowaiv.Specs/Diagnostics/Contracts/Empty_type_attribute_specs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Diagnostics.Contracts.Empty_type_attribute_specs; | ||
|
||
public class Can_decorate_empty | ||
{ | ||
[Test] | ||
public void Classes() | ||
=> typeof(SomeEmptyClass).Should().BeDecoratedWith<EmptyTestClassAttribute>(); | ||
|
||
[Test] | ||
public void Enums() | ||
=> typeof(SomeEmptyEnumeration).Should().BeDecoratedWith<EmptyTestEnumAttribute>(); | ||
|
||
[Test] | ||
public void Interfaces() | ||
=> typeof(ISomeEmptyInterface).Should().BeDecoratedWith<EmptyTestInterfaceAttribute>(); | ||
|
||
[Test] | ||
public void Structs() | ||
=> typeof(SomeEmptyStruct).Should().BeDecoratedWith<EmptyTestStructAttribute>(); | ||
} | ||
|
||
[EmptyTestClass] | ||
internal class SomeEmptyClass { } | ||
|
||
[EmptyTestEnum] | ||
internal enum SomeEmptyEnumeration { } | ||
|
||
[EmptyTestInterface] | ||
internal interface ISomeEmptyInterface { } | ||
|
||
[EmptyTestStruct] | ||
internal struct SomeEmptyStruct { } |
28 changes: 28 additions & 0 deletions
28
specs/Qowaiv.Specs/Diagnostics/Contracts/Impure_attribute_specs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Diagnostics.Contracts.Impure_attribute_specs; | ||
|
||
public class Can_decorate_methods_with | ||
{ | ||
[Test] | ||
public void Collection_mutation_attribute() | ||
=> typeof(SomeClass).GetMethod(nameof(SomeClass.CollectionMutation)).Should().BeDecoratedWith<CollectionMutationAttribute>(); | ||
|
||
[Test] | ||
public void Impure_attribute() | ||
=> typeof(SomeClass).GetMethod(nameof(SomeClass.Impure)).Should().BeDecoratedWith<ImpureAttribute>(); | ||
|
||
[Test] | ||
public void Fluent_syntax_attribute() | ||
=> typeof(SomeClass).GetMethod(nameof(SomeClass.FluentSyntax)).Should().BeDecoratedWith<FluentSyntaxAttribute>(); | ||
} | ||
|
||
internal class SomeClass | ||
{ | ||
[CollectionMutation("It just returns if addition worked.")] | ||
public bool CollectionMutation(HashSet<SomeClass> set) => set.Add(this); | ||
|
||
[Impure("It has side effects.")] | ||
public static int Impure() => 42; | ||
|
||
[FluentSyntax("We like fluent syntaxes.")] | ||
public SomeClass FluentSyntax() => this; | ||
} |
13 changes: 13 additions & 0 deletions
13
specs/Qowaiv.Specs/Diagnostics/Contracts/Inheritable_attribute_specs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Diagnostics.Contracts.Inheritable_attribute_specs; | ||
|
||
internal class Can_decorate | ||
{ | ||
[Test] | ||
public void Classes() | ||
=> typeof(SomeClass).Should().BeDecoratedWith<InheritableAttribute>(); | ||
} | ||
|
||
[Inheritable("For test purposes")] | ||
internal class SomeClass | ||
{ | ||
} |
13 changes: 13 additions & 0 deletions
13
specs/Qowaiv.Specs/Diagnostics/Contracts/Mutable_attribute_specs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Diagnostics.Contracts.Mutable_attribute_specs; | ||
|
||
internal class Can_decorate | ||
{ | ||
[Test] | ||
public void Classes() | ||
=> typeof(SomeClass).Should().BeDecoratedWith<MutableAttribute>(); | ||
} | ||
|
||
[Mutable("For test purposes")] | ||
internal class SomeClass | ||
{ | ||
} |
26 changes: 26 additions & 0 deletions
26
specs/Qowaiv.Specs/Diagnostics/Contracts/Will_be_sealed_attribute_specs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Diagnostics.Contracts.Will_be_sealed_attribute_specs; | ||
|
||
internal class Can_decorate | ||
{ | ||
[Test] | ||
public void Classes() | ||
=> typeof(SomeClass).Should().BeDecoratedWith<WillBeSealedAttribute>(); | ||
|
||
[Test] | ||
public void Properties() | ||
=> typeof(SomeClass).GetProperty(nameof(SomeClass.Property)).Should().BeDecoratedWith<WillBeSealedAttribute>(); | ||
|
||
[Test] | ||
public void Methods() | ||
=> typeof(SomeClass).GetMethod(nameof(SomeClass.Method)).Should().BeDecoratedWith<WillBeSealedAttribute>(); | ||
} | ||
|
||
[WillBeSealed("For test purposes")] | ||
internal class SomeClass | ||
{ | ||
[WillBeSealed("No reason to change this property.")] | ||
public virtual int Property { get; } = 42; | ||
|
||
[WillBeSealed("No reason to change this method.")] | ||
public virtual int Method() => 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the class is empty by design.</summary> | ||
/// <remarks> | ||
/// Using this attribute prevents S2094 (Classes should not be empty) from | ||
/// showing up. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public class EmptyClassAttribute(string justification) : EmptyTypeAttribute(justification) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the enum is empty by design.</summary> | ||
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public class EmptyEnumAttribute(string justification) : EmptyTypeAttribute(justification) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the class is empty by design.</summary> | ||
[AttributeUsage(AttributeTargets.Interface, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public class EmptyInterfaceAttribute(string justification) : EmptyTypeAttribute(justification) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the struct is empty by design.</summary> | ||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public class EmptyStructAttribute(string justification) : EmptyTypeAttribute(justification) { } |
10 changes: 10 additions & 0 deletions
10
src/Qowaiv.Diagnostics.Contracts/EmptyTestClassAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the class is empty by design.</summary> | ||
/// <remarks> | ||
/// Using this attribute prevents S2094 (Classes should not be empty) from | ||
/// showing up. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public sealed class EmptyTestClassAttribute(string? justification = null) : EmptyClassAttribute(justification ?? "For test purposes.") { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the enum is empty by design.</summary> | ||
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public sealed class EmptyTestEnumAttribute(string? justification = null) : EmptyEnumAttribute(justification ?? "For test purposes.") { } |
6 changes: 6 additions & 0 deletions
6
src/Qowaiv.Diagnostics.Contracts/EmptyTestInterfaceAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the class is empty by design.</summary> | ||
[AttributeUsage(AttributeTargets.Interface, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public sealed class EmptyTestInterfaceAttribute(string? justification = null) : EmptyInterfaceAttribute(justification ?? "For test purposes.") { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the struct is empty by design.</summary> | ||
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)] | ||
[Conditional("CONTRACTS_FULL")] | ||
public sealed class EmptyTestStructAttribute(string? justification = null) : EmptyStructAttribute(justification ?? "For test purposes.") { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Qowaiv.Diagnostics.Contracts; | ||
|
||
/// <summary>Indicates the type is empty by design.</summary> | ||
[Conditional("CONTRACTS_FULL")] | ||
public abstract class EmptyTypeAttribute(string justification) : Attribute | ||
Check warning on line 5 in src/Qowaiv.Diagnostics.Contracts/EmptyTypeAttribute.cs GitHub Actions / Build
Check warning on line 5 in src/Qowaiv.Diagnostics.Contracts/EmptyTypeAttribute.cs GitHub Actions / Build
|
||
{ | ||
/// <summary>The justification of this decoration.</summary> | ||
public string Justification { get; } = justification; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.