Skip to content

Commit ec25e09

Browse files
committed
Use TestCommands for running apps
This will include both STDOUT and STDERR in the log, as well as launched process path and args
1 parent 4475e46 commit ec25e09

19 files changed

+43
-83
lines changed

src/Tests/Microsoft.NET.Build.Tests/AppHostTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public void It_builds_a_runnable_apphost_by_default(string targetFramework)
5252
"HelloWorld.runtimeconfig.json",
5353
});
5454

55-
Command.Create(Path.Combine(outputDirectory.FullName, hostExecutable), new string[] { })
56-
.EnvironmentVariable(
55+
56+
new RunExeCommand(Log, Path.Combine(outputDirectory.FullName, hostExecutable))
57+
.WithEnvironmentVariable(
5758
Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)",
5859
Path.GetDirectoryName(TestContext.Current.ToolsetUnderTest.DotNetHostPath))
59-
.CaptureStdOut()
6060
.Execute()
6161
.Should()
6262
.Pass()

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantAllResourcesInSatellite.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,25 @@ internal static void TestSatelliteResources(
7575
"en/AllResourcesInSatellite.resources.dll"
7676
};
7777

78-
Command command;
78+
TestCommand command;
7979
if (targetFramework == "net46")
8080
{
8181
outputFiles.Add("AllResourcesInSatellite.exe");
8282
outputFiles.Add("AllResourcesInSatellite.exe.config");
83-
command = Command.Create(Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.exe"), Array.Empty<string>());
83+
command = new RunExeCommand(log, Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.exe"));
8484
}
8585
else
8686
{
8787
outputFiles.Add("AllResourcesInSatellite.dll");
8888
outputFiles.Add("AllResourcesInSatellite.deps.json");
8989
outputFiles.Add("AllResourcesInSatellite.runtimeconfig.json");
9090
outputFiles.Add("AllResourcesInSatellite.runtimeconfig.dev.json");
91-
command = Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.dll") });
91+
command = new DotnetCommand(log, Path.Combine(outputDirectory.FullName, "AllResourcesInSatellite.dll"));
9292
}
9393

9494
outputDirectory.Should().OnlyHaveFiles(outputFiles);
9595

9696
command
97-
.CaptureStdOut()
9897
.Execute()
9998
.Should()
10099
.Pass()

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ public void It_handles_native_dependencies_and_platform_target(
108108
.Pass();
109109

110110
var exe = Path.Combine(buildCommand.GetOutputDirectory("net46").FullName, "DesktopMinusRid.exe");
111-
var runCommand = Command.Create(exe, Array.Empty<string>());
111+
var runCommand = new RunExeCommand(Log, exe);
112112
runCommand
113-
.CaptureStdOut()
114113
.Execute()
115114
.Should()
116115
.Pass()
@@ -189,9 +188,8 @@ public void It_appends_rid_to_outdir_correctly(string identifier, string rid, bo
189188
{
190189
var exe = Path.Combine(directory.FullName, "DesktopMinusRid.exe");
191190

192-
var runCommand = Command.Create(exe, Array.Empty<string>());
191+
var runCommand = new RunExeCommand(Log, exe);
193192
runCommand
194-
.CaptureStdOut()
195193
.Execute()
196194
.Should()
197195
.Pass()

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreApp.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ public static void Main()
366366

367367
string outputFolder = buildCommand.GetOutputDirectory(project.TargetFrameworks, runtimeIdentifier: runtimeIdentifier ?? "").FullName;
368368

369-
Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputFolder, project.Name + ".dll") })
370-
.CaptureStdOut()
369+
new DotnetCommand(Log, Path.Combine(outputFolder, project.Name + ".dll"))
371370
.Execute()
372371
.Should()
373372
.Pass()

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildASelfContainedApp.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public void It_builds_a_runnable_output(string targetFramework, bool dependencie
8181
$"apphost{Constants.ExeSuffix}",
8282
});
8383

84-
Command.Create(selfContainedExecutableFullPath, new string[] { })
85-
.CaptureStdOut()
84+
new RunExeCommand(Log, selfContainedExecutableFullPath)
8685
.Execute()
8786
.Should()
8887
.Pass()
@@ -149,8 +148,7 @@ public void It_succeeds_when_RuntimeIdentifier_and_PlatformTarget_mismatch_but_P
149148

150149
string selfContainedExecutableFullPath = Path.Combine(outputDirectory.FullName, selfContainedExecutable);
151150

152-
Command.Create(selfContainedExecutableFullPath, new string[] { })
153-
.CaptureStdOut()
151+
new RunExeCommand(Log, selfContainedExecutable)
154152
.Execute()
155153
.Should()
156154
.Pass()

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithLibrariesAndRid.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ public void It_builds_a_RID_specific_runnable_output()
5555

5656
string selfContainedExecutableFullPath = Path.Combine(outputDirectory.FullName, selfContainedExecutable);
5757

58-
Command.Create(selfContainedExecutableFullPath, new string[] { })
59-
.CaptureStdOut()
60-
.CaptureStdErr()
58+
new RunExeCommand(Log, selfContainedExecutableFullPath)
6159
.Execute()
6260
.Should()
6361
.Pass()
@@ -118,8 +116,7 @@ public void It_builds_a_framework_dependent_RID_specific_runnable_output()
118116
"LibraryWithRids.pdb",
119117
});
120118

121-
Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "App.dll") })
122-
.CaptureStdOut()
119+
new DotnetCommand(Log, Path.Combine(outputDirectory.FullName, "App.dll"))
123120
.Execute()
124121
.Should().Pass()
125122
.And.HaveStdOutContaining($"3.13.0 '{runtimeIdentifier}' 3.13.0 '{runtimeIdentifier}' Hello World");

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithLibrary.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ void VerifyAppBuilds(TestAsset testAsset)
7676
"TestLibrary.pdb",
7777
});
7878

79-
Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "TestApp.dll") })
80-
.CaptureStdOut()
79+
new DotnetCommand(Log, Path.Combine(outputDirectory.FullName, "TestApp.dll"))
8180
.Execute()
8281
.Should()
8382
.Pass()
@@ -121,8 +120,7 @@ public void It_generates_satellite_assemblies()
121120

122121
var outputDir = buildCommand.GetOutputDirectory("netcoreapp2.0");
123122

124-
var commandResult = Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputDir.FullName, "TestApp.dll") })
125-
.CaptureStdOut()
123+
var commandResult = new DotnetCommand(Log, Path.Combine(outputDir.FullName, "TestApp.dll"))
126124
.Execute();
127125

128126
commandResult.Should().Pass();

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithTransitiveProjectRefs.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ void VerifyAppBuilds(TestAsset testAsset)
6666
"AuxLibrary.pdb",
6767
});
6868

69-
Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] { Path.Combine(outputDirectory.FullName, "TestApp.dll") })
70-
.CaptureStdOut()
69+
new DotnetCommand(Log, Path.Combine(outputDirectory.FullName, "TestApp.dll"))
7170
.Execute()
7271
.Should()
7372
.Pass()

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithoutTransitiveProjectRefs.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void It_builds_the_project_successfully_when_RAR_finds_all_references()
4747
"5.pdb",
4848
});
4949

50-
Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] {Path.Combine(outputDirectory.FullName, "1.dll")})
51-
.CaptureStdOut()
50+
new DotnetCommand(Log, Path.Combine(outputDirectory.FullName, "1.dll"))
5251
.Execute()
5352
.Should()
5453
.Pass()
@@ -91,8 +90,7 @@ public void It_builds_the_project_successfully_when_RAR_does_not_find_all_refere
9190
"2.pdb",
9291
});
9392

94-
Command.Create(TestContext.Current.ToolsetUnderTest.DotNetHostPath, new[] {Path.Combine(outputDirectory.FullName, "1.dll")})
95-
.CaptureStdOut()
93+
new DotnetCommand(Log, Path.Combine(outputDirectory.FullName, "1.dll"))
9694
.Execute()
9795
.Should()
9896
.Pass()

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAppsWithFrameworkRefs.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ void VerifyProjectsBuild(TestAsset testAsset, params string[] buildArgs)
6363
var buildCommand = new BuildCommand(Log, appProjectDirectory);
6464
var outputDirectory = buildCommand.GetOutputDirectory("net451", runtimeIdentifier: "win7-x86");
6565

66-
Command.Create(Path.Combine(outputDirectory.FullName, "EntityFrameworkApp.exe"), Enumerable.Empty<string>())
67-
.CaptureStdOut()
66+
new RunExeCommand(Log, Path.Combine(outputDirectory.FullName, "EntityFrameworkApp.exe"))
6867
.Execute()
6968
.Should()
7069
.Pass()

0 commit comments

Comments
 (0)