Skip to content
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
9 changes: 4 additions & 5 deletions src/CommandLine/ParserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public CultureInfo ParsingCulture
/// Gets or sets the <see cref="System.IO.TextWriter"/> used for help method output.
/// Setting this property to null, will disable help screen.
/// </summary>
/// <remarks>
/// It is the caller's responsibility to dispose or close the <see cref="TextWriter"/>.
/// </remarks>
public TextWriter HelpWriter
{
get { return helpWriter; }
Expand Down Expand Up @@ -165,11 +168,7 @@ private void Dispose(bool disposing)

if (disposing)
{
if (HelpWriter != null)
{
helpWriter.Dispose();
helpWriter = null;
}
// Do not dispose HelpWriter. It is the caller's responsibility.

disposed = true;
}
Expand Down
1 change: 1 addition & 0 deletions tests/CommandLine.Tests/CommandLine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="Unit\Infrastructure\FSharpOptionHelperTests.cs" />
<Compile Include="Unit\Core\ReflectionExtensions.cs" />
<Compile Include="Unit\ParserResultExtensionsTests.cs" />
<Compile Include="Unit\ParserSettingsTests.cs" />
<Compile Include="Unit\ParserTests.cs" />
<Compile Include="Unit\Text\HelpTextTests.cs" />
<Compile Include="Unit\UnParserExtensionsTests.cs" />
Expand Down
44 changes: 44 additions & 0 deletions tests/CommandLine.Tests/Unit/ParserSettingsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace CommandLine.Tests.Unit
{
public class ParserSettingsTests
{
public class DisposeTrackingStringWriter : StringWriter
{
public DisposeTrackingStringWriter()
{
Disposed = false;
}

public bool Disposed { get; private set; }

protected override void Dispose(bool disposing)
{
Disposed = true;
base.Dispose(disposing);
}
}

[Fact]
public void Disposal_does_not_dispose_HelpWriter()
{
using (DisposeTrackingStringWriter textWriter = new DisposeTrackingStringWriter())
{
using (ParserSettings parserSettings = new ParserSettings())
{
parserSettings.HelpWriter = textWriter;
}

textWriter.Disposed.Should().BeFalse("not disposed");
}
}
}
}