Fixing a bug in the restore option where specifying verbosity through /v was not entirely honored.

Adding tests for implicit restore for all the affected commands.

Fixing an issue where the command target was being passed to the restore command during implicit restore.

Adding restore params to all commands with implicit restore. Also, implicitly set the restore output to quiet.

Adding tests for the no-restore option.
This commit is contained in:
Livar Cunha 2017-06-02 23:32:53 -07:00
parent dd76fec564
commit 3231295acf
14 changed files with 475 additions and 179 deletions

View file

@ -14,6 +14,27 @@ namespace Microsoft.DotNet.Tools
private IEnumerable<string> ArgsToForward { get; }
private IEnumerable<string> ArgsToForwardToRestore
{
get
{
var restoreArguments = ArgsToForward.Where(a =>
!a.StartsWith("/t:") &&
!a.StartsWith("/target:") &&
!a.StartsWith("/ConsoleLoggerParameters:") &&
!a.StartsWith("/clp:"));
if (!restoreArguments.Any(a => a.StartsWith("/v:") || a.StartsWith("/verbosity:")))
{
restoreArguments = restoreArguments.Concat(new string[] { "/v:q" });
}
return restoreArguments;
}
}
private bool ShouldRunImplicitRestore => !NoRestore;
public RestoringCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
: base(msbuildArgs, msbuildPath)
{
@ -25,7 +46,7 @@ namespace Microsoft.DotNet.Tools
{
if (ShouldRunImplicitRestore)
{
int exitCode = RestoreCommand.Run(ArgsToForward.ToArray());
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore.ToArray());
if (exitCode != 0)
{
return exitCode;
@ -34,7 +55,5 @@ namespace Microsoft.DotNet.Tools
return base.Execute();
}
private bool ShouldRunImplicitRestore => !NoRestore;
}
}

View file

@ -1,6 +1,7 @@
// 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 System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools;
@ -18,26 +19,42 @@ namespace Microsoft.DotNet.Cli
.With(name: CommonLocalizableStrings.CmdProjectFile,
description:
"The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."),
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOptionName)
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--no-incremental",
LocalizableStrings.NoIncrementialOptionDescription),
Create.Option(
"--no-dependencies",
LocalizableStrings.NoDependenciesOptionDescription,
Accept.NoArguments()
.ForwardAs("/p:BuildProjectReferences=false")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
FullBuildOptions
);
private static Option[] FullBuildOptions
{
get
{
var fullBuildOptions = new List<Option>
{
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOptionName)
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--no-incremental",
LocalizableStrings.NoIncrementialOptionDescription),
Create.Option(
"--no-dependencies",
LocalizableStrings.NoDependenciesOptionDescription,
Accept.NoArguments()
.ForwardAs("/p:BuildProjectReferences=false")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption()
};
RestoreCommandParser.AddImplicitRestoreOptions(fullBuildOptions);
return fullBuildOptions.ToArray();
}
}
}
}

View file

@ -1,6 +1,7 @@
// 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 System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings;
@ -14,32 +15,47 @@ namespace Microsoft.DotNet.Cli
"pack",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments(),
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.CmdOutputDirDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdOutputDir)
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
Create.Option(
"--no-build",
LocalizableStrings.CmdNoBuildOptionDescription,
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
Create.Option(
"--include-symbols",
LocalizableStrings.CmdIncludeSymbolsDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
Create.Option(
"--include-source",
LocalizableStrings.CmdIncludeSourceDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"-s|--serviceable",
LocalizableStrings.CmdServiceableDescription,
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
FullPackOptions);
private static Option[] FullPackOptions
{
get
{
var fullPackOptions = new List<Option>
{
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.CmdOutputDirDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdOutputDir)
.ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")),
Create.Option(
"--no-build",
LocalizableStrings.CmdNoBuildOptionDescription,
Accept.NoArguments().ForwardAs("/p:NoBuild=true")),
Create.Option(
"--include-symbols",
LocalizableStrings.CmdIncludeSymbolsDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")),
Create.Option(
"--include-source",
LocalizableStrings.CmdIncludeSourceDescription,
Accept.NoArguments().ForwardAs("/p:IncludeSource=true")),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"-s|--serviceable",
LocalizableStrings.CmdServiceableDescription,
Accept.NoArguments().ForwardAs("/p:Serviceable=true")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption()
};
RestoreCommandParser.AddImplicitRestoreOptions(fullPackOptions);
return fullPackOptions.ToArray();
}
}
}
}

View file

@ -1,6 +1,7 @@
// 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 System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings;
@ -14,34 +15,49 @@ namespace Microsoft.DotNet.Cli
"publish",
LocalizableStrings.AppDescription,
Accept.ZeroOrMoreArguments(),
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOption)
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--manifest",
LocalizableStrings.ManifestOptionDescription,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.ManifestOption)
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
Create.Option(
"--self-contained",
LocalizableStrings.SelfContainedOptionDescription,
Accept.ZeroOrOneArgument()
.WithSuggestionsFrom("true", "false")
.ForwardAsSingle(o =>
{
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
return $"/p:SelfContained={value}";
})),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
FullPublishOptions);
private static Option[] FullPublishOptions
{
get
{
var fullPublishOptions = new List<Option>
{
CommonOptions.HelpOption(),
Create.Option(
"-o|--output",
LocalizableStrings.OutputOptionDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.OutputOption)
.ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")),
CommonOptions.FrameworkOption(),
CommonOptions.RuntimeOption(),
CommonOptions.ConfigurationOption(),
CommonOptions.VersionSuffixOption(),
Create.Option(
"--manifest",
LocalizableStrings.ManifestOptionDescription,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.ManifestOption)
.ForwardAsSingle(o => $"/p:TargetManifestFiles={string.Join("%3B", o.Arguments)}")),
Create.Option(
"--self-contained",
LocalizableStrings.SelfContainedOptionDescription,
Accept.ZeroOrOneArgument()
.WithSuggestionsFrom("true", "false")
.ForwardAsSingle(o =>
{
string value = o.Arguments.Any() ? o.Arguments.Single() : "true";
return $"/p:SelfContained={value}";
})),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption()
};
RestoreCommandParser.AddImplicitRestoreOptions(fullPublishOptions);
return fullPublishOptions.ToArray();
}
}
}
}

View file

@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Tools.Restore
"/t:Restore"
};
if (!parsedRestore.HasOption("verbosity"))
if (!HasVerbosityOption(parsedRestore))
{
msbuildArgs.Add("/ConsoleLoggerParameters:Verbosity=Minimal");
}
@ -45,7 +45,7 @@ namespace Microsoft.DotNet.Tools.Restore
msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded());
msbuildArgs.AddRange(parsedRestore.Arguments);
return new RestoreCommand(msbuildArgs, msbuildPath);
}
@ -65,5 +65,12 @@ namespace Microsoft.DotNet.Tools.Restore
return cmd.Execute();
}
private static bool HasVerbosityOption(AppliedOption parsedRestore)
{
return parsedRestore.HasOption("verbosity") ||
parsedRestore.Arguments.Any(a => a.Contains("/v:")) ||
parsedRestore.Arguments.Any(a => a.Contains("/verbosity:"));
}
}
}

View file

@ -1,6 +1,7 @@
// 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 System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using LocalizableStrings = Microsoft.DotNet.Tools.Restore.LocalizableStrings;
@ -14,15 +15,42 @@ namespace Microsoft.DotNet.Cli
"restore",
LocalizableStrings.AppFullName,
Accept.ZeroOrMoreArguments(),
CommonOptions.HelpOption(),
FullRestoreOptions);
private static Option[] FullRestoreOptions
{
get
{
var fullRestoreOptions = new List<Option>();
fullRestoreOptions.Add(CommonOptions.HelpOption());
AddImplicitRestoreOptions(fullRestoreOptions, true, true);
fullRestoreOptions.Add(CommonOptions.VerbosityOption());
return fullRestoreOptions.ToArray();
}
}
public static void AddImplicitRestoreOptions(
List<Option> commandOptions,
bool showHelp = false,
bool useShortOptions = false)
{
commandOptions.AddRange(ImplicitRestoreOptions(showHelp, useShortOptions)
.Where(o => !commandOptions.Any(c => c.Name == o.Name)));
}
private static Option[] ImplicitRestoreOptions(bool showHelp = false, bool useShortOptions = false)
{
return new Option[] {
Create.Option(
"-s|--source",
LocalizableStrings.CmdSourceOptionDescription,
useShortOptions ? "-s|--source" : "--source",
showHelp ? LocalizableStrings.CmdSourceOptionDescription : string.Empty,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.CmdSourceOption)
.ForwardAsSingle(o => $"/p:RestoreSources={string.Join("%3B", o.Arguments)}")),
Create.Option(
"-r|--runtime",
useShortOptions ? "-r|--runtime" : "--runtime" ,
LocalizableStrings.CmdRuntimeOptionDescription,
Accept.OneOrMoreArguments()
.WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile())
@ -30,29 +58,29 @@ namespace Microsoft.DotNet.Cli
.ForwardAsSingle(o => $"/p:RuntimeIdentifiers={string.Join("%3B", o.Arguments)}")),
Create.Option(
"--packages",
LocalizableStrings.CmdPackagesOptionDescription,
showHelp ? LocalizableStrings.CmdPackagesOptionDescription : string.Empty,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdPackagesOption)
.ForwardAsSingle(o => $"/p:RestorePackagesPath={o.Arguments.Single()}")),
Create.Option(
"--disable-parallel",
LocalizableStrings.CmdDisableParallelOptionDescription,
showHelp ? LocalizableStrings.CmdDisableParallelOptionDescription : string.Empty,
Accept.NoArguments()
.ForwardAs("/p:RestoreDisableParallel=true")),
Create.Option(
"--configfile",
LocalizableStrings.CmdConfigFileOptionDescription,
showHelp ? LocalizableStrings.CmdConfigFileOptionDescription : string.Empty,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdConfigFileOption)
.ForwardAsSingle(o => $"/p:RestoreConfigFile={o.Arguments.Single()}")),
Create.Option(
"--no-cache",
LocalizableStrings.CmdNoCacheOptionDescription,
showHelp ? LocalizableStrings.CmdNoCacheOptionDescription : string.Empty,
Accept.NoArguments()
.ForwardAs("/p:RestoreNoCache=true")),
Create.Option(
"--ignore-failed-sources",
LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription,
showHelp ? LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription : string.Empty,
Accept.NoArguments()
.ForwardAs("/p:RestoreIgnoreFailedSources=true")),
Create.Option(
@ -65,6 +93,8 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.CmdForceRestoreOptionDescription,
Accept.NoArguments()
.ForwardAs("/p:RestoreForce=true")),
CommonOptions.VerbosityOption());
CommonOptions.VerbosityOption()
};
}
}
}

View file

@ -21,6 +21,7 @@ namespace Microsoft.DotNet.Tools.Run
public string Project { get; private set; }
public IReadOnlyCollection<string> Args { get; private set; }
public bool NoRestore { get; private set; }
public IEnumerable<string> RestoreArgs { get; private set; }
private List<string> _args;
private bool ShouldBuild => !NoBuild;
@ -58,6 +59,7 @@ namespace Microsoft.DotNet.Tools.Run
string launchProfile,
bool noLaunchProfile,
bool noRestore,
IEnumerable<string> restoreArgs,
IReadOnlyCollection<string> args)
{
Configuration = configuration;
@ -67,6 +69,7 @@ namespace Microsoft.DotNet.Tools.Run
LaunchProfile = launchProfile;
NoLaunchProfile = noLaunchProfile;
Args = args;
RestoreArgs = restoreArgs;
NoRestore = noRestore;
}
@ -77,6 +80,7 @@ namespace Microsoft.DotNet.Tools.Run
string launchProfile = null,
bool? noLaunchProfile = null,
bool? noRestore = null,
IEnumerable<string> restoreArgs = null,
IReadOnlyCollection<string> args = null)
{
return new RunCommand(
@ -87,6 +91,7 @@ namespace Microsoft.DotNet.Tools.Run
launchProfile ?? this.LaunchProfile,
noLaunchProfile ?? this.NoLaunchProfile,
noRestore ?? this.NoRestore,
restoreArgs ?? this.RestoreArgs,
args ?? this.Args
);
}
@ -138,15 +143,7 @@ namespace Microsoft.DotNet.Tools.Run
buildArgs.Add("/nologo");
buildArgs.Add("/verbosity:quiet");
if (!string.IsNullOrWhiteSpace(Configuration))
{
buildArgs.Add($"/p:Configuration={Configuration}");
}
if (!string.IsNullOrWhiteSpace(Framework))
{
buildArgs.Add($"/p:TargetFramework={Framework}");
}
buildArgs.AddRange(RestoreArgs);
var buildResult = new RestoringCommand(buildArgs, NoRestore).Execute();
if (buildResult != 0)

View file

@ -1,6 +1,8 @@
// 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 System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Tools.Run;
using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings;
@ -24,9 +26,16 @@ namespace Microsoft.DotNet.Cli
launchProfile: o.SingleArgumentOrDefault("--launch-profile"),
noLaunchProfile: o.HasOption("--no-launch-profile"),
noRestore: o.HasOption("--no-restore"),
restoreArgs: o.OptionValuesToBeForwarded(),
args: o.Arguments
)),
options: new[]
options: FullRunOptions);
private static Option[] FullRunOptions
{
get
{
var fullRunOptions = new List<Option>
{
CommonOptions.HelpOption(),
CommonOptions.ConfigurationOption(),
@ -47,7 +56,13 @@ namespace Microsoft.DotNet.Cli
"--no-build",
LocalizableStrings.CommandOptionNoBuildDescription,
Accept.NoArguments()),
CommonOptions.NoRestoreOption(),
});
CommonOptions.NoRestoreOption()
};
RestoreCommandParser.AddImplicitRestoreOptions(fullRunOptions);
return fullRunOptions.ToArray();
}
}
}
}

View file

@ -1,3 +1,6 @@
// 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 System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
@ -15,74 +18,89 @@ namespace Microsoft.DotNet.Cli
.With(name: LocalizableStrings.CmdArgProject,
description: LocalizableStrings.CmdArgDescription),
false,
CommonOptions.HelpOption(),
Create.Option(
"-s|--settings",
LocalizableStrings.CmdSettingsDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdSettingsFile)
.ForwardAsSingle(o => $"/p:VSTestSetting={o.Arguments.Single()}")),
Create.Option(
"-t|--list-tests",
LocalizableStrings.CmdListTestsDescription,
Accept.NoArguments()
.ForwardAsSingle(o => "/p:VSTestListTests=true")),
Create.Option(
"--filter",
LocalizableStrings.CmdTestCaseFilterDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdTestCaseFilterExpression)
.ForwardAsSingle(o => $"/p:VSTestTestCaseFilter={o.Arguments.Single()}")),
Create.Option(
"-a|--test-adapter-path",
LocalizableStrings.CmdTestAdapterPathDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdTestAdapterPath)
.ForwardAsSingle(o => $"/p:VSTestTestAdapterPath={o.Arguments.Single()}")),
Create.Option(
"-l|--logger",
LocalizableStrings.CmdLoggerDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdLoggerOption)
.ForwardAsSingle(o =>
{
var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments));
return $"/p:VSTestLogger={loggersString}";
})),
CommonOptions.ConfigurationOption(),
CommonOptions.FrameworkOption(),
Create.Option(
"-o|--output",
LocalizableStrings.CmdOutputDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdOutputDir)
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
Create.Option(
"-d|--diag",
LocalizableStrings.CmdPathTologFileDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdPathToLogFile)
.ForwardAsSingle(o => $"/p:VSTestDiag={o.Arguments.Single()}")),
Create.Option(
"--no-build",
LocalizableStrings.CmdNoBuildDescription,
Accept.NoArguments()
.ForwardAsSingle(o => "/p:VSTestNoBuild=true")),
Create.Option(
"-r|--results-directory",
LocalizableStrings.CmdResultsDirectoryDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdPathToResultsDirectory)
.ForwardAsSingle(o => $"/p:VSTestResultsDirectory={o.Arguments.Single()}")),
Create.Option(
"--collect",
LocalizableStrings.cmdCollectDescription,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.cmdCollectFriendlyName)
.ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption());
FullTestOptions);
private static Option[] FullTestOptions
{
get
{
var fullTestOptions = new List<Option>
{
CommonOptions.HelpOption(),
Create.Option(
"-s|--settings",
LocalizableStrings.CmdSettingsDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdSettingsFile)
.ForwardAsSingle(o => $"/p:VSTestSetting={o.Arguments.Single()}")),
Create.Option(
"-t|--list-tests",
LocalizableStrings.CmdListTestsDescription,
Accept.NoArguments()
.ForwardAsSingle(o => "/p:VSTestListTests=true")),
Create.Option(
"--filter",
LocalizableStrings.CmdTestCaseFilterDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdTestCaseFilterExpression)
.ForwardAsSingle(o => $"/p:VSTestTestCaseFilter={o.Arguments.Single()}")),
Create.Option(
"-a|--test-adapter-path",
LocalizableStrings.CmdTestAdapterPathDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdTestAdapterPath)
.ForwardAsSingle(o => $"/p:VSTestTestAdapterPath={o.Arguments.Single()}")),
Create.Option(
"-l|--logger",
LocalizableStrings.CmdLoggerDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdLoggerOption)
.ForwardAsSingle(o =>
{
var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments));
return $"/p:VSTestLogger={loggersString}";
})),
CommonOptions.ConfigurationOption(),
CommonOptions.FrameworkOption(),
Create.Option(
"-o|--output",
LocalizableStrings.CmdOutputDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdOutputDir)
.ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")),
Create.Option(
"-d|--diag",
LocalizableStrings.CmdPathTologFileDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdPathToLogFile)
.ForwardAsSingle(o => $"/p:VSTestDiag={o.Arguments.Single()}")),
Create.Option(
"--no-build",
LocalizableStrings.CmdNoBuildDescription,
Accept.NoArguments()
.ForwardAsSingle(o => "/p:VSTestNoBuild=true")),
Create.Option(
"-r|--results-directory",
LocalizableStrings.CmdResultsDirectoryDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdPathToResultsDirectory)
.ForwardAsSingle(o => $"/p:VSTestResultsDirectory={o.Arguments.Single()}")),
Create.Option(
"--collect",
LocalizableStrings.cmdCollectDescription,
Accept.OneOrMoreArguments()
.With(name: LocalizableStrings.cmdCollectFriendlyName)
.ForwardAsSingle(o => $"/p:VSTestCollect=\"{string.Join(";", o.Arguments)}\"")),
CommonOptions.NoRestoreOption(),
CommonOptions.VerbosityOption()
};
RestoreCommandParser.AddImplicitRestoreOptions(fullTestOptions);
return fullTestOptions.ToArray();
}
}
private static string GetSemiColonEsacpedstring(string arg)
{

View file

@ -38,6 +38,35 @@ namespace Microsoft.DotNet.Cli.Build.Tests
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenBuilding()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance(testAppName)
.WithSourceFiles();
new BuildCommand()
.WithWorkingDirectory(testInstance.Root)
.Execute()
.Should().Pass();
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenBuildingWithTheNoRestoreOption()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance(testAppName)
.WithSourceFiles();
new BuildCommand()
.WithWorkingDirectory(testInstance.Root)
.ExecuteWithCapturedOutput("--no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void ItRunsWhenRestoringToSpecificPackageDir()
{
@ -62,7 +91,7 @@ namespace Microsoft.DotNet.Cli.Build.Tests
new BuildCommand()
.WithWorkingDirectory(rootPath)
.Execute()
.Execute("--no-restore")
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

View file

@ -158,7 +158,7 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
}
[Fact]
public void PackWorksWithLocalProjectJson()
public void PackWorksWithLocalProject()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
@ -171,6 +171,33 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
.Should().Pass();
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenPackaging()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
.WithSourceFiles();
new PackCommand()
.WithWorkingDirectory(testInstance.Root)
.Execute()
.Should().Pass();
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenPackagingWithTheNoRestoreOption()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
.WithSourceFiles();
new PackCommand()
.WithWorkingDirectory(testInstance.Root)
.ExecuteWithCapturedOutput("--no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void HasServiceableFlagWhenArgumentPassed()
{
@ -231,7 +258,7 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
new PackCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should()
.Pass();

View file

@ -44,6 +44,39 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
.And.HaveStdOutContaining("Hello World");
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenPublishing()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new PublishCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("--framework netcoreapp2.0")
.Should().Pass();
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenPublishingWithTheNoRestoreOption()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new PublishCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--framework netcoreapp2.0 --no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void ItPublishesARunnableSelfContainedApp()
{
@ -170,7 +203,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
new PublishCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

View file

@ -37,6 +37,40 @@ namespace Microsoft.DotNet.Cli.Run.Tests
.And.HaveStdOutContaining("Hello World!");
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenRunning()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.HaveStdOutContaining("Hello World!");
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenRunningWithTheNoRestoreOption()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void ItBuildsTheProjectBeforeRunning()
{
@ -160,7 +194,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests
new RunCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}

View file

@ -31,6 +31,43 @@ namespace Microsoft.DotNet.Cli.Test.Tests
result.ExitCode.Should().Be(1);
}
[Fact]
public void ItImplicitlyRestoresAProjectWhenTesting()
{
string testAppName = "VSTestCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
result.ExitCode.Should().Be(1);
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenTestingWithTheNoRestoreOption()
{
string testAppName = "VSTestCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-restore")
.Should().Fail()
.And.HaveStdOutContaining("project.assets.json' not found.");;
}
[Fact]
public void XunitSingleTFM()
{
@ -161,14 +198,14 @@ namespace Microsoft.DotNet.Cli.Test.Tests
new BuildCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should()
.Pass()
.And.NotHaveStdErr();
CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
.ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-restore");
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
@ -209,6 +246,7 @@ namespace Microsoft.DotNet.Cli.Test.Tests
.Execute()
.Should()
.Pass();
return testProjectDirectory;
}
}