diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index c36daf92..78f87dee 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -239,9 +239,6 @@ public void Close() var outputPath = _config.OutputLocation; stream = _outputStreamFactory(outputPath); - var testOutputPath = _config.TestOutputLocation; - testStream = _outputStreamFactory(testOutputPath); - leaveStreamOpen = true; var usingDirectives = new SortedSet(StringComparer.Ordinal); @@ -333,6 +330,9 @@ public void Close() if (testHasAnyContents) { + var testOutputPath = _config.TestOutputLocation; + testStream = _outputStreamFactory(testOutputPath); + using var sw = new StreamWriter(testStream, s_defaultStreamWriterEncoding, DefaultStreamWriterBufferSize, leaveStreamOpen); sw.NewLine = "\n"; @@ -358,7 +358,7 @@ public void Close() } else { - testStream = null; + Debug.Assert(testStream is null); } }