Skip to content

Commit b6bd8e2

Browse files
Add test for issue #48 error reporting
1 parent 40f7f9c commit b6bd8e2

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

UnityDataTool.Tests/UnityDataToolPlayerDataTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,39 @@ public async Task DumpText_PlayerData_TextFileCreatedCorrectly()
8585

8686
Assert.AreEqual(expected, content);
8787
}
88+
89+
[Test]
90+
public async Task Analyze_PlayerDataNoTypeTree_ReportsFailureCorrectly()
91+
{
92+
// Test for issue #48: Files that fail to process should be counted as failures, not successes
93+
var testDataFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "PlayerNoTypeTree");
94+
var databasePath = SQLTestHelper.GetDatabasePath(m_TestOutputFolder);
95+
96+
using var swOut = new StringWriter();
97+
using var swErr = new StringWriter();
98+
var currentOut = Console.Out;
99+
var currentErr = Console.Error;
100+
try
101+
{
102+
Console.SetOut(swOut);
103+
Console.SetError(swErr);
104+
105+
// Analyze should return 0 even if files fail (non-zero would be a critical error)
106+
Assert.AreEqual(0, await Program.Main(new string[] { "analyze", testDataFolder, "-p", "level0" }));
107+
108+
var output = swOut.ToString() + swErr.ToString();
109+
110+
// Check that the filename appears in the error output
111+
Assert.That(output, Does.Contain("level0"), "Expected 'level0' to appear in error output");
112+
113+
// Check that the summary line correctly reports the failure
114+
Assert.That(output, Does.Contain("Failed files: 1"), "Expected 'Failed files: 1' in summary");
115+
Assert.That(output, Does.Contain("Successfully processed files: 0"), "Expected 'Successfully processed files: 0' in summary");
116+
}
117+
finally
118+
{
119+
Console.SetOut(currentOut);
120+
Console.SetError(currentErr);
121+
}
122+
}
88123
}

0 commit comments

Comments
 (0)