Skip to content

Commit cd98668

Browse files
committed
Update tests due to presence of --interactive
1 parent b4edd25 commit cd98668

File tree

10 files changed

+51
-31
lines changed

10 files changed

+51
-31
lines changed

src/Cli/dotnet/CommonOptions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,21 @@ private static bool IsCIEnvironmentOrRedirected() =>
123123
/// A 'template' for interactive usage across the whole dotnet CLI. Use this as a base and then specialize it for your use cases.
124124
/// Despite being a 'forwarded option' there is no default forwarding configured, so if you want forwarding you can add it on a per-command basis.
125125
/// </summary>
126-
/// <remarks>If not set by a user, this will default to true if the user is not in a CI environment as detected by <see cref="Telemetry.CIEnvironmentDetectorForTelemetry.IsCIEnvironment"/>.</remarks>
127-
public static ForwardedOption<bool> InteractiveOption() =>
126+
/// <param name="acceptArgument">Whether the option accepts an boolean argument. If false, the option will be a flag.</param>
127+
/// <remarks>
128+
// If not set by a user, this will default to true if the user is not in a CI environment as detected by <see cref="Telemetry.CIEnvironmentDetectorForTelemetry.IsCIEnvironment"/>.
129+
// If this is set to function as a flag, then there is no simple user-provided way to circumvent the behavior.
130+
// </remarks>
131+
public static ForwardedOption<bool> InteractiveOption(bool acceptArgument = false) =>
128132
new("--interactive")
129133
{
130134
Description = CommonLocalizableStrings.CommandInteractiveOptionDescription,
131-
Arity = ArgumentArity.Zero,
135+
Arity = acceptArgument ? ArgumentArity.ZeroOrOne : ArgumentArity.Zero,
132136
// this default is called when no tokens/options are passed on the CLI args
133137
DefaultValueFactory = (ar) => IsCIEnvironmentOrRedirected()
134138
};
135139

136-
public static CliOption<bool> InteractiveMsBuildForwardOption = InteractiveOption().ForwardIfEnabled("-property:NuGetInteractive=true");
140+
public static CliOption<bool> InteractiveMsBuildForwardOption = InteractiveOption(acceptArgument: true).ForwardAsSingle(b => $"-property:NuGetInteractive={(b ? "true" : "false")}");
137141

138142
public static CliOption<bool> DisableBuildServersOption =
139143
new ForwardedOption<bool>("--disable-build-servers")

src/Cli/dotnet/commands/dotnet-run/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static RunCommand FromParseResult(ParseResult parseResult)
6161
noLaunchProfile: parseResult.HasOption(RunCommandParser.NoLaunchProfileOption),
6262
noLaunchProfileArguments: parseResult.HasOption(RunCommandParser.NoLaunchProfileArgumentsOption),
6363
noRestore: parseResult.HasOption(RunCommandParser.NoRestoreOption) || parseResult.HasOption(RunCommandParser.NoBuildOption),
64-
interactive: parseResult.HasOption(RunCommandParser.InteractiveOption),
64+
interactive: parseResult.GetValue(RunCommandParser.InteractiveOption),
6565
verbosity: parseResult.HasOption(CommonOptions.VerbosityOption) ? parseResult.GetValue(CommonOptions.VerbosityOption) : null,
6666
restoreArgs: [.. restoreArgs],
6767
args: [.. nonBinLogArgs],

test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dotnet reference add <PROJECT_PATH>... [options]
2424
Options:
2525
-f, --framework <FRAMEWORK> Add the reference only when targeting a specific framework.
2626
--interactive Allows the command to stop and wait for user input or action (for example to complete
27-
authentication).
27+
authentication). [default: True]
2828
--project The project file to operate on. If a file is not specified, the command will search the
2929
current directory for one.
3030
-?, -h, --help Show command line help.";

test/dotnet-remove-package.Tests/GivenDotnetRemovePackage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public class GivenDotnetRemovePackage : SdkTest
1212
Remove a NuGet package reference from the project.
1313
1414
Usage:
15-
dotnet remove <PROJECT> package <PACKAGE_NAME> [options]
15+
dotnet remove [<PROJECT>] package <PACKAGE_NAME>... [options]
1616
1717
Arguments:
1818
<PROJECT> The project file to operate on. If a file is not specified, the command will search the current directory for one. [default: {PathUtility.EnsureTrailingSlash(defaultVal)}]
1919
<PACKAGE_NAME> The package reference to remove.
2020
2121
Options:
22-
--interactive Allows the command to stop and wait for user input or action (for example to complete authentication).
22+
--interactive Allows the command to stop and wait for user input or action (for example to complete authentication). [default: True]
2323
-?, -h, --help Show command line help.";
2424

2525
private Func<string, string> RemoveCommandHelpText = (defaultVal) => $@"Description:

test/dotnet-run.Tests/GivenDotnetRunBuildsCsProj.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ public void ItRunsWithTheSpecifiedVerbosity()
693693
}
694694

695695
[Fact]
696-
public void ItDoesNotShowImportantLevelMessageByDefault()
696+
public void ItDoesShowImportantLevelMessageByDefault()
697697
{
698698
var testAppName = "MSBuildTestApp";
699699
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
@@ -704,6 +704,24 @@ public void ItDoesNotShowImportantLevelMessageByDefault()
704704
.WithWorkingDirectory(testInstance.Path)
705705
.Execute();
706706

707+
// this message should show because interactivity (and therefore nuget auth) is the default
708+
result.Should().Pass()
709+
.And.HaveStdOutContaining("Important text");
710+
}
711+
712+
[Fact]
713+
public void ItDoesNotShowImportantLevelMessageByDefaultWhenInteractivityDisabled()
714+
{
715+
var testAppName = "MSBuildTestApp";
716+
var testInstance = _testAssetsManager.CopyTestAsset(testAppName)
717+
.WithSource()
718+
.WithProjectChanges(ProjectModification.AddDisplayMessageBeforeRestoreToProject);
719+
720+
var result = new DotnetCommand(Log, "run", "--interactive", "false")
721+
.WithWorkingDirectory(testInstance.Path)
722+
.Execute();
723+
724+
// this message should show because interactivity (and therefore nuget auth) is the default
707725
result.Should().Pass()
708726
.And.NotHaveStdOutContaining("Important text");
709727
}
@@ -951,7 +969,7 @@ public void EnvOptionOverridesImplicitlySetVariables()
951969
var testInstance = _testAssetsManager.CopyTestAsset("TestAppWithLaunchSettings")
952970
.WithSource();
953971

954-
//
972+
//
955973
var dotnetLaunchProfile = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
956974
? "DOTNET_LAUNCH_profile"
957975
: "DOTNET_LAUNCH_PROFILE";

test/dotnet.Tests/GivenParserDirectives.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void ItCanInvokeDiagramDirective()
1818
.Should()
1919
.Pass()
2020
.And
21-
.HaveStdOutContaining("[ dotnet [ build [ -o <output> ] ] ]");
21+
.HaveStdOutContaining("[ dotnet [ build [ -o <output> ] *[ --interactive ] ] ]");
2222
}
2323

2424
[Fact]

test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public void AddReferenceHasInteractiveFlag()
3838
}
3939

4040
[Fact]
41-
public void AddReferenceDoesNotHaveInteractiveFlagByDefault()
41+
public void AddReferenceDoesHaveInteractiveFlagByDefault()
4242
{
4343
var result = Parser.Instance.Parse("dotnet add reference my.csproj");
4444

4545
result.GetValue<bool>(ReferenceAddCommandParser.InteractiveOption)
46-
.Should().BeFalse();
46+
.Should().BeTrue();
4747
}
4848

4949
[Fact]

test/dotnet.Tests/ParserTests/InstallToolParserTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void InstallToolParserCanParseNoCacheOption()
119119
var result =
120120
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --no-cache");
121121

122-
result.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand()).Should().BeEquivalentTo("--no-cache");
122+
result.GetValue(ToolCommandRestorePassThroughOptions.NoCacheOption).Should().BeTrue();
123123
}
124124

125125
[Fact]
@@ -128,7 +128,7 @@ public void InstallToolParserCanParseNoHttpCacheOption()
128128
var result =
129129
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --no-http-cache");
130130

131-
result.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand()).Should().BeEquivalentTo("--no-http-cache");
131+
result.GetValue(ToolCommandRestorePassThroughOptions.NoHttpCacheOption).Should().BeTrue();
132132
}
133133

134134
[Fact]
@@ -137,7 +137,7 @@ public void InstallToolParserCanParseIgnoreFailedSourcesOption()
137137
var result =
138138
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --ignore-failed-sources");
139139

140-
result.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand()).Should().ContainSingle("--ignore-failed-sources");
140+
result.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption).Should().BeTrue();
141141
}
142142

143143
[Fact]
@@ -146,7 +146,7 @@ public void InstallToolParserCanParseDisableParallelOption()
146146
var result =
147147
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --disable-parallel");
148148

149-
result.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand()).Should().ContainSingle("--disable-parallel");
149+
result.GetValue(ToolCommandRestorePassThroughOptions.DisableParallelOption).Should().BeTrue();
150150
}
151151

152152
[Fact]
@@ -155,7 +155,7 @@ public void InstallToolParserCanParseInteractiveRestoreOption()
155155
var result =
156156
Parser.Instance.Parse(@"dotnet tool install -g console.test.app --interactive");
157157

158-
result.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand()).Should().ContainSingle("--interactive");
158+
result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption).Should().BeTrue();
159159
}
160160
}
161161
}

test/dotnet.Tests/ParserTests/ToolRestoreParserTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void ToolRestoreParserCanParseNoCacheOption()
7878
var result =
7979
Parser.Instance.Parse(@"dotnet tool restore --no-cache");
8080

81-
result.OptionValuesToBeForwarded(ToolRestoreCommandParser.GetCommand()).Should().ContainSingle("--no-cache");
81+
result.GetValue(ToolCommandRestorePassThroughOptions.NoCacheOption).Should().BeTrue();
8282
}
8383

8484
[Fact]
@@ -87,7 +87,7 @@ public void ToolRestoreParserCanParseNoHttpCacheOption()
8787
var result =
8888
Parser.Instance.Parse(@"dotnet tool restore --no-http-cache");
8989

90-
result.OptionValuesToBeForwarded(ToolRestoreCommandParser.GetCommand()).Should().ContainSingle("--no-http-cache");
90+
result.GetValue(ToolCommandRestorePassThroughOptions.NoHttpCacheOption).Should().BeTrue();
9191
}
9292

9393
[Fact]
@@ -96,7 +96,7 @@ public void ToolRestoreParserCanParseIgnoreFailedSourcesOption()
9696
var result =
9797
Parser.Instance.Parse(@"dotnet tool restore --ignore-failed-sources");
9898

99-
result.OptionValuesToBeForwarded(ToolRestoreCommandParser.GetCommand()).Should().BeEquivalentTo("--ignore-failed-sources");
99+
result.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption).Should().BeTrue();
100100
}
101101

102102
[Fact]
@@ -105,7 +105,7 @@ public void ToolRestoreParserCanParseDisableParallelOption()
105105
var result =
106106
Parser.Instance.Parse(@"dotnet tool restore --disable-parallel");
107107

108-
result.OptionValuesToBeForwarded(ToolRestoreCommandParser.GetCommand()).Should().ContainSingle("--disable-parallel");
108+
result.GetValue(ToolCommandRestorePassThroughOptions.DisableParallelOption).Should().BeTrue();
109109
}
110110

111111
[Fact]
@@ -114,7 +114,7 @@ public void ToolRestoreParserCanParseInteractiveRestoreOption()
114114
var result =
115115
Parser.Instance.Parse(@"dotnet tool restore --interactive");
116116

117-
result.OptionValuesToBeForwarded(ToolRestoreCommandParser.GetCommand()).Should().ContainSingle("--interactive");
117+
result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption).Should().BeTrue();
118118
}
119119
}
120120
}

test/dotnet.Tests/ParserTests/UpdateToolParserTests.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public void UpdateToolParserCanParseMultipleSourceOption()
6969
$"--add-source {expectedSourceValue1} " +
7070
$"--add-source {expectedSourceValue2} console.test.app");
7171

72-
result.GetValue<string[]>(ToolInstallCommandParser.AddSourceOption)[0].Should().Be(expectedSourceValue1);
73-
result.GetValue<string[]>(ToolInstallCommandParser.AddSourceOption)[1].Should().Be(expectedSourceValue2);
72+
result.GetValue<string[]>(ToolInstallCommandParser.AddSourceOption).Should().BeEquivalentTo([expectedSourceValue1, expectedSourceValue2]);
7473
}
7574

7675
[Fact]
@@ -99,7 +98,7 @@ public void UpdateToolParserCanParseNoCacheOption()
9998
var result =
10099
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --no-cache");
101100

102-
result.OptionValuesToBeForwarded(ToolUpdateCommandParser.GetCommand()).Should().ContainSingle("--no-cache");
101+
result.GetValue(ToolCommandRestorePassThroughOptions.NoCacheOption).Should().Be(true);
103102
}
104103

105104
[Fact]
@@ -108,7 +107,7 @@ public void UpdateToolParserCanParseNoHttpCacheOption()
108107
var result =
109108
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --no-http-cache");
110109

111-
result.OptionValuesToBeForwarded(ToolUpdateCommandParser.GetCommand()).Should().BeEquivalentTo("--no-http-cache");
110+
result.GetValue(ToolCommandRestorePassThroughOptions.NoHttpCacheOption).Should().Be(true);
112111
}
113112

114113
[Fact]
@@ -117,7 +116,7 @@ public void UpdateToolParserCanParseIgnoreFailedSourcesOption()
117116
var result =
118117
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --ignore-failed-sources");
119118

120-
result.OptionValuesToBeForwarded(ToolUpdateCommandParser.GetCommand()).Should().ContainSingle("--ignore-failed-sources");
119+
result.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption).Should().Be(true);
121120
}
122121

123122
[Fact]
@@ -126,16 +125,15 @@ public void UpdateToolParserCanParseDisableParallelOption()
126125
var result =
127126
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --disable-parallel");
128127

129-
result.OptionValuesToBeForwarded(ToolUpdateCommandParser.GetCommand()).Should().ContainSingle("--disable-parallel");
128+
result.GetValue(ToolCommandRestorePassThroughOptions.DisableParallelOption).Should().Be(true);
130129
}
131130

132131
[Fact]
133132
public void UpdateToolParserCanParseInteractiveRestoreOption()
134133
{
135134
var result =
136135
Parser.Instance.Parse(@"dotnet tool update -g console.test.app --interactive");
137-
138-
result.OptionValuesToBeForwarded(ToolUpdateCommandParser.GetCommand()).Should().ContainSingle("--interactive");
136+
result.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption).Should().Be(true);
139137
}
140138

141139
[Fact]

0 commit comments

Comments
 (0)