Adding dotnet run tests for passing arguments to the app.
This commit is contained in:
parent
dd327b52a5
commit
5d2da26e74
3 changed files with 90 additions and 14 deletions
|
@ -103,6 +103,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-dependency-tool-invo
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Compiler.Common.Tests", "test\Microsoft.DotNet.Compiler.Common.Tests\Microsoft.DotNet.Compiler.Common.Tests.xproj", "{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Compiler.Common.Tests", "test\Microsoft.DotNet.Compiler.Common.Tests\Microsoft.DotNet.Compiler.Common.Tests.xproj", "{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-run.Tests", "test\dotnet-run.Tests\dotnet-run.Tests.xproj", "{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}"
|
||||||
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Performance", "test\Performance\Performance.xproj", "{6A3095FF-A7C5-4300-85A9-C025C384401D}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Performance", "test\Performance\Performance.xproj", "{6A3095FF-A7C5-4300-85A9-C025C384401D}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
@ -725,6 +727,22 @@ Global
|
||||||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||||
{6A3095FF-A7C5-4300-85A9-C025C384401D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{6A3095FF-A7C5-4300-85A9-C025C384401D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{6A3095FF-A7C5-4300-85A9-C025C384401D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6A3095FF-A7C5-4300-85A9-C025C384401D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6A3095FF-A7C5-4300-85A9-C025C384401D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
{6A3095FF-A7C5-4300-85A9-C025C384401D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
@ -789,6 +807,7 @@ Global
|
||||||
{1AB5B24B-B317-4142-A5D1-A6E84F15BA34} = {ADA7052B-884B-4776-8B8D-D04191D0AA70}
|
{1AB5B24B-B317-4142-A5D1-A6E84F15BA34} = {ADA7052B-884B-4776-8B8D-D04191D0AA70}
|
||||||
{C26A48BB-193F-450C-AB09-4D3324C78188} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
|
{C26A48BB-193F-450C-AB09-4D3324C78188} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
|
||||||
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||||
|
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||||
{6A3095FF-A7C5-4300-85A9-C025C384401D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
{6A3095FF-A7C5-4300-85A9-C025C384401D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
{
|
{
|
||||||
|
@ -20,22 +21,18 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
|
|
||||||
private string ConfigurationOption => string.IsNullOrEmpty(_configuration) ? "" : $"-c {_configuration}";
|
private string ConfigurationOption => string.IsNullOrEmpty(_configuration) ? "" : $"-c {_configuration}";
|
||||||
|
|
||||||
private string PreserveTemporaryOption => _preserveTemporary ? $"-t \"{_projectPath}\"" : "";
|
|
||||||
|
|
||||||
private string AppArgsArgument => _appArgs;
|
private string AppArgsArgument => _appArgs;
|
||||||
|
|
||||||
public RunCommand(
|
public RunCommand(
|
||||||
string projectPath,
|
string projectPath,
|
||||||
string framework = "",
|
string framework = "",
|
||||||
string configuration = "",
|
string configuration = "",
|
||||||
bool preserveTemporary = false,
|
|
||||||
string appArgs = "")
|
string appArgs = "")
|
||||||
: base("dotnet")
|
: base("dotnet")
|
||||||
{
|
{
|
||||||
_projectPath = projectPath;
|
_projectPath = projectPath;
|
||||||
_framework = framework;
|
_framework = framework;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_preserveTemporary = preserveTemporary;
|
|
||||||
_appArgs = appArgs;
|
_appArgs = appArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +54,17 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
return base.ExecuteAsync(args);
|
return base.ExecuteAsync(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string BuildArgs() => $"{ProjectPathOption} {FrameworkOption} {ConfigurationOption} {PreserveTemporaryOption} {AppArgsArgument}";
|
private string BuildArgs()
|
||||||
|
{
|
||||||
|
return string.Join(" ",
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
ProjectPathOption,
|
||||||
|
FrameworkOption,
|
||||||
|
ConfigurationOption,
|
||||||
|
AppArgsArgument,
|
||||||
|
}
|
||||||
|
.Where(s => !string.IsNullOrEmpty(s)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,18 +82,67 @@ namespace Microsoft.DotNet.Tools.Run.Tests
|
||||||
.HaveStdOutContaining("Hélló Wórld!");
|
.HaveStdOutContaining("Hélló Wórld!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
[Fact]
|
||||||
|
public void ItPassesArgumentsToTheApp()
|
||||||
{
|
{
|
||||||
// copy all the files to temp dir
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithArgs")
|
||||||
foreach (var file in Directory.EnumerateFiles(projectDir))
|
.WithLockFiles()
|
||||||
{
|
.WithBuildArtifacts();
|
||||||
tempDir.CopyFile(file);
|
new RunCommand(instance.TestRoot)
|
||||||
}
|
.ExecuteWithCapturedOutput("one --two -three")
|
||||||
|
.Should()
|
||||||
|
.Pass()
|
||||||
|
.And
|
||||||
|
.HaveStdOutContaining(
|
||||||
|
JoinWithNewlines(
|
||||||
|
"Hello World!",
|
||||||
|
"I was passed 3 args:",
|
||||||
|
"arg: [one]",
|
||||||
|
"arg: [--two]",
|
||||||
|
"arg: [-three]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetProjectPath(TempDirectory projectDir)
|
[Fact]
|
||||||
|
public void ItPassesAllArgsAfterUnexpectedArg()
|
||||||
{
|
{
|
||||||
return Path.Combine(projectDir.Path, "project.json");
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithArgs")
|
||||||
|
.WithLockFiles()
|
||||||
|
.WithBuildArtifacts();
|
||||||
|
new RunCommand(instance.TestRoot)
|
||||||
|
.ExecuteWithCapturedOutput("Hello -f")
|
||||||
|
.Should()
|
||||||
|
.Pass()
|
||||||
|
.And
|
||||||
|
.HaveStdOutContaining(
|
||||||
|
JoinWithNewlines(
|
||||||
|
"Hello World!",
|
||||||
|
"I was passed 2 args:",
|
||||||
|
"arg: [Hello]",
|
||||||
|
"arg: [-f]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItHandlesArgSeparatorCorrectly()
|
||||||
|
{
|
||||||
|
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithArgs")
|
||||||
|
.WithLockFiles()
|
||||||
|
.WithBuildArtifacts();
|
||||||
|
new RunCommand(instance.TestRoot)
|
||||||
|
.ExecuteWithCapturedOutput("-- one two")
|
||||||
|
.Should()
|
||||||
|
.Pass()
|
||||||
|
.And
|
||||||
|
.HaveStdOutContaining(
|
||||||
|
JoinWithNewlines(
|
||||||
|
"Hello World!",
|
||||||
|
"I was passed 2 args:",
|
||||||
|
"arg: [one]",
|
||||||
|
"arg: [two]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string JoinWithNewlines(params string[] values)
|
||||||
|
{
|
||||||
|
return string.Join(Environment.NewLine, values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue