2017-03-07 04:53:26 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using FluentAssertions;
|
2017-03-09 17:14:55 +00:00
|
|
|
using System.Linq;
|
2017-03-07 04:53:26 +00:00
|
|
|
using Microsoft.DotNet.Cli;
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
|
|
|
using Xunit;
|
|
|
|
using static Microsoft.DotNet.Cli.CommandLine.Accept;
|
|
|
|
using static Microsoft.DotNet.Cli.CommandLine.Create;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tests.ParserTests
|
|
|
|
{
|
|
|
|
public class ArgumentForwardingExtensionsTests
|
|
|
|
{
|
|
|
|
[Fact]
|
2017-03-09 17:14:55 +00:00
|
|
|
public void AnOutgoingCommandLineCanBeGeneratedBasedOnAParseResult()
|
2017-03-07 04:53:26 +00:00
|
|
|
{
|
|
|
|
var command = Command("the-command", "",
|
2017-03-09 17:14:55 +00:00
|
|
|
Option("-o|--one", "",
|
2017-03-11 01:11:19 +00:00
|
|
|
ZeroOrOneArgument()
|
2017-03-16 20:22:08 +00:00
|
|
|
.ForwardAsSingle(o => $"/i:{o.Arguments.Single()}")),
|
2017-03-09 17:14:55 +00:00
|
|
|
Option("-t|--two", "",
|
2017-03-11 01:11:19 +00:00
|
|
|
NoArguments()
|
2017-03-09 17:14:55 +00:00
|
|
|
.ForwardAs("/s:true")));
|
2017-03-07 04:53:26 +00:00
|
|
|
|
2017-03-09 17:14:55 +00:00
|
|
|
var result = command.Parse("the-command -t -o 123");
|
2017-03-07 04:53:26 +00:00
|
|
|
|
|
|
|
result["the-command"]
|
2017-03-09 15:35:06 +00:00
|
|
|
.OptionValuesToBeForwarded()
|
2017-03-07 04:53:26 +00:00
|
|
|
.Should()
|
2017-03-09 17:14:55 +00:00
|
|
|
.BeEquivalentTo("/i:123", "/s:true");
|
2017-03-07 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void MultipleArgumentsCanBeJoinedWhenForwarding()
|
|
|
|
{
|
|
|
|
var command = Command("the-command", "",
|
2017-03-09 17:14:55 +00:00
|
|
|
Option("-x", "",
|
2017-03-11 01:11:19 +00:00
|
|
|
ZeroOrMoreArguments()
|
2017-03-16 20:22:08 +00:00
|
|
|
.ForwardAsSingle(o => $"/x:{string.Join("&", o.Arguments)}")));
|
2017-03-07 04:53:26 +00:00
|
|
|
|
|
|
|
var result = command.Parse("the-command -x one -x two");
|
|
|
|
|
|
|
|
result["the-command"]
|
2017-03-09 15:35:06 +00:00
|
|
|
.OptionValuesToBeForwarded()
|
2017-03-07 04:53:26 +00:00
|
|
|
.Should()
|
|
|
|
.BeEquivalentTo("/x:one&two");
|
|
|
|
}
|
2017-03-09 17:14:55 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void AnArgumentCanBeForwardedAsIs()
|
|
|
|
{
|
|
|
|
var command = Command("the-command", "",
|
|
|
|
Option("-x", "",
|
2017-03-11 01:11:19 +00:00
|
|
|
ZeroOrMoreArguments()
|
2017-03-09 17:14:55 +00:00
|
|
|
.Forward()));
|
|
|
|
|
|
|
|
var result = command.Parse("the-command -x one");
|
|
|
|
|
|
|
|
result["the-command"]
|
|
|
|
.OptionValuesToBeForwarded()
|
|
|
|
.Should()
|
|
|
|
.BeEquivalentTo("one");
|
|
|
|
}
|
2017-03-07 04:53:26 +00:00
|
|
|
}
|
2017-03-10 18:13:11 +00:00
|
|
|
}
|