From d13d5f5661dec56b0210589e88f006fab95c90b7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 17 May 2026 06:55:05 +0000 Subject: [PATCH 1/4] Add unit tests for ResponseFileHelper.SplitCommandLine Cover the state-machine command-line tokenizer with 14 test cases: - Empty and whitespace-only inputs - Single and multiple tokens - Leading/trailing/multiple whitespace handling - Quoted strings with embedded spaces - Mixed quoted and unquoted tokens - Tab-separated tokens - Real-world response file line pattern Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../CommandLine/ResponseFileHelperTests.cs | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs new file mode 100644 index 0000000000..1e6ba65068 --- /dev/null +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs @@ -0,0 +1,146 @@ +// 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_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] + public void SplitCommandLine_OptionWithArgument_ReturnsAsSeperateTokens() + { + 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_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]); + } +} From d9924f104cdc34e04de6c1e342c0145625088165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 18 May 2026 17:05:26 +0200 Subject: [PATCH 2/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../CommandLine/ResponseFileHelperTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs index 1e6ba65068..9615dcbe57 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs @@ -93,7 +93,7 @@ public void SplitCommandLine_MultipleQuotedTokens_EachUnquotedSeparately() } [TestMethod] - public void SplitCommandLine_OptionWithArgument_ReturnsAsSeperateTokens() + public void SplitCommandLine_OptionWithArgument_ReturnsAsSeparateTokens() { string[] result = [.. ResponseFileHelper.SplitCommandLine("--filter TestClass1")]; From fa6b6cf60ec6947834d042cfbf1cb71d99b004e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 May 2026 15:13:02 +0000 Subject: [PATCH 3/4] Add missing ResponseFileHelper edge case tests Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../CommandLine/ResponseFileHelperTests.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs index 9615dcbe57..6f514a5c5b 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs @@ -22,6 +22,10 @@ public void SplitCommandLine_WhitespaceOnly_ReturnsEmpty() Assert.IsEmpty(result); } + [TestMethod] + public void SplitCommandLine_NullInput_ThrowsNullReferenceException() + => Assert.ThrowsException(() => ResponseFileHelper.SplitCommandLine(null!).ToArray()); + [TestMethod] public void SplitCommandLine_SingleToken_ReturnsSingleElement() { @@ -93,7 +97,7 @@ public void SplitCommandLine_MultipleQuotedTokens_EachUnquotedSeparately() } [TestMethod] - public void SplitCommandLine_OptionWithArgument_ReturnsAsSeparateTokens() + public void SplitCommandLine_OptionWithArgument_ReturnsSeparateTokens() { string[] result = [.. ResponseFileHelper.SplitCommandLine("--filter TestClass1")]; @@ -122,6 +126,14 @@ public void SplitCommandLine_QuotedStringContainingMultipleSpaces_PreservesInter 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() { From e4ef952236e59e49887b8df06f49abd6a968a644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 19 May 2026 05:56:39 +0200 Subject: [PATCH 4/4] Apply suggestion from @Evangelink --- .../CommandLine/ResponseFileHelperTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs index 6f514a5c5b..a4bd24cdc0 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ResponseFileHelperTests.cs @@ -24,7 +24,7 @@ public void SplitCommandLine_WhitespaceOnly_ReturnsEmpty() [TestMethod] public void SplitCommandLine_NullInput_ThrowsNullReferenceException() - => Assert.ThrowsException(() => ResponseFileHelper.SplitCommandLine(null!).ToArray()); + => Assert.Throws(() => ResponseFileHelper.SplitCommandLine(null!).ToArray()); [TestMethod] public void SplitCommandLine_SingleToken_ReturnsSingleElement()