Skip to content

Commit 43c2b21

Browse files
committed
Fix: Bump to latest tunit version
1 parent a38aa03 commit 43c2b21

27 files changed

+776
-502
lines changed

.editorconfig

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# noinspection EditorConfigKeyCorrectness
12
[*]
23
charset = utf-8-bom
34
end_of_line = crlf
@@ -7,12 +8,15 @@ indent_style = space
78
indent_size = 4
89

910
# Microsoft .NET properties
11+
csharp_indent_braces = false
1012
csharp_new_line_before_members_in_object_initializers = false
1113
csharp_new_line_before_open_brace = none
12-
csharp_preferred_modifier_order = public, internal, protected, private, static, override, async, virtual, file, new, sealed, required, abstract, extern, volatile, unsafe, readonly:suggestion
14+
csharp_preferred_modifier_order = private, internal, protected, public, required, static, file, new, abstract, override, sealed, virtual, readonly, extern, volatile, unsafe, async:suggestion
1315
csharp_style_prefer_utf8_string_literals = true:suggestion
1416
csharp_style_var_elsewhere = false:none
1517
csharp_style_var_for_built_in_types = false:suggestion
18+
csharp_style_var_when_type_is_apparent = true:none
19+
csharp_using_directive_placement = outside_namespace:silent
1620
dotnet_naming_rule.private_constants_rule.import_to_resharper = True
1721
dotnet_naming_rule.private_constants_rule.resharper_description = Constant fields (private)
1822
dotnet_naming_rule.private_constants_rule.resharper_guid = 236f7aa5-7b06-43ca-bf2a-9b31bfcff09a
@@ -92,6 +96,7 @@ dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds =
9296
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field
9397
dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance
9498
dotnet_sort_system_directives_first = false
99+
csharp_new_line_between_members = false
95100
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
96101
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
97102
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
@@ -104,8 +109,9 @@ dotnet_style_qualification_for_property = false:suggestion
104109
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
105110

106111
# ReSharper properties
112+
resharper_accessor_owner_body = expression_body
107113
resharper_align_multiline_binary_expressions_chain = false
108-
resharper_align_multiline_statement_conditions = false
114+
resharper_align_multiline_statement_Assertions = false
109115
resharper_arguments_anonymous_function = named
110116
resharper_arguments_skip_single = true
111117
resharper_autodetect_indent_settings = true
@@ -118,25 +124,30 @@ resharper_blank_lines_around_property = 0
118124
resharper_braces_for_for = required
119125
resharper_braces_for_foreach = required_for_multiline_statement
120126
resharper_braces_for_ifelse = not_required
121-
resharper_braces_for_while = required_for_multiline
127+
resharper_braces_for_using = required
128+
resharper_braces_for_while = required_for_multiline_statement
122129
resharper_braces_redundant = false
123130
resharper_cpp_insert_final_newline = true
131+
resharper_csharp_align_multiline_argument = false
124132
resharper_csharp_blank_lines_around_field = 0
125133
resharper_csharp_blank_lines_around_invocable = 0
126134
resharper_csharp_blank_lines_around_region = 0
127135
resharper_csharp_blank_lines_inside_region = 0
128136
resharper_csharp_insert_final_newline = true
129137
resharper_csharp_keep_blank_lines_in_declarations = 100
130-
resharper_csharp_max_line_length = 505
138+
resharper_csharp_max_line_length = 709
131139
resharper_csharp_remove_blank_lines_near_braces_in_code = false
132140
resharper_csharp_remove_blank_lines_near_braces_in_declarations = false
133141
resharper_csharp_space_around_alias_eq = false
142+
resharper_csharp_space_around_shift_op = false
134143
resharper_csharp_space_before_trailing_comment = false
135144
resharper_csharp_stick_comment = false
136145
resharper_csharp_wrap_after_declaration_lpar = true
137146
resharper_csharp_wrap_before_binary_opsign = true
138147
resharper_csharp_wrap_before_declaration_rpar = true
139148
resharper_csharp_wrap_extends_list_style = chop_if_long
149+
resharper_csharp_wrap_parameters_style = chop_if_long
150+
resharper_force_attribute_style = join
140151
resharper_formatter_off_tag = @formatter:off
141152
resharper_formatter_on_tag = @formatter:on
142153
resharper_formatter_tags_enabled = true
@@ -149,23 +160,32 @@ resharper_keep_existing_declaration_block_arrangement = true
149160
resharper_keep_existing_embedded_block_arrangement = true
150161
resharper_max_attribute_length_for_same_line = 70
151162
resharper_method_or_operator_body = expression_body
163+
resharper_nested_ternary_style = expanded
164+
resharper_object_creation_when_type_evident = target_typed
152165
resharper_parentheses_redundancy_style = remove
153-
resharper_place_accessorholder_attribute_on_same_line = false
166+
resharper_place_accessorholder_attribute_on_same_line = true
154167
resharper_place_expr_accessor_on_single_line = true
155168
resharper_place_expr_property_on_single_line = true
169+
resharper_place_record_field_attribute_on_same_line = true
156170
resharper_place_simple_accessor_on_single_line = false
157171
resharper_place_simple_anonymousmethod_on_single_line = false
158172
resharper_place_simple_case_statement_on_same_line = true
159173
resharper_place_simple_embedded_statement_on_same_line = true
160174
resharper_place_simple_initializer_on_single_line = false
161175
resharper_place_simple_list_pattern_on_single_line = false
162-
resharper_place_type_attribute_on_same_line = if_owner_is_single_line
176+
resharper_place_single_method_argument_lambda_on_same_line = false
177+
resharper_place_type_attribute_on_same_line = false
163178
resharper_qualified_using_at_nested_scope = true
179+
resharper_space_in_singleline_anonymous_method = false
164180
resharper_space_within_empty_braces = false
165181
resharper_treat_case_statement_with_break_as_simple = false
166182
resharper_use_indent_from_vs = false
183+
resharper_wrap_array_initializer_style = chop_always
184+
resharper_wrap_before_primary_constructor_declaration_rpar = true
185+
resharper_wrap_chained_binary_expressions = wrap_if_long
167186
resharper_wrap_list_pattern = chop_always
168187
resharper_wrap_object_and_collection_initializer_style = chop_always
188+
resharper_wrap_ternary_expr_style = chop_if_long
169189

170190
# ReSharper inspection severities
171191
resharper_arrange_redundant_parentheses_highlighting = hint
@@ -201,3 +221,7 @@ indent_size = 2
201221
indent_style = space
202222
indent_size = 4
203223
tab_width = 4
224+
225+
[*.razor]
226+
csharp_space_after_keywords_in_control_flow_statements = true
227+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.CodeAnalysis;
5+
using TUnit.Assertions.Core;
6+
7+
namespace CodeOfChaos.Testing.TUnit.Assertions;
8+
// ---------------------------------------------------------------------------------------------------------------------
9+
// Code
10+
// ---------------------------------------------------------------------------------------------------------------------
11+
public class GeneratorDriverRunResultHasSourceTextEqualToAssertion(
12+
AssertionContext<GeneratorDriverRunResult> context,
13+
string filename,
14+
string expected,
15+
StringComparison stringComparison,
16+
bool ignoreWhiteSpace,
17+
bool withTrimming
18+
)
19+
: Assertion<GeneratorDriverRunResult>(context) {
20+
21+
// -----------------------------------------------------------------------------------------------------------------
22+
// Methods
23+
// -----------------------------------------------------------------------------------------------------------------
24+
protected override string GetExpectation() => "to have a source with the the expected text";
25+
26+
protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<GeneratorDriverRunResult> metadata) {
27+
if (metadata.Exception is {} exception) return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().Name}"));
28+
29+
GeneratorDriverRunResult? generatorResult = metadata.Value;
30+
31+
if (generatorResult is null) return Task.FromResult(AssertionResult.Failed("Compilation is null"));
32+
33+
GeneratedSourceResult? generatedSource = generatorResult.Results
34+
.SelectMany(result => result.GeneratedSources)
35+
.SingleOrDefault(result => result.HintName == filename);
36+
37+
if (generatedSource is null) return Task.FromResult(AssertionResult.Failed($"Could not find source with name '{filename}'"));
38+
if (generatedSource.Value.SourceText is not {} sourceText) return Task.FromResult(AssertionResult.Failed("Source text is null"));
39+
40+
string actualValue = sourceText.ToString();
41+
string expectedValue = expected;
42+
43+
// Use the TUnit Equals String so it follows the same structure
44+
if (withTrimming) {
45+
actualValue = actualValue.Trim();
46+
expectedValue = expectedValue.Trim();
47+
}
48+
49+
if (ignoreWhiteSpace) {
50+
actualValue = string.Concat(actualValue.Where(c => !char.IsWhiteSpace(c)));
51+
expectedValue = string.Concat(expectedValue.Where(c => !char.IsWhiteSpace(c)));
52+
}
53+
54+
if (string.Equals(actualValue, expectedValue, stringComparison)) return Task.FromResult(AssertionResult.Passed);
55+
return Task.FromResult(AssertionResult.Failed($"Source text does not match"));
56+
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
// ---------------------------------------------------------------------------------------------------------------------
2-
// Imports
3-
// ---------------------------------------------------------------------------------------------------------------------
4-
using Microsoft.CodeAnalysis;
5-
using System.Collections.Immutable;
6-
using TUnit.Assertions.AssertConditions;
7-
8-
namespace CodeOfChaos.Testing.TUnit.Conditions.Library;
9-
// ---------------------------------------------------------------------------------------------------------------------
10-
// Code
11-
// ---------------------------------------------------------------------------------------------------------------------
12-
public class ContainsDiagnosticAssertCondition<T>(Func<T, ValueTask<ImmutableArray<Diagnostic>>> getDiagnosticsAction, string expectedId) : BaseAssertCondition<T> {
13-
// -----------------------------------------------------------------------------------------------------------------
14-
// Methods
15-
// -----------------------------------------------------------------------------------------------------------------
16-
protected override string GetExpectation() => $"to have a diagnostic with Id \"{expectedId}\"";
17-
18-
protected override async ValueTask<AssertionResult> GetResult(T? actualValue, Exception? exception, AssertionMetadata assertionMetadata) {
19-
if (actualValue is null) return AssertionResult.Fail($"{nameof(T)} is null");
20-
21-
ImmutableArray<Diagnostic> diagnostics = await getDiagnosticsAction(actualValue);
22-
if (!diagnostics.Any()) return FailWithMessage("No diagnostics");
23-
if (diagnostics.Any(d => d.Id == expectedId)) return AssertionResult.Passed;
24-
25-
return FailWithMessage("No diagnostic with Id");
26-
}
27-
}
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.CodeAnalysis;
5+
using System.Collections.Immutable;
6+
using TUnit.Assertions.Core;
7+
8+
namespace CodeOfChaos.Testing.TUnit.Assertions.Library;
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
// Code
11+
// ---------------------------------------------------------------------------------------------------------------------
12+
public class ContainsDiagnosticAssertion<T>(
13+
AssertionContext<T> context,
14+
Func<T, ValueTask<ImmutableArray<Diagnostic>>> getDiagnosticsAction,
15+
string expectedId
16+
) : Assertion<T>(context) {
17+
// -----------------------------------------------------------------------------------------------------------------
18+
// Methods
19+
// -----------------------------------------------------------------------------------------------------------------
20+
protected override string GetExpectation() => $"to have a diagnostic with Id \"{expectedId}\"";
21+
22+
protected override async Task<AssertionResult> CheckAsync(EvaluationMetadata<T> metadata) {
23+
if (metadata.Exception is {} exception) return AssertionResult.Failed($"threw {exception.GetType().Name}");
24+
25+
T? actualValue = metadata.Value;
26+
if (actualValue is null) return AssertionResult.Failed($"{nameof(T)} is null");
27+
28+
ImmutableArray<Diagnostic> diagnostics = await getDiagnosticsAction(actualValue);
29+
if (!diagnostics.Any()) return AssertionResult.Failed("No diagnostics");
30+
if (diagnostics.Any(d => d.Id == expectedId)) return AssertionResult.Passed;
31+
32+
return AssertionResult.Failed("No diagnostic with Id");
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,56 @@
1-
// ---------------------------------------------------------------------------------------------------------------------
2-
// Imports
3-
// ---------------------------------------------------------------------------------------------------------------------
4-
using Microsoft.CodeAnalysis;
5-
using System.Collections.Immutable;
6-
using TUnit.Assertions.AssertConditions;
7-
8-
namespace CodeOfChaos.Testing.TUnit.Conditions.Library;
9-
// ---------------------------------------------------------------------------------------------------------------------
10-
// Code
11-
// ---------------------------------------------------------------------------------------------------------------------
12-
public class ContainsDiagnosticsExclusivelyAssertCondition<T>(Func<T, ValueTask<ImmutableArray<Diagnostic>>> getDiagnosticsAction, string[] expectedIds) : BaseAssertCondition<T> {
13-
private readonly HashSet<string> ExpectedValuesHashSet = expectedIds.ToHashSet();
14-
15-
// -----------------------------------------------------------------------------------------------------------------
16-
// Methods
17-
// -----------------------------------------------------------------------------------------------------------------
18-
protected override string GetExpectation() => $"to have a compilation output with the following Ids \"{expectedIds}\"";
19-
protected override async ValueTask<AssertionResult> GetResult(T? actualValue, Exception? exception, AssertionMetadata assertionMetadata) {
20-
if (actualValue is null) return AssertionResult.Fail($"{nameof(T)} is null");
21-
22-
ImmutableArray<Diagnostic> diagnostics = await getDiagnosticsAction(actualValue);
23-
if (!diagnostics.Any() && expectedIds.Length == 0) return AssertionResult.Passed;
24-
if (!diagnostics.Any()) return FailWithMessage("No diagnostics");
25-
if (expectedIds.Length != diagnostics.Length) return FailWithMessage("Wrong number of diagnostics");
26-
27-
HashSet<string> diagnosticsHashSet = diagnostics.Select(d => d.Id).ToHashSet();
28-
29-
if (diagnosticsHashSet.SetEquals(ExpectedValuesHashSet)) return AssertionResult.Passed;
30-
31-
// Find which diagnostics are missing or unexpected
32-
string[] missingDiagnostics = ExpectedValuesHashSet.Except(diagnosticsHashSet).ToArray();
33-
string[] unexpectedDiagnostics = diagnosticsHashSet.Except(ExpectedValuesHashSet).ToArray();
34-
35-
string errorMessage = "Diagnostics do not match:";
36-
37-
if (missingDiagnostics.Length != 0) {
38-
errorMessage += $"\n - Missing diagnostics: {string.Join(", ", missingDiagnostics)}";
39-
}
40-
41-
if (unexpectedDiagnostics.Length != 0) {
42-
errorMessage += $"\n - Unexpected diagnostics: {string.Join(", ", unexpectedDiagnostics)}";
43-
}
44-
45-
return AssertionResult.Fail(errorMessage);
46-
47-
}
48-
}
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.CodeAnalysis;
5+
using System.Collections.Immutable;
6+
using TUnit.Assertions.Core;
7+
8+
namespace CodeOfChaos.Testing.TUnit.Assertions.Library;
9+
// ---------------------------------------------------------------------------------------------------------------------
10+
// Code
11+
// ---------------------------------------------------------------------------------------------------------------------
12+
public class ContainsDiagnosticsExclusivelyAssertion<T>(
13+
AssertionContext<T> context,
14+
Func<T, ValueTask<ImmutableArray<Diagnostic>>> getDiagnosticsAction,
15+
string[] expectedIds
16+
) : Assertion<T>(context) {
17+
private readonly HashSet<string> ExpectedValuesHashSet = expectedIds.ToHashSet();
18+
19+
// -----------------------------------------------------------------------------------------------------------------
20+
// Methods
21+
// -----------------------------------------------------------------------------------------------------------------
22+
protected override string GetExpectation() => $"to have a compilation output with the following Ids \"{expectedIds}\"";
23+
24+
protected override async Task<AssertionResult> CheckAsync(EvaluationMetadata<T> metadata) {
25+
if (metadata.Exception is {} exception) return AssertionResult.Failed($"threw {exception.GetType().Name}");
26+
27+
T? actualValue = metadata.Value;
28+
if (actualValue is null) return AssertionResult.Failed($"{nameof(T)} is null");
29+
30+
ImmutableArray<Diagnostic> diagnostics = await getDiagnosticsAction(actualValue);
31+
if (!diagnostics.Any() && expectedIds.Length == 0) return AssertionResult.Passed;
32+
if (!diagnostics.Any()) return AssertionResult.Failed("No diagnostics");
33+
if (expectedIds.Length != diagnostics.Length) return AssertionResult.Failed("Wrong number of diagnostics");
34+
35+
HashSet<string> diagnosticsHashSet = diagnostics.Select(d => d.Id).ToHashSet();
36+
37+
if (diagnosticsHashSet.SetEquals(ExpectedValuesHashSet)) return AssertionResult.Passed;
38+
39+
// Find which diagnostics are missing or unexpected
40+
string[] missingDiagnostics = ExpectedValuesHashSet.Except(diagnosticsHashSet).ToArray();
41+
string[] unexpectedDiagnostics = diagnosticsHashSet.Except(ExpectedValuesHashSet).ToArray();
42+
43+
string errorMessage = "Diagnostics do not match:";
44+
45+
if (missingDiagnostics.Length != 0) {
46+
errorMessage += $"\n - Missing diagnostics: {string.Join(", ", missingDiagnostics)}";
47+
}
48+
49+
if (unexpectedDiagnostics.Length != 0) {
50+
errorMessage += $"\n - Unexpected diagnostics: {string.Join(", ", unexpectedDiagnostics)}";
51+
}
52+
53+
return AssertionResult.Failed(errorMessage);
54+
55+
}
56+
}

0 commit comments

Comments
 (0)