Skip to content

Commit

Permalink
Add unit test to guard against conflicting option prototypes (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Sep 29, 2021
1 parent 1056dca commit abe8931
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/Microsoft.DotNet.XHarness.CLI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.DotNet.XHarness.CLI.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.XHarness.CLI.Android;
using Microsoft.DotNet.XHarness.CLI.CommandArguments;
using Microsoft.DotNet.XHarness.CLI.Commands;
using Microsoft.DotNet.XHarness.CLI.Commands.Apple;
using Microsoft.DotNet.XHarness.CLI.Commands.Wasm;
using Microsoft.DotNet.XHarness.Common.CLI;
using Microsoft.Extensions.Logging;
using Mono.Options;
Expand Down Expand Up @@ -242,6 +246,41 @@ public void ExtraneousArgumentsDetectedInPassThroughMode()
Assert.False(_command.CommandRun);
}

[Theory]
[InlineData("apple test -h")]
[InlineData("apple run -h")]
[InlineData("apple just-test -h")]
[InlineData("apple just-run -h")]
[InlineData("apple install -h")]
[InlineData("apple uninstall -h")]
[InlineData("apple state -h")]

[InlineData("android test -h")]
[InlineData("android run -h")]
[InlineData("android install -h")]
[InlineData("android uninstall -h")]
[InlineData("android state -h")]

[InlineData("wasm test -h")]
[InlineData("wasm test-browser -h")]
public void ArgumentPrototypesAreNotClashing(string command)
{
// This test tries to run all of the commands which will fail because of some missing argument
// If we for example add a new option and that would clash with some already existing argument,
// this will fail to add the duplicate option prototype.
// (it already happened that we added -d to all commands and the WASM command failed because it already had -d)
var commandSet = new CommandSet("test")
{
new AppleCommandSet(),
new AndroidCommandSet(),
new WasmCommandSet(),
new XHarnessHelpCommand(),
new XHarnessVersionCommand()
};

Assert.Equal((int)ExitCode.HELP_SHOWN, commandSet.Run(command.Split(" ")));
}

private class SampleUnitTestArguments : XHarnessCommandArguments
{
public SampleNumberArgument Number { get; } = new();
Expand Down

0 comments on commit abe8931

Please sign in to comment.