Skip to content

Commit 95bcc31

Browse files
committed
fix(mstest): support C# file discovery under test/ directory
The test/ directory pattern was missing from C# test file discovery. While tests/, Tests/ patterns existed, the singular test/ was missing, causing files under test/IntegrationTests/ in repos like microsoft/testfx to not be detected. - Add test/ pattern to isCSharpTestFile - Add test cases fix #94
1 parent aaad38e commit 95bcc31

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

pkg/parser/scanner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,9 @@ func isCSharpTestFile(path string) bool {
809809
if strings.Contains(normalizedPath, ".Specs/") || strings.Contains(normalizedPath, ".Spec/") {
810810
return true
811811
}
812-
// "Tests/" as project folder pattern (both capitalized and lowercase)
813-
if strings.HasPrefix(normalizedPath, "Tests/") || strings.Contains(normalizedPath, "/Tests/") ||
814-
strings.HasPrefix(normalizedPath, "tests/") {
812+
// "test/", "tests/", "Tests/" as project folder patterns
813+
if strings.HasPrefix(normalizedPath, "test/") || strings.HasPrefix(normalizedPath, "tests/") ||
814+
strings.HasPrefix(normalizedPath, "Tests/") || strings.Contains(normalizedPath, "/Tests/") {
815815
return true
816816
}
817817

pkg/parser/scanner_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
_ "github.com/specvital/core/pkg/parser/strategies/cargotest"
1919
_ "github.com/specvital/core/pkg/parser/strategies/gtest"
2020
_ "github.com/specvital/core/pkg/parser/strategies/jest"
21+
_ "github.com/specvital/core/pkg/parser/strategies/mstest"
2122
_ "github.com/specvital/core/pkg/parser/strategies/phpunit"
2223
)
2324

@@ -1096,3 +1097,55 @@ fn integration_test() {
10961097
}
10971098
})
10981099
}
1100+
1101+
func TestScan_CSharpTestDirectory(t *testing.T) {
1102+
t.Run("should discover C# files in test/ directory", func(t *testing.T) {
1103+
tmpDir := t.TempDir()
1104+
1105+
// Create test/SomeProject/ directory structure
1106+
testDir := filepath.Join(tmpDir, "test", "SomeProject")
1107+
if err := os.MkdirAll(testDir, 0755); err != nil {
1108+
t.Fatalf("failed to create test dir: %v", err)
1109+
}
1110+
1111+
// Create a C# MSTest file with non-standard naming (like DataRowTests_Regular.cs)
1112+
testContent := []byte(`using Microsoft.VisualStudio.TestTools.UnitTesting;
1113+
1114+
namespace SomeProject;
1115+
1116+
[TestClass]
1117+
public class DataRowTests_Regular
1118+
{
1119+
[TestMethod]
1120+
public void Test1() => Assert.IsTrue(true);
1121+
}
1122+
`)
1123+
testFile := filepath.Join(testDir, "DataRowTests_Regular.cs")
1124+
if err := os.WriteFile(testFile, testContent, 0644); err != nil {
1125+
t.Fatalf("failed to write test file: %v", err)
1126+
}
1127+
1128+
src, err := source.NewLocalSource(tmpDir)
1129+
if err != nil {
1130+
t.Fatalf("failed to create source: %v", err)
1131+
}
1132+
defer src.Close()
1133+
1134+
result, err := parser.Scan(context.Background(), src)
1135+
if err != nil {
1136+
t.Fatalf("unexpected error: %v", err)
1137+
}
1138+
1139+
if len(result.Inventory.Files) != 1 {
1140+
t.Fatalf("expected 1 file, got %d", len(result.Inventory.Files))
1141+
}
1142+
1143+
file := result.Inventory.Files[0]
1144+
if file.Framework != "mstest" {
1145+
t.Errorf("expected framework 'mstest', got %q", file.Framework)
1146+
}
1147+
if file.Language != "csharp" {
1148+
t.Errorf("expected language 'csharp', got %q", file.Language)
1149+
}
1150+
})
1151+
}

tests/integration/testdata/golden/testfx-v4.0.2.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"repository": "testfx",
33
"ref": "v4.0.2",
44
"expectedFrameworks": ["mstest"],
5-
"fileCount": 264,
6-
"testCount": 1668,
5+
"fileCount": 320,
6+
"testCount": 1813,
77
"frameworkCounts": {
8-
"mstest": 264
8+
"mstest": 320
99
},
1010
"sampleFiles": [
1111
{
@@ -130,7 +130,7 @@
130130
}
131131
],
132132
"stats": {
133-
"filesMatched": 264,
134-
"filesScanned": 509
133+
"filesMatched": 320,
134+
"filesScanned": 675
135135
}
136136
}

0 commit comments

Comments
 (0)