From e519f61f0fabc4cea1c82695cbbe20fbd0b91c3c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 5 Jan 2026 17:36:08 +0000 Subject: [PATCH] Address code review feedback: fix exception handling and initialization order Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- .../BenchmarkBase.cs | 6 ++-- .../WriteBenchmarks.cs | 32 +++++++------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/tests/SharpCompress.Performance/BenchmarkBase.cs b/tests/SharpCompress.Performance/BenchmarkBase.cs index ae4a5b36..55b66f5a 100644 --- a/tests/SharpCompress.Performance/BenchmarkBase.cs +++ b/tests/SharpCompress.Performance/BenchmarkBase.cs @@ -17,9 +17,11 @@ public class BenchmarkBase StringComparison.OrdinalIgnoreCase ); var path = AppDomain.CurrentDomain.BaseDirectory.Substring(0, index); - var SOLUTION_BASE_PATH = Path.GetDirectoryName(path) ?? throw new ArgumentNullException(); + var solutionBasePath = + Path.GetDirectoryName(path) + ?? throw new InvalidOperationException("Could not determine solution base path"); - TEST_ARCHIVES_PATH = Path.Combine(SOLUTION_BASE_PATH, "TestArchives", "Archives"); + TEST_ARCHIVES_PATH = Path.Combine(solutionBasePath, "TestArchives", "Archives"); } protected string GetTestArchivePath(string filename) => diff --git a/tests/SharpCompress.Performance/WriteBenchmarks.cs b/tests/SharpCompress.Performance/WriteBenchmarks.cs index 51e80e14..95c31cdb 100644 --- a/tests/SharpCompress.Performance/WriteBenchmarks.cs +++ b/tests/SharpCompress.Performance/WriteBenchmarks.cs @@ -14,23 +14,24 @@ namespace SharpCompress.Performance; public class WriteBenchmarks : BenchmarkBase { private string _tempOutputPath = null!; - private readonly string[] _testFiles = null!; - - public WriteBenchmarks() - { - // Get some test files to compress - var originalPath = Path.Combine(Path.GetDirectoryName(TEST_ARCHIVES_PATH)!, "Original"); - if (Directory.Exists(originalPath)) - { - _testFiles = Directory.GetFiles(originalPath).Take(5).ToArray(); - } - } + private string[] _testFiles = null!; [GlobalSetup] public void Setup() { _tempOutputPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(_tempOutputPath); + + // Get some test files to compress + var originalPath = Path.Combine(Path.GetDirectoryName(TEST_ARCHIVES_PATH)!, "Original"); + if (Directory.Exists(originalPath)) + { + _testFiles = Directory.GetFiles(originalPath).Take(5).ToArray(); + } + else + { + _testFiles = []; + } } [GlobalCleanup] @@ -45,9 +46,6 @@ public class WriteBenchmarks : BenchmarkBase [Benchmark] public void ZipWriterWrite() { - if (_testFiles == null || _testFiles.Length == 0) - return; - var outputFile = Path.Combine(_tempOutputPath, "test.zip"); using var stream = File.Create(outputFile); using var writer = WriterFactory.Open( @@ -64,9 +62,6 @@ public class WriteBenchmarks : BenchmarkBase [Benchmark] public void TarWriterWrite() { - if (_testFiles == null || _testFiles.Length == 0) - return; - var outputFile = Path.Combine(_tempOutputPath, "test.tar"); using var stream = File.Create(outputFile); using var writer = WriterFactory.Open( @@ -83,9 +78,6 @@ public class WriteBenchmarks : BenchmarkBase [Benchmark] public void TarGzWriterWrite() { - if (_testFiles == null || _testFiles.Length == 0) - return; - var outputFile = Path.Combine(_tempOutputPath, "test.tar.gz"); using var stream = File.Create(outputFile); using var writer = WriterFactory.Open(