From 00d35653be1a2238eb682806a66e8df3c3d44c10 Mon Sep 17 00:00:00 2001 From: AraHaan Date: Fri, 23 Feb 2024 12:22:39 -0500 Subject: [PATCH] Fixed tests to Compile with latest dependency changes as some of them are wildcard versions. This is what broke the build on the test assembly. --- .editorconfig | 234 ++++++++++++++++++ .github/workflows/codacy-analysis.yml | 8 +- .github/workflows/dotnetcore-build.yml | 8 +- .github/workflows/dotnetcore-publish.yml | 8 +- .github/workflows/dotnetcore.yml | 8 +- .../Directory.Build.props | 2 +- .../Directory.Packages.props | 5 + .../Directory.Packages.props | 5 + .../Directory.Packages.props | 5 + .../Directory.Packages.props | 5 + tests/CSGeneratorTest.cs | 19 +- tests/CSharpIncrementalGeneratorTest.cs | 32 ++- tests/ConfigOptions.cs | 14 +- tests/Directory.Build.props | 2 +- tests/Directory.Packages.props | 5 + tests/IDisposableGeneratorTests.CSharp10.cs | 16 +- tests/IDisposableGeneratorTests.CSharp9.cs | 14 +- .../IDisposableGeneratorTests.VisualBasic.cs | 14 +- tests/IDisposableGeneratorTests.cs | 4 +- tests/VBGeneratorTest.cs | 14 +- tests/VisualBasicIncrementalGeneratorTest.cs | 32 ++- 21 files changed, 361 insertions(+), 93 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..220b188 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,234 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +# C# files +[*.cs] + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# New line preferences +end_of_line = crlf +insert_final_newline = false + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = true:warning +dotnet_style_qualification_for_field = true +dotnet_style_qualification_for_method = true:warning +dotnet_style_qualification_for_property = true:warning + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_operators = never_if_unnecessary +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# Expression-level preferences +dotnet_style_coalesce_expression = true:warning +dotnet_style_collection_initializer = true:warning +dotnet_style_explicit_tuple_names = true:warning +dotnet_style_namespace_match_folder = true +dotnet_style_null_propagation = true:warning +dotnet_style_object_initializer = true:warning +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:warning +dotnet_style_prefer_collection_expression = when_types_loosely_match +dotnet_style_prefer_compound_assignment = true:warning +dotnet_style_prefer_conditional_expression_over_assignment = true:warning +dotnet_style_prefer_conditional_expression_over_return = true:warning +dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed +dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning +dotnet_style_prefer_inferred_tuple_names = true:warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning +dotnet_style_prefer_simplified_boolean_expressions = true:warning +dotnet_style_prefer_simplified_interpolation = true + +# Field preferences +dotnet_style_readonly_field = true:warning + +# Parameter preferences +dotnet_code_quality_unused_parameters = all:warning + +# Suppression preferences +dotnet_remove_unnecessary_suppression_exclusions = none + +# New line preferences +dotnet_style_allow_multiple_blank_lines_experimental = true +dotnet_style_allow_statement_immediately_after_block_experimental = true + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = true:warning +csharp_style_var_for_built_in_types = true:warning +csharp_style_var_when_type_is_apparent = true:warning + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true:warning +csharp_style_expression_bodied_constructors = true:warning +csharp_style_expression_bodied_indexers = true:warning +csharp_style_expression_bodied_lambdas = true:suggestion +csharp_style_expression_bodied_local_functions = true +csharp_style_expression_bodied_methods = true:warning +csharp_style_expression_bodied_operators = true:warning +csharp_style_expression_bodied_properties = true:warning + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true:warning +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_prefer_extended_property_pattern = true +csharp_style_prefer_not_pattern = true:warning +csharp_style_prefer_pattern_matching = true:warning +csharp_style_prefer_switch_expression = true:warning + +# Null-checking preferences +csharp_style_conditional_delegate_call = true:warning + +# Modifier preferences +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async +csharp_style_prefer_readonly_struct = true +csharp_style_prefer_readonly_struct_member = true + +# Code-block preferences +csharp_prefer_braces = true:warning +csharp_prefer_simple_using_statement = true +csharp_style_namespace_declarations = file_scoped:warning +csharp_style_prefer_method_group_conversion = true +csharp_style_prefer_primary_constructors = true +csharp_style_prefer_top_level_statements = true + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:warning +csharp_style_deconstructed_variable_declaration = true:warning +csharp_style_implicit_object_creation_when_type_is_apparent = true:warning +csharp_style_inlined_variable_declaration = true:warning +csharp_style_prefer_index_operator = true:warning +csharp_style_prefer_local_over_anonymous_function = true:warning +csharp_style_prefer_null_check_over_type_check = true +csharp_style_prefer_range_operator = true:warning +csharp_style_prefer_tuple_swap = true +csharp_style_prefer_utf8_string_literals = true +csharp_style_throw_expression = true:warning +csharp_style_unused_value_assignment_preference = discard_variable +csharp_style_unused_value_expression_statement_preference = discard_variable + +# 'using' directive preferences +csharp_using_directive_placement = inside_namespace:warning + +# New line preferences +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true +csharp_style_allow_embedded_statements_on_same_line_experimental = true + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = false +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = false + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +# IDE0005: Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/.github/workflows/codacy-analysis.yml b/.github/workflows/codacy-analysis.yml index e126eba..24a9db5 100644 --- a/.github/workflows/codacy-analysis.yml +++ b/.github/workflows/codacy-analysis.yml @@ -23,11 +23,11 @@ jobs: - name: Checkout code uses: actions/checkout@main - - name: .NET core build - uses: actions/setup-dotnet@main + - name: Install latest .NET 8 SDK + uses: Elskom/setup-latest-dotnet@main with: - dotnet-version: '6.0.x' - include-prerelease: true + SDK_VERSION: '8.0.200' + RUNTIME_VERSIONS: '' - name: Restore, Build, test, and pack uses: Elskom/build-dotnet@main diff --git a/.github/workflows/dotnetcore-build.yml b/.github/workflows/dotnetcore-build.yml index 3178c93..344dd8d 100644 --- a/.github/workflows/dotnetcore-build.yml +++ b/.github/workflows/dotnetcore-build.yml @@ -13,11 +13,11 @@ jobs: DOTNET_NOLOGO: true steps: - uses: actions/checkout@main - - name: .NET core build - uses: actions/setup-dotnet@main + - name: Install latest .NET 8 SDK + uses: Elskom/setup-latest-dotnet@main with: - dotnet-version: '6.0.x' - include-prerelease: true + SDK_VERSION: '8.0.200' + RUNTIME_VERSIONS: '' - name: Restore, Build, test, and pack uses: Elskom/build-dotnet@main diff --git a/.github/workflows/dotnetcore-publish.yml b/.github/workflows/dotnetcore-publish.yml index 599f86d..2582634 100644 --- a/.github/workflows/dotnetcore-publish.yml +++ b/.github/workflows/dotnetcore-publish.yml @@ -15,11 +15,11 @@ jobs: NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} steps: - uses: actions/checkout@main - - name: .NET core build - uses: actions/setup-dotnet@main + - name: Install latest .NET 8 SDK + uses: Elskom/setup-latest-dotnet@main with: - dotnet-version: '6.0.x' - include-prerelease: true + SDK_VERSION: '8.0.200' + RUNTIME_VERSIONS: '' - name: Restore, Build, test, pack, and push uses: Elskom/build-dotnet@main diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index b3280bf..a94eb38 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -11,11 +11,11 @@ jobs: DOTNET_NOLOGO: true steps: - uses: actions/checkout@main - - name: .NET core build - uses: actions/setup-dotnet@main + - name: Install latest .NET 8 SDK + uses: Elskom/setup-latest-dotnet@main with: - dotnet-version: '6.0.x' - include-prerelease: true + SDK_VERSION: '8.0.200' + RUNTIME_VERSIONS: '' - name: Restore, Build, test, and pack uses: Elskom/build-dotnet@main diff --git a/pkg/IDisposableGenerator/Directory.Build.props b/pkg/IDisposableGenerator/Directory.Build.props index dde3a2e..9d7440b 100644 --- a/pkg/IDisposableGenerator/Directory.Build.props +++ b/pkg/IDisposableGenerator/Directory.Build.props @@ -6,7 +6,7 @@ 1.1.1 Changes in this release: - Fixed bug in the KeepOpen dispose check in generated code. - Copyright (c) 2021~2022 + Copyright (c) 2021~2024 false true diff --git a/pkg/IDisposableGenerator/Directory.Packages.props b/pkg/IDisposableGenerator/Directory.Packages.props index f6ad6d8..be0465d 100644 --- a/pkg/IDisposableGenerator/Directory.Packages.props +++ b/pkg/IDisposableGenerator/Directory.Packages.props @@ -1,5 +1,10 @@ + + false + false + + diff --git a/src/IDisposableGenerator.CSharp/Directory.Packages.props b/src/IDisposableGenerator.CSharp/Directory.Packages.props index 5e6213a..dc31bf2 100644 --- a/src/IDisposableGenerator.CSharp/Directory.Packages.props +++ b/src/IDisposableGenerator.CSharp/Directory.Packages.props @@ -1,5 +1,10 @@ + + false + false + + diff --git a/src/IDisposableGenerator.VisualBasic/Directory.Packages.props b/src/IDisposableGenerator.VisualBasic/Directory.Packages.props index 3e93ecd..5dcafb1 100644 --- a/src/IDisposableGenerator.VisualBasic/Directory.Packages.props +++ b/src/IDisposableGenerator.VisualBasic/Directory.Packages.props @@ -1,5 +1,10 @@ + + false + false + + diff --git a/src/IDisposableGenerator/Directory.Packages.props b/src/IDisposableGenerator/Directory.Packages.props index 6ef939f..0b8ea51 100644 --- a/src/IDisposableGenerator/Directory.Packages.props +++ b/src/IDisposableGenerator/Directory.Packages.props @@ -1,5 +1,10 @@ + + false + false + + all diff --git a/tests/CSGeneratorTest.cs b/tests/CSGeneratorTest.cs index 75c3176..db4165e 100644 --- a/tests/CSGeneratorTest.cs +++ b/tests/CSGeneratorTest.cs @@ -2,17 +2,10 @@ namespace IDisposableGenerator.Tests; public class CSGeneratorTest : CSharpIncrementalGeneratorTest, IGeneratorTestBase { - public List<(string, string)> GlobalOptions { get; } = new(); - - public LanguageVersion LanguageVersion { get; set; } - - protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) - => CSharpGeneratorDriver.Create( - sourceGenerators, - project.AnalyzerOptions.AdditionalFiles, - (CSharpParseOptions)this.CreateParseOptions(), - new OptionsProvider(project.AnalyzerOptions.AnalyzerConfigOptionsProvider, this.GlobalOptions)); - - protected override ParseOptions CreateParseOptions() - => ((CSharpParseOptions)base.CreateParseOptions()).WithLanguageVersion(this.LanguageVersion); + // protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) + // => CSharpGeneratorDriver.Create( + // sourceGenerators, + // project.AnalyzerOptions.AdditionalFiles, + // (CSharpParseOptions)this.CreateParseOptions(), + // new OptionsProvider(project.AnalyzerOptions.AnalyzerConfigOptionsProvider, this.GlobalOptions)); } diff --git a/tests/CSharpIncrementalGeneratorTest.cs b/tests/CSharpIncrementalGeneratorTest.cs index 85cbd12..5d8856e 100644 --- a/tests/CSharpIncrementalGeneratorTest.cs +++ b/tests/CSharpIncrementalGeneratorTest.cs @@ -4,24 +4,36 @@ public class CSharpIncrementalGeneratorTest : Sourc where TSourceGenerator : IIncrementalGenerator, new() where TVerifier : IVerifier, new() { - protected override IEnumerable GetSourceGenerators() - => new[] { new TSourceGenerator().AsSourceGenerator() }; + protected override IEnumerable GetSourceGenerators() + => [typeof(TSourceGenerator)]; protected override string DefaultFileExt => "cs"; public override string Language => LanguageNames.CSharp; - [ExcludeFromCodeCoverage] - protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) - => CSharpGeneratorDriver.Create( - sourceGenerators, - project.AnalyzerOptions.AdditionalFiles, - (CSharpParseOptions)project.ParseOptions!, - project.AnalyzerOptions.AnalyzerConfigOptionsProvider); + public List<(string, string)> GlobalOptions { get; } = []; + + public LanguageVersion LanguageVersion { get; set; } + // [ExcludeFromCodeCoverage] + // protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) + // => CSharpGeneratorDriver.Create( + // sourceGenerators, + // project.AnalyzerOptions.AdditionalFiles, + // (CSharpParseOptions)project.ParseOptions!, + // project.AnalyzerOptions.AnalyzerConfigOptionsProvider); + + [ExcludeFromCodeCoverage] protected override CompilationOptions CreateCompilationOptions() => new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true); + [ExcludeFromCodeCoverage] protected override ParseOptions CreateParseOptions() - => new CSharpParseOptions(LanguageVersion.Default, DocumentationMode.Diagnose); + => new CSharpParseOptions(this.LanguageVersion, DocumentationMode.Diagnose); + + [ExcludeFromCodeCoverage] + protected override AnalyzerOptions GetAnalyzerOptions(Project project) + => new( + project.AnalyzerOptions.AdditionalFiles, + new OptionsProvider(project.AnalyzerOptions.AnalyzerConfigOptionsProvider, this.GlobalOptions)); } diff --git a/tests/ConfigOptions.cs b/tests/ConfigOptions.cs index df890c3..df6478e 100644 --- a/tests/ConfigOptions.cs +++ b/tests/ConfigOptions.cs @@ -3,17 +3,11 @@ namespace IDisposableGenerator.Tests; /// /// Allows adding additional global options /// -internal class ConfigOptions : AnalyzerConfigOptions +[method: ExcludeFromCodeCoverage] +internal class ConfigOptions(AnalyzerConfigOptions workspaceOptions, List<(string, string)> globalOptions) : AnalyzerConfigOptions { - private readonly AnalyzerConfigOptions _workspaceOptions; - private readonly Dictionary _globalOptions; - - [ExcludeFromCodeCoverage] - public ConfigOptions(AnalyzerConfigOptions workspaceOptions, List<(string, string)> globalOptions) - { - this._workspaceOptions = workspaceOptions; - this._globalOptions = globalOptions.ToDictionary( t => t.Item1, t => t.Item2); - } + private readonly AnalyzerConfigOptions _workspaceOptions = workspaceOptions; + private readonly Dictionary _globalOptions = globalOptions.ToDictionary(t => t.Item1, t => t.Item2); [ExcludeFromCodeCoverage] public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 64d07a5..afabd48 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -1,7 +1,7 @@ - net6.0 + net8.0 preview false enable diff --git a/tests/Directory.Packages.props b/tests/Directory.Packages.props index 20dbc60..3c89b32 100644 --- a/tests/Directory.Packages.props +++ b/tests/Directory.Packages.props @@ -1,5 +1,10 @@ + + false + false + + diff --git a/tests/IDisposableGeneratorTests.CSharp10.cs b/tests/IDisposableGeneratorTests.CSharp10.cs index feee154..e329199 100644 --- a/tests/IDisposableGeneratorTests.CSharp10.cs +++ b/tests/IDisposableGeneratorTests.CSharp10.cs @@ -41,7 +41,7 @@ public partial class TestDisposable [NullOnDispose] char[] testsetnull = new char[] { 't', 'e', 's', 't', 'i', 'n', 'g' }; } -", LanguageVersion.CSharp10).ConfigureAwait(false); +", LanguageVersion.CSharp10); [Fact] public async Task TestGeneratingDisposableNotOwnsCSharp10() @@ -82,7 +82,7 @@ internal partial class TestDisposable [NullOnDispose] char[] testsetnull = new char[] { 't', 'e', 's', 't', 'i', 'n', 'g' }; } -", LanguageVersion.CSharp10).ConfigureAwait(false); +", LanguageVersion.CSharp10); [Fact] public async Task TestGeneratingDisposableOwnsCSharp10() @@ -128,7 +128,7 @@ internal partial class TestDisposable [NullOnDispose] char[] testsetnull = new char[] { 't', 'e', 's', 't', 'i', 'n', 'g' }; } -", LanguageVersion.CSharp10).ConfigureAwait(false); +", LanguageVersion.CSharp10); [Fact] public async Task TestGeneratingStreamNotOwnsCSharp10() @@ -180,7 +180,7 @@ internal partial class TestDisposable : Stream public override void SetLength(long _) => throw new NotSupportedException(); public override void Write(byte[] _, int _1, int _2) => throw new NotSupportedException(); } -", LanguageVersion.CSharp10).ConfigureAwait(false); +", LanguageVersion.CSharp10); [Fact] public async Task TestGeneratingStreamOwnsCSharp10() @@ -237,7 +237,7 @@ internal partial class TestDisposable : Stream public override void SetLength(long _) => throw new NotSupportedException(); public override void Write(byte[] _, int _1, int _2) => throw new NotSupportedException(); } -", LanguageVersion.CSharp10).ConfigureAwait(false); +", LanguageVersion.CSharp10); [Fact] public async Task TestGeneratingCallOnDisposeCSharp10() @@ -286,7 +286,7 @@ private void TestCallThisOnDispose() // here as this is called inside of Dispose(bool)). } } -", LanguageVersion.CSharp10).ConfigureAwait(false); +", LanguageVersion.CSharp10); [Fact] public async Task TestAttributeOnDisposableMemberFromBCLCSharp10() @@ -324,7 +324,7 @@ internal partial class TestDisposable [StringLength(50)] public string? test { get; set; } = ""stuff here.""; } -", LanguageVersion.CSharp10).ConfigureAwait(false); +", LanguageVersion.CSharp10); [Fact] public async Task TestGeneratingDisposableWithMultipleNamespacesCSharp10() @@ -418,6 +418,6 @@ internal partial class TestDisposable [NullOnDispose] public string? test { get; set; } = ""stuff here.""; } -", LanguageVersion.CSharp10, testSources, generatedSources).ConfigureAwait(false); +", LanguageVersion.CSharp10, testSources, generatedSources); } } diff --git a/tests/IDisposableGeneratorTests.CSharp9.cs b/tests/IDisposableGeneratorTests.CSharp9.cs index 2cf649f..8b8e59b 100644 --- a/tests/IDisposableGeneratorTests.CSharp9.cs +++ b/tests/IDisposableGeneratorTests.CSharp9.cs @@ -45,7 +45,7 @@ public partial class TestDisposable char[] testsetnull = new char[] { 't', 'e', 's', 't', 'i', 'n', 'g' }; } } -").ConfigureAwait(false); +"); [Fact] public async Task TestGeneratingDisposableNotOwnsCSharp9() @@ -90,7 +90,7 @@ internal partial class TestDisposable char[] testsetnull = new char[] { 't', 'e', 's', 't', 'i', 'n', 'g' }; } } -").ConfigureAwait(false); +"); [Fact] public async Task TestGeneratingDisposableOwnsCSharp9() @@ -140,7 +140,7 @@ internal partial class TestDisposable char[] testsetnull = new char[] { 't', 'e', 's', 't', 'i', 'n', 'g' }; } } -").ConfigureAwait(false); +"); [Fact] public async Task TestGeneratingStreamNotOwnsCSharp9() @@ -196,7 +196,7 @@ internal partial class TestDisposable : Stream public override void Write(byte[] _, int _1, int _2) => throw new NotSupportedException(); } } -").ConfigureAwait(false); +"); [Fact] public async Task TestGeneratingStreamOwnsCSharp9() @@ -257,7 +257,7 @@ internal partial class TestDisposable : Stream public override void Write(byte[] _, int _1, int _2) => throw new NotSupportedException(); } } -").ConfigureAwait(false); +"); [Fact] public async Task TestGeneratingCallOnDisposeCSharp9() @@ -310,7 +310,7 @@ private void TestCallThisOnDispose() } } } -").ConfigureAwait(false); +"); [Fact] public async Task TestAttributeOnDisposableMemberFromBCLCSharp9() @@ -352,5 +352,5 @@ internal partial class TestDisposable public string? test { get; set; } = ""stuff here.""; } } -").ConfigureAwait(false); +"); } diff --git a/tests/IDisposableGeneratorTests.VisualBasic.cs b/tests/IDisposableGeneratorTests.VisualBasic.cs index 88a9741..f44036c 100644 --- a/tests/IDisposableGeneratorTests.VisualBasic.cs +++ b/tests/IDisposableGeneratorTests.VisualBasic.cs @@ -45,7 +45,7 @@ Private testDispose As IDisposable Private testsetnull As Char() = { ""t""c, ""e""c, ""s""c, ""t""c, ""i""c, ""n""c, ""g""c } End Class End Namespace -", null).ConfigureAwait(false); +", null); [Fact] public async Task TestGeneratingDisposableNotOwnsVisualBasic() @@ -90,7 +90,7 @@ Private testDispose As IDisposable Private testsetnull As Char() = { ""t""c, ""e""c, ""s""c, ""t""c, ""i""c, ""n""c, ""g""c } End Class End Namespace -", null).ConfigureAwait(false); +", null); [Fact] public async Task TestGeneratingDisposableOwnsVisualBasic() @@ -139,7 +139,7 @@ Private testDispose As IDisposable Private testsetnull As Char() = { ""t""c, ""e""c, ""s""c, ""t""c, ""i""c, ""n""c, ""g""c } End Class End Namespace -", null).ConfigureAwait(false); +", null); [Fact] public async Task TestGeneratingStreamNotOwnsVisualBasic() @@ -226,7 +226,7 @@ Throw New NotSupportedException() End Sub End Class End Namespace -", null).ConfigureAwait(false); +", null); [Fact] public async Task TestGeneratingStreamOwnsVisualBasic() @@ -317,7 +317,7 @@ Throw New NotSupportedException() End Sub End Class End Namespace -", null).ConfigureAwait(false); +", null); [Fact] public async Task TestGeneratingCallOnDisposeVisualBasic() @@ -368,7 +368,7 @@ Private Sub TestCallThisOnDispose() End Sub End Class End Namespace -", null).ConfigureAwait(false); +", null); [Fact] public async Task TestAttributeOnDisposableMemberFromBCLVisualBasic() @@ -410,5 +410,5 @@ Friend Partial Class TestDisposable Public Property test As String = ""stuff here."" End Class End Namespace -", null).ConfigureAwait(false); +", null); } diff --git a/tests/IDisposableGeneratorTests.cs b/tests/IDisposableGeneratorTests.cs index cce8ab3..e233e19 100644 --- a/tests/IDisposableGeneratorTests.cs +++ b/tests/IDisposableGeneratorTests.cs @@ -4,7 +4,7 @@ public partial class IDisposableGeneratorTests { [Fact] public async Task TestGeneratingNoInput() - => await RunTest(string.Empty, string.Empty).ConfigureAwait(false); + => await RunTest(string.Empty, string.Empty); private static async Task RunTest( string generatedSource, @@ -16,7 +16,7 @@ private static async Task RunTest( { var test = new TestType { - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, + ReferenceAssemblies = ReferenceAssemblies.Net.Net80, TestState = { Sources = diff --git a/tests/VBGeneratorTest.cs b/tests/VBGeneratorTest.cs index 5332869..0d9c052 100644 --- a/tests/VBGeneratorTest.cs +++ b/tests/VBGeneratorTest.cs @@ -2,12 +2,10 @@ namespace IDisposableGenerator.Tests; public class VBGeneratorTest : VisualBasicIncrementalGeneratorTest, IGeneratorTestBase { - public List<(string, string)> GlobalOptions { get; } = new(); - - protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) - => VisualBasicGeneratorDriver.Create( - sourceGenerators, - project.AnalyzerOptions.AdditionalFiles, - (VisualBasicParseOptions)project.ParseOptions!, - new OptionsProvider(project.AnalyzerOptions.AnalyzerConfigOptionsProvider, this.GlobalOptions)); + // protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) + // => VisualBasicGeneratorDriver.Create( + // sourceGenerators, + // project.AnalyzerOptions.AdditionalFiles, + // (VisualBasicParseOptions)project.ParseOptions!, + // new OptionsProvider(project.AnalyzerOptions.AnalyzerConfigOptionsProvider, this.GlobalOptions)); } diff --git a/tests/VisualBasicIncrementalGeneratorTest.cs b/tests/VisualBasicIncrementalGeneratorTest.cs index 67a205d..68119ec 100644 --- a/tests/VisualBasicIncrementalGeneratorTest.cs +++ b/tests/VisualBasicIncrementalGeneratorTest.cs @@ -4,24 +4,36 @@ public class VisualBasicIncrementalGeneratorTest : where TSourceGenerator : IIncrementalGenerator, new() where TVerifier : IVerifier, new() { - protected override IEnumerable GetSourceGenerators() - => new[] { new TSourceGenerator().AsSourceGenerator() }; + protected override IEnumerable GetSourceGenerators() + => [typeof(TSourceGenerator)]; protected override string DefaultFileExt => "vb"; public override string Language => LanguageNames.VisualBasic; - [ExcludeFromCodeCoverage] - protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) - => VisualBasicGeneratorDriver.Create( - sourceGenerators, - project.AnalyzerOptions.AdditionalFiles, - (VisualBasicParseOptions)project.ParseOptions!, - project.AnalyzerOptions.AnalyzerConfigOptionsProvider); + public List<(string, string)> GlobalOptions { get; } = []; + + public Microsoft.CodeAnalysis.VisualBasic.LanguageVersion LanguageVersion { get; set; } = Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.Default; + // [ExcludeFromCodeCoverage] + // protected override GeneratorDriver CreateGeneratorDriver(Project project, ImmutableArray sourceGenerators) + // => VisualBasicGeneratorDriver.Create( + // sourceGenerators, + // project.AnalyzerOptions.AdditionalFiles, + // (VisualBasicParseOptions)project.ParseOptions!, + // project.AnalyzerOptions.AnalyzerConfigOptionsProvider); + + [ExcludeFromCodeCoverage] protected override CompilationOptions CreateCompilationOptions() => new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + [ExcludeFromCodeCoverage] protected override ParseOptions CreateParseOptions() - => new VisualBasicParseOptions(Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.Default, DocumentationMode.Diagnose); + => new VisualBasicParseOptions(this.LanguageVersion, DocumentationMode.Diagnose); + + [ExcludeFromCodeCoverage] + protected override AnalyzerOptions GetAnalyzerOptions(Project project) + => new( + project.AnalyzerOptions.AdditionalFiles, + new OptionsProvider(project.AnalyzerOptions.AnalyzerConfigOptionsProvider, this.GlobalOptions)); }