Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in generating KeepOpen. #32

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/IDisposableGenerator/DisposableCodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ If Not Me.isDisposed AndAlso disposing Then

if (classItem.Owns.Any())
{
_ = sourceBuilder.Append($@" If Me.{(classItem.Stream ? "KeepOpen" : "IsOwned")} Then
_ = sourceBuilder.Append($@" If {(classItem.Stream ? "Not Me.KeepOpen" : "Me.IsOwned")} Then
");
foreach (var ownedItem in classItem.Owns)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace {workItem.Namespace};

if (classItem.Owns.Any())
{
_ = sourceBuilder.Append($@" if (this.{(classItem.Stream ? "KeepOpen" : "IsOwned")})
_ = sourceBuilder.Append($@" if ({(classItem.Stream ? "!this.KeepOpen" : "this.IsOwned")})
{{
");
foreach (var ownedItem in classItem.Owns)
Expand Down Expand Up @@ -285,7 +285,7 @@ namespace {workItem.Namespace}

if (classItem.Owns.Any())
{
_ = sourceBuilder.Append($@" if (this.{(classItem.Stream ? "KeepOpen" : "IsOwned")})
_ = sourceBuilder.Append($@" if ({(classItem.Stream ? "!this.KeepOpen" : "this.IsOwned")})
{{
");
foreach (var ownedItem in classItem.Owns)
Expand Down
2 changes: 1 addition & 1 deletion tests/IDisposableGeneratorTests.CSharp10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected override void Dispose(bool disposing)
{
if (!this.isDisposed && disposing)
{
if (this.KeepOpen)
if (!this.KeepOpen)
{
this.testDispose?.Dispose();
this.testDispose = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/IDisposableGeneratorTests.CSharp9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected override void Dispose(bool disposing)
{
if (!this.isDisposed && disposing)
{
if (this.KeepOpen)
if (!this.KeepOpen)
{
this.testDispose?.Dispose();
this.testDispose = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/IDisposableGeneratorTests.VisualBasic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Friend ReadOnly Property KeepOpen As Boolean
''' <inheritdoc/>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If Not Me.isDisposed AndAlso disposing Then
If Me.KeepOpen Then
If Not Me.KeepOpen Then
Me.testDispose?.Dispose()
Me.testDispose = Nothing
End If
Expand Down
13 changes: 5 additions & 8 deletions tests/IDisposableGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ public partial class IDisposableGeneratorTests
{
[Fact]
public async Task TestGeneratingNoInput()
=> _ = await Assert.ThrowsAsync<EqualWithMessageException>([ExcludeFromCodeCoverage] async () =>
{
await RunTest<CSGeneratorTest>(string.Empty, string.Empty).ConfigureAwait(false);
}).ConfigureAwait(false);
=> await RunTest<CSGeneratorTest>(string.Empty, string.Empty).ConfigureAwait(false);

private static async Task RunTest<TestType>(
string generatedSource,
Expand All @@ -34,9 +31,8 @@ private static async Task RunTest<TestType>(
case false when test is CSGeneratorTest tst:
{
tst.LanguageVersion = languageVersion!.Value;
var generatedAttributeSource = Properties.Resources.AttributeCodeCSharp!;
test.TestState.GeneratedSources.Add(
(typeof(IDisposableGenerator), "GeneratedAttributes.g.cs", generatedAttributeSource));
(typeof(IDisposableGenerator), "GeneratedAttributes.g.cs", Properties.Resources.AttributeCodeCSharp!));
if (generatedSources is not null
&& languageVersion == LanguageVersion.CSharp10)
{
Expand All @@ -61,14 +57,15 @@ private static async Task RunTest<TestType>(
}
case false when test is VBGeneratorTest:
{
var generatedAttributeSource = Properties.Resources.AttributeCodeVisualBasic!;
test.TestState.GeneratedSources.Add(
(typeof(IDisposableGeneratorVB), "GeneratedAttributes.g.vb", generatedAttributeSource));
(typeof(IDisposableGeneratorVB), "GeneratedAttributes.g.vb", Properties.Resources.AttributeCodeVisualBasic!));
test.TestState.GeneratedSources.Add(
(typeof(IDisposableGeneratorVB), "Disposables.g.vb", generatedSource));
break;
}
default:
test.TestState.GeneratedSources.Add(
(typeof(IDisposableGenerator), "GeneratedAttributes.g.cs", Properties.Resources.AttributeCodeCSharp!));
test.TestState.Sources.Clear();
break;
}
Expand Down