Skip to content

Commit 19af0fd

Browse files
committed
feat: enhance command-line arguments and add output path support in CodeLineCounter
1 parent 34b1657 commit 19af0fd

16 files changed

+613
-140
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/codeql*
2121
/*.dot
2222
/*snyk*
23+
/exports
2324

2425
# Mac OS
2526
.DS_Store

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
"cwd": "${workspaceFolder}",
2121
"stopAtEntry": false,
2222
"console": "internalConsole"
23+
},
24+
{
25+
"name": "C#: CodeLineCounter - withOutputPath",
26+
"type": "coreclr",
27+
"request": "launch",
28+
"program": "${workspaceFolder}/CodeLineCounter/bin/Debug/net9.0/CodeLineCounter.dll",
29+
"args": ["-d", "${workspaceFolder}", "-output", "${workspaceFolder}\\exports" ],
30+
"cwd": "${workspaceFolder}",
31+
"stopAtEntry": false,
32+
"console": "internalConsole"
2333
}
2434
]
2535
}

CodeLineCounter.Tests/CodeDuplicationCheckerTests.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22

33
namespace CodeLineCounter.Tests
44
{
5-
public class CodeDuplicationCheckerTests
5+
public class CodeDuplicationCheckerTests : IDisposable
66
{
7+
private readonly string _testDirectory;
8+
private bool _disposed;
9+
10+
public CodeDuplicationCheckerTests()
11+
{
12+
_testDirectory = Path.Combine(Path.GetTempPath(), "CodeDuplicationCheckerTests");
13+
Directory.CreateDirectory(_testDirectory);
14+
}
15+
716
[Fact]
817
public void DetectCodeDuplicationInFiles_ShouldDetectDuplicates()
918
{
1019
// Arrange
11-
var file1 = "TestFile1.cs";
12-
var file2 = "TestFile2.cs";
20+
var file1 = Path.Combine(_testDirectory, "TestFile1.cs");
21+
var file2 = Path.Combine(_testDirectory, "TestFile2.cs");
1322

1423
var code1 = @"
1524
public class TestClass
@@ -85,8 +94,8 @@ public void AnotherTestMethod()
8594
}
8695
}";
8796

88-
var file1 = "TestFile3.cs";
89-
var file2 = "TestFile4.cs";
97+
var file1 = Path.Combine(_testDirectory, "TestFile3.cs");
98+
var file2 = Path.Combine(_testDirectory, "TestFile4.cs");
9099

91100
// Act
92101
checker.DetectCodeDuplicationInSourceCode(file1, sourceCode1);
@@ -126,8 +135,8 @@ public void AnotherTestMethod()
126135
}
127136
}";
128137

129-
var file1 = "TestFile5.cs";
130-
var file2 = "TestFile6.cs";
138+
var file1 = Path.Combine(_testDirectory, "TestFile5.cs");
139+
var file2 = Path.Combine(_testDirectory, "TestFile6.cs");
131140

132141
// Act
133142
checker.DetectCodeDuplicationInSourceCode(file1, sourceCode1);
@@ -137,5 +146,32 @@ public void AnotherTestMethod()
137146
// Assert
138147
Assert.Empty(result); // No duplicates should be detected
139148
}
149+
150+
protected virtual void Dispose(bool disposing)
151+
{
152+
if (!_disposed)
153+
{
154+
if (disposing && Directory.Exists(_testDirectory))
155+
{
156+
// Dispose managed resources
157+
Directory.Delete(_testDirectory, true);
158+
}
159+
160+
// Dispose unmanaged resources (if any)
161+
162+
_disposed = true;
163+
}
164+
}
165+
166+
public void Dispose()
167+
{
168+
Dispose(true);
169+
GC.SuppressFinalize(this);
170+
}
171+
172+
~CodeDuplicationCheckerTests()
173+
{
174+
Dispose(false);
175+
}
140176
}
141177
}

0 commit comments

Comments
 (0)