Repository navigation
Conversation
SkowronskiAndrew
left a comment
There was a problem hiding this comment.
Thanks for taking this on, but it needs a fair bit more work to be helpful. As it stands the PR adds a second helper class for something the test project already has a helper for, and it only migrates two of the many copies, so overall it adds to the duplication instead of reducing it. Here is what it would need to be mergeable.
- Extend ConsoleTestHelper instead of adding CommandTestHelper
UnityDataTool.Tests/ConsoleTestHelper.cs already exists for this ("Helpers for running UnityDataTool commands while capturing their console output"). It has RunCapturingStdErr and RunCapturingStdOut, and several Analyze fixtures already use it. Please delete CommandTestHelper.cs and add the both-streams variant to ConsoleTestHelper, named to match the existing methods, for example:
public static async Task<(int exitCode, string stdOut, string stdErr)> RunCapturingOutput(params string[] args)
- Migrate all the private run-and-capture wrappers, not just two
These fixtures each have their own copy of the redirect/Program.Main/restore code in a private method. All of them should call ConsoleTestHelper and either be deleted or shrink to a one-line wrapper that adds the fixed arguments ("analyze", "find-refs" ... --stdout):
- AnalyzeExitCodeTests.RunAnalyze (both streams)
- AnalyzeOverwriteTests.RunAnalyze (stderr)
- AnalyzeDuplicateNameTests.RunAnalyze (stderr; identical to the AnalyzeOverwriteTests copy)
- SerializedFileCommandTests.RunCaptured (both streams; the same as the proposed helper)
- FindRefsTests.RunFindRefsOn (stdout)
- SceneBundleContentTests.RunAndCaptureStdout (stdout; asserts the exit code is 0 inside the helper, so keep that check at the call site)
Keep the existing assertions unchanged. If a wrapper used to capture only one stream, have it call the matching single-stream method, so this PR doesn't change what each test sees.
- Inline copies: either include them or list them for a follow-up
Many tests also redirect the console inline, inside the test method itself. The main places are DumpTests, ArchiveTests, SerializedFileCommandTests, UnityDataToolPlayerDataTests (the two no-TypeTree tests named in #139), ExtractedTypeTreeTests, UnityDataToolAssetBundleTests and WebBundleSupportTests. Converting these is welcome but not required for this PR. If you leave them, please say so in the PR description so #139 stays open with an accurate list of what's left.
- Out of scope
The output-folder setup and teardown that #139 also mentions is a separate change. Please leave it out of this PR.
- Small things
- Use the repo's commit format: [#139] Short description.
- Remove the extra blank line after RunAnalyze in AnalyzeExitCodeTests.cs.
- After the migration, check for using directives that are no longer needed, e.g. System.IO where StringWriter was the only use.
- Run the full dotnet test and include the results.
|
Thank you for the detailed feedback and guidance! I missed the existing ConsoleTestHelper in my initial implementation. I'll update the PR to extend ConsoleTestHelper instead of introducing a new helper class, and migrate all six private capture wrappers while preserving their existing behavior and assertions. I'll also document the remaining inline copies, follow the repository's commit message format, and rerun the full test suite. Thanks again for your review! |
Summay
Part of #139
Extract duplicated console-capture logic into a shared CommandTestHelper.
Changes
Testing
Scope
This PR addresses the console-capture portion of #139. Output-folder setup and cleanup remain outside its scope.