Skip to content

Commit c41426e

Browse files
committed
fix tests
1 parent f45e5c8 commit c41426e

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetSourcesTests.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,8 +1201,9 @@ public void List_Sources_LocalizatedPackagesourceKeys_ConsideredDiffererent()
12011201
/// <summary>
12021202
/// Verify non-zero status code and proper messages
12031203
/// </summary>
1204-
/// <remarks>Checks invalid arguments message in stderr, check help message in stdout</remarks>
1205-
/// <param name="commandName">The nuget.exe command name to verify, without "nuget.exe" at the beginning</param>
1204+
/// <remarks>Checks invalid arguments message in stderr or stdout (System.CommandLine may write parse errors to stderr), check help message in stdout</remarks>
1205+
/// <param name="command">The nuget.exe command name to verify, without "nuget.exe" at the beginning</param>
1206+
/// <param name="badCommandIndex">Index of the bad argument in the space-split command string</param>
12061207
internal void TestCommandInvalidArguments(string command, int badCommandIndex)
12071208
{
12081209
using (var testDirectory = _fixture.CreateTestDirectory())
@@ -1222,24 +1223,17 @@ internal void TestCommandInvalidArguments(string command, int badCommandIndex)
12221223
// 3rd - nextParam
12231224
string badCommand = commandSplit[badCommandIndex];
12241225

1225-
// Assert command
1226-
Assert.Contains("'" + badCommand + "'", result.Output, StringComparison.InvariantCultureIgnoreCase);
1226+
// System.CommandLine may write parse errors to stderr, so check AllOutput
1227+
Assert.Contains("'" + badCommand + "'", result.AllOutput, StringComparison.InvariantCultureIgnoreCase);
12271228

1229+
// System.CommandLine uses "Unrecognized command or argument" or "'X' was not matched"
1230+
bool hasUnrecognized = result.AllOutput.Contains("Unrecognized command or argument", StringComparison.OrdinalIgnoreCase);
1231+
bool hasNotMatched = result.AllOutput.Contains("was not matched", StringComparison.OrdinalIgnoreCase);
1232+
Assert.True(hasUnrecognized || hasNotMatched,
1233+
"Expected 'Unrecognized command or argument' or 'was not matched' error. Actual output: " + result.AllOutput);
12281234

1229-
// Assert invalid argument message
1230-
string invalidMessage;
1231-
if (badCommand.StartsWith("-"))
1232-
{
1233-
invalidMessage = ": Unrecognized option";
1234-
}
1235-
else
1236-
{
1237-
invalidMessage = ": Unrecognized command";
1238-
}
1239-
1240-
Assert.True(result.Output.Contains(invalidMessage), "Expected error is " + invalidMessage + ". Actual error is " + result.Output);
1241-
// Verify traits of help message in stdout
1242-
Assert.Contains("Specify --help for a list of available options and commands.", result.Output);
1235+
// Verify help message is shown in output
1236+
Assert.Contains("Show help and usage information", result.AllOutput);
12431237
}
12441238
}
12451239
}

0 commit comments

Comments
 (0)