Address code review feedback: fix exception handling and initialization order

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-05 17:36:08 +00:00
parent 49f2271253
commit e519f61f0f
2 changed files with 16 additions and 22 deletions

View File

@@ -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) =>

View File

@@ -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(