-
Notifications
You must be signed in to change notification settings - Fork 294
[Test Improver] Add unit tests for ResponseFileHelper.SplitCommandLine #8325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Evangelink
merged 5 commits into
main
from
test-assist/response-file-helper-tests-004d52984fdd738c
May 19, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d13d5f5
Add unit tests for ResponseFileHelper.SplitCommandLine
github-actions[bot] d9924f1
Potential fix for pull request finding
Evangelink 7fbf901
Merge branch 'main' into test-assist/response-file-helper-tests-004d5…
Evangelink fa6b6cf
Add missing ResponseFileHelper edge case tests
Copilot e4ef952
Apply suggestion from @Evangelink
Evangelink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Platform.UnitTests; | ||
|
|
||
| [TestClass] | ||
| public sealed class ResponseFileHelperTests | ||
| { | ||
| [TestMethod] | ||
| public void SplitCommandLine_EmptyString_ReturnsEmpty() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine(string.Empty)]; | ||
|
|
||
| Assert.IsEmpty(result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_WhitespaceOnly_ReturnsEmpty() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine(" \t ")]; | ||
|
|
||
| Assert.IsEmpty(result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_NullInput_ThrowsNullReferenceException() | ||
| => Assert.Throws<NullReferenceException>(() => ResponseFileHelper.SplitCommandLine(null!).ToArray()); | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_SingleToken_ReturnsSingleElement() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("hello")]; | ||
|
|
||
| Assert.HasCount(1, result); | ||
| Assert.AreEqual("hello", result[0]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_MultipleTokens_ReturnsAllElements() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("one two three")]; | ||
|
|
||
| Assert.HasCount(3, result); | ||
| Assert.AreEqual("one", result[0]); | ||
| Assert.AreEqual("two", result[1]); | ||
| Assert.AreEqual("three", result[2]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_LeadingAndTrailingWhitespace_IsIgnored() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine(" hello world ")]; | ||
|
|
||
| Assert.HasCount(2, result); | ||
| Assert.AreEqual("hello", result[0]); | ||
| Assert.AreEqual("world", result[1]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_MultipleSpacesBetweenTokens_TokensSplitCorrectly() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("a b")]; | ||
|
|
||
| Assert.HasCount(2, result); | ||
| Assert.AreEqual("a", result[0]); | ||
| Assert.AreEqual("b", result[1]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_QuotedStringWithSpace_ReturnsSingleToken() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("\"hello world\"")]; | ||
|
|
||
| Assert.HasCount(1, result); | ||
| Assert.AreEqual("hello world", result[0]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_QuotedAndUnquotedTokens_SplitsCorrectly() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("--opt \"some value\" other")]; | ||
|
|
||
| Assert.HasCount(3, result); | ||
| Assert.AreEqual("--opt", result[0]); | ||
| Assert.AreEqual("some value", result[1]); | ||
| Assert.AreEqual("other", result[2]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_MultipleQuotedTokens_EachUnquotedSeparately() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("\"foo bar\" \"baz qux\"")]; | ||
|
|
||
| Assert.HasCount(2, result); | ||
| Assert.AreEqual("foo bar", result[0]); | ||
| Assert.AreEqual("baz qux", result[1]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
|
Evangelink marked this conversation as resolved.
|
||
| public void SplitCommandLine_OptionWithArgument_ReturnsSeparateTokens() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("--filter TestClass1")]; | ||
|
|
||
| Assert.HasCount(2, result); | ||
| Assert.AreEqual("--filter", result[0]); | ||
| Assert.AreEqual("TestClass1", result[1]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_DashPrefixedOptions_PreserveDashes() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("--timeout 30 -v")]; | ||
|
|
||
| Assert.HasCount(3, result); | ||
| Assert.AreEqual("--timeout", result[0]); | ||
| Assert.AreEqual("30", result[1]); | ||
| Assert.AreEqual("-v", result[2]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_QuotedStringContainingMultipleSpaces_PreservesInternalSpaces() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("\"a b c\"")]; | ||
|
|
||
| Assert.HasCount(1, result); | ||
| Assert.AreEqual("a b c", result[0]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_UnclosedQuote_ReturnsEmpty() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("\"hello world")]; | ||
|
|
||
| Assert.IsEmpty(result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_TabSeparatedTokens_SplitsOnTab() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("one\ttwo")]; | ||
|
|
||
| Assert.HasCount(2, result); | ||
| Assert.AreEqual("one", result[0]); | ||
| Assert.AreEqual("two", result[1]); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void SplitCommandLine_RealWorldResponseFileLine_ParsesCorrectly() | ||
| { | ||
| string[] result = [.. ResponseFileHelper.SplitCommandLine("--filter \"FullyQualifiedName~MyNamespace.MyClass\" --timeout 60")]; | ||
|
|
||
| Assert.HasCount(4, result); | ||
| Assert.AreEqual("--filter", result[0]); | ||
| Assert.AreEqual("FullyQualifiedName~MyNamespace.MyClass", result[1]); | ||
| Assert.AreEqual("--timeout", result[2]); | ||
| Assert.AreEqual("60", result[3]); | ||
| } | ||
| } | ||
|
Evangelink marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.