diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs index 46c8f2ce13287..e2406c873b986 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs @@ -46,11 +46,11 @@ public void InitBlazorWasmProjectDir(string id, string targetFramework = Default public string CreateBlazorWasmTemplateProject(string id) { InitBlazorWasmProjectDir(id); - new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) - .WithWorkingDirectory(_projectDir!) - .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("new blazorwasm") - .EnsureSuccessful(); + using DotNetCommand dotnetCommand = new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false); + CommandResult result = dotnetCommand.WithWorkingDirectory(_projectDir!) + .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) + .ExecuteWithCapturedOutput("new blazorwasm") + .EnsureSuccessful(); return Path.Combine(_projectDir!, $"{id}.csproj"); } @@ -195,12 +195,12 @@ public async Task BlazorRunTest(string runArgs, runOptions.ServerEnvironment?.ToList().ForEach( kv => s_buildEnv.EnvVars[kv.Key] = kv.Value); - using var runCommand = new RunCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(workingDirectory); + using RunCommand runCommand = new RunCommand(s_buildEnv, _testOutput); + ToolCommand cmd = runCommand.WithWorkingDirectory(workingDirectory); await using var runner = new BrowserRunner(_testOutput); var page = await runner.RunAsync( - runCommand, + cmd, runArgs, onConsoleMessage: OnConsoleMessage, onServerMessage: runOptions.OnServerMessage, diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/CleanTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/CleanTests.cs index db3c7da2243ac..122aa27496237 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/CleanTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/CleanTests.cs @@ -40,11 +40,11 @@ public void Blazor_BuildThenClean_NativeRelinking(string config) Assert.True(Directory.Exists(relinkDir), $"Could not find expected relink dir: {relinkDir}"); string logPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-clean.binlog"); - new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("build", "-t:Clean", $"-p:Configuration={config}", $"-bl:{logPath}") - .EnsureSuccessful(); + using ToolCommand cmd = new DotNetCommand(s_buildEnv, _testOutput) + .WithWorkingDirectory(_projectDir!); + cmd.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) + .ExecuteWithCapturedOutput("build", "-t:Clean", $"-p:Configuration={config}", $"-bl:{logPath}") + .EnsureSuccessful(); AssertEmptyOrNonExistentDirectory(relinkDir); } @@ -88,9 +88,9 @@ private void Blazor_BuildNativeNonNative_ThenCleanTest(string config, bool first Assert.True(Directory.Exists(relinkDir), $"Could not find expected relink dir: {relinkDir}"); string logPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}-clean.binlog"); - new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .WithEnvironmentVariable("NUGET_PACKAGES", _projectDir!) + using ToolCommand cmd = new DotNetCommand(s_buildEnv, _testOutput) + .WithWorkingDirectory(_projectDir!); + cmd.WithEnvironmentVariable("NUGET_PACKAGES", _projectDir!) .ExecuteWithCapturedOutput("build", "-t:Clean", $"-p:Configuration={config}", $"-bl:{logPath}") .EnsureSuccessful(); diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests2.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests2.cs index 23c002b454d91..00a47837523ce 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests2.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests2.cs @@ -59,11 +59,11 @@ private CommandResult PublishForRequiresWorkloadTest(string config, string extra extraItems: extraItems); string publishLogPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}.binlog"); - return new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("publish", - $"-bl:{publishLogPath}", - $"-p:Configuration={config}"); + using DotNetCommand cmd = new DotNetCommand(s_buildEnv, _testOutput); + return cmd.WithWorkingDirectory(_projectDir!) + .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) + .ExecuteWithCapturedOutput("publish", + $"-bl:{publishLogPath}", + $"-p:Configuration={config}"); } } diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs index 4d82356b10379..cdd0143cd2f08 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs @@ -99,17 +99,15 @@ public void BugRegression_60479_WithRazorClassLib() string wasmProjectDir = Path.Combine(_projectDir!, "wasm"); string wasmProjectFile = Path.Combine(wasmProjectDir, "wasm.csproj"); Directory.CreateDirectory(wasmProjectDir); - new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) - .WithWorkingDirectory(wasmProjectDir) - .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("new blazorwasm") - .EnsureSuccessful(); - + using DotNetCommand cmd = new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false); + cmd.WithWorkingDirectory(wasmProjectDir) + .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) + .ExecuteWithCapturedOutput("new blazorwasm") + .EnsureSuccessful(); string razorProjectDir = Path.Combine(_projectDir!, "RazorClassLibrary"); Directory.CreateDirectory(razorProjectDir); - new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) - .WithWorkingDirectory(razorProjectDir) + cmd.WithWorkingDirectory(razorProjectDir) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) .ExecuteWithCapturedOutput("new razorclasslib") .EnsureSuccessful(); diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 1f120016ef6aa..310819d9e90df 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -163,10 +163,10 @@ public BuildTestBase(ProjectProviderBase providerBase, ITestOutputHelper output, if (buildProjectOptions.Publish && buildProjectOptions.BuildOnlyAfterPublish) commandLineArgs.Append("-p:WasmBuildOnlyAfterPublish=true"); - var cmd = new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .WithEnvironmentVariables(buildProjectOptions.ExtraBuildEnvironmentVariables); + using ToolCommand cmd = new DotNetCommand(s_buildEnv, _testOutput) + .WithWorkingDirectory(_projectDir!); + cmd.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) + .WithEnvironmentVariables(buildProjectOptions.ExtraBuildEnvironmentVariables); if (UseWBTOverridePackTargets && s_buildEnv.IsWorkload) cmd.WithEnvironmentVariable("WBTOverrideRuntimePack", "true"); diff --git a/src/mono/wasm/Wasm.Build.Tests/Common/TestOutputWrapper.cs b/src/mono/wasm/Wasm.Build.Tests/Common/TestOutputWrapper.cs index 03bef6c6ccb33..8bf1992249f9f 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Common/TestOutputWrapper.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Common/TestOutputWrapper.cs @@ -18,7 +18,7 @@ public void WriteLine(string message) baseOutput.WriteLine(message); _outputBuffer.AppendLine(message); if (EnvironmentVariables.ShowBuildOutput) - Console.WriteLine(message); + Console.WriteLine(message); } public void WriteLine(string format, params object[] args) diff --git a/src/mono/wasm/Wasm.Build.Tests/Common/ToolCommand.cs b/src/mono/wasm/Wasm.Build.Tests/Common/ToolCommand.cs index c8289da17350d..da0c6a76f6db1 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Common/ToolCommand.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Common/ToolCommand.cs @@ -13,6 +13,7 @@ namespace Wasm.Build.Tests { public class ToolCommand : IDisposable { + private bool isDisposed = false; private string _label; protected ITestOutputHelper _testOutput; @@ -93,12 +94,15 @@ public virtual CommandResult ExecuteWithCapturedOutput(params string[] args) public virtual void Dispose() { + if (isDisposed) + return; if (CurrentProcess is not null && !CurrentProcess.HasExited) { CurrentProcess.Kill(entireProcessTree: true); CurrentProcess.Dispose(); CurrentProcess = null; } + isDisposed = true; } protected virtual string GetFullArgs(params string[] args) => string.Join(" ", args); @@ -109,7 +113,7 @@ private async Task ExecuteAsyncInternal(string executable, string CurrentProcess = CreateProcess(executable, args); DataReceivedEventHandler errorHandler = (s, e) => { - if (e.Data == null) + if (e.Data == null || isDisposed) return; string msg = $"[{_label}] {e.Data}"; @@ -120,7 +124,7 @@ private async Task ExecuteAsyncInternal(string executable, string DataReceivedEventHandler outputHandler = (s, e) => { - if (e.Data == null) + if (e.Data == null || isDisposed) return; string msg = $"[{_label}] {e.Data}"; diff --git a/src/mono/wasm/Wasm.Build.Tests/NonWasmTemplateBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/NonWasmTemplateBuildTests.cs index 4f86c39c3addf..f97e2ea7cc895 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NonWasmTemplateBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NonWasmTemplateBuildTests.cs @@ -108,22 +108,20 @@ private void NonWasmConsoleBuild(string config, File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.props"), ""); File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.targets"), directoryBuildTargets); - new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput("new console --no-restore") - .EnsureSuccessful(); + using DotNetCommand cmd = new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false); + cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput("new console --no-restore") + .EnsureSuccessful(); - new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput($"build -restore -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} {extraBuildArgs} -f {targetFramework}") - .EnsureSuccessful(); + cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput($"build -restore -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} {extraBuildArgs} -f {targetFramework}") + .EnsureSuccessful(); if (shouldRun) { - var result = new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput($"run -c {config} -f {targetFramework} --no-build") - .EnsureSuccessful(); + CommandResult result = cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput($"run -c {config} -f {targetFramework} --no-build") + .EnsureSuccessful(); Assert.Contains("Hello, World!", result.Output); } diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/NativeBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/NativeBuildTests.cs index 37f9b6aa46ca2..ff111d60207aa 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/NativeBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/NativeBuildTests.cs @@ -45,10 +45,10 @@ public void BuildWithUndefinedNativeSymbol(bool allowUndefined) File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), code); File.Copy(Path.Combine(BuildEnvironment.TestAssetsPath, "native-libs", "undefined-symbol.c"), Path.Combine(_projectDir!, "undefined_xyz.c")); - CommandResult result = new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("build", "-c Release"); + using DotNetCommand cmd = new DotNetCommand(s_buildEnv, _testOutput); + CommandResult result = cmd.WithWorkingDirectory(_projectDir!) + .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) + .ExecuteWithCapturedOutput("build", "-c Release"); if (allowUndefined) { @@ -83,17 +83,17 @@ public void ProjectWithDllImportsRequiringMarshalIlGen_ArrayTypeParameter(string Path.Combine(_projectDir!, "Program.cs"), overwrite: true); - CommandResult result = new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("build", $"-c {config} -bl"); + using DotNetCommand cmd = new DotNetCommand(s_buildEnv, _testOutput); + CommandResult result = cmd.WithWorkingDirectory(_projectDir!) + .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) + .ExecuteWithCapturedOutput("build", $"-c {config} -bl"); Assert.True(result.ExitCode == 0, "Expected build to succeed"); - CommandResult res = new RunCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config}") - .EnsureSuccessful(); + using RunCommand runCmd = new RunCommand(s_buildEnv, _testOutput); + CommandResult res = runCmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config}") + .EnsureSuccessful(); Assert.Contains("Hello, Console!", res.Output); Assert.Contains("Hello, World! Greetings from node version", res.Output); } diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs index b32b95debd879..af700f65afc98 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs @@ -193,10 +193,10 @@ public void ConsoleBuildThenPublish(string config) IsBrowserProject: false )); - CommandResult res = new RunCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config}") - .EnsureSuccessful(); + using RunCommand cmd = new RunCommand(s_buildEnv, _testOutput); + CommandResult res = cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config}") + .EnsureSuccessful(); Assert.Contains("Hello, Console!", res.Output); if (!_buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product)) @@ -262,10 +262,10 @@ private void ConsoleBuildAndRun(string config, bool relinking, string extraNewAr IsBrowserProject: false )); - CommandResult res = new RunCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config} x y z") - .EnsureExitCode(42); + using RunCommand cmd = new RunCommand(s_buildEnv, _testOutput); + CommandResult res = cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {config} x y z") + .EnsureExitCode(42); Assert.Contains("args[0] = x", res.Output); Assert.Contains("args[1] = y", res.Output); @@ -355,7 +355,7 @@ private Task ConsoleRunWithAndThenWithoutBuildAsync(string config, string extraP using var cmd = new RunCommand(s_buildEnv, _testOutput, label: id) .WithWorkingDirectory(workingDir) .WithEnvironmentVariables(s_buildEnv.EnvVars); - var res = cmd.ExecuteWithCapturedOutput(runArgs).EnsureExitCode(42); + CommandResult res = cmd.ExecuteWithCapturedOutput(runArgs).EnsureExitCode(42); Assert.Contains("args[0] = x", res.Output); Assert.Contains("args[1] = y", res.Output); @@ -370,7 +370,7 @@ private Task ConsoleRunWithAndThenWithoutBuildAsync(string config, string extraP runArgs += " x y z"; using var cmd = new RunCommand(s_buildEnv, _testOutput, label: id) .WithWorkingDirectory(workingDir); - var res = cmd.ExecuteWithCapturedOutput(runArgs).EnsureExitCode(42); + CommandResult res = cmd.ExecuteWithCapturedOutput(runArgs).EnsureExitCode(42); Assert.Contains("args[0] = x", res.Output); Assert.Contains("args[1] = y", res.Output); @@ -429,23 +429,26 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) UseCache: false, IsBrowserProject: false)); - new RunCommand(s_buildEnv, _testOutput, label: id) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput("--info") - .EnsureExitCode(0); + using (RunCommand cmd = new RunCommand(s_buildEnv, _testOutput, label: id)) + { + cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput("--info") + .EnsureExitCode(0); + } string runArgs = $"run --no-silent --no-build -c {config} -v diag"; runArgs += " x y z"; - var res = new RunCommand(s_buildEnv, _testOutput, label: id) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput(runArgs) - .EnsureExitCode(42); - - if (aot) - Assert.Contains($"AOT: image '{Path.GetFileNameWithoutExtension(projectFile)}' found", res.Output); - Assert.Contains("args[0] = x", res.Output); - Assert.Contains("args[1] = y", res.Output); - Assert.Contains("args[2] = z", res.Output); + using (RunCommand cmd = new RunCommand(s_buildEnv, _testOutput, label: id)) + { + CommandResult res = cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput(runArgs) + .EnsureExitCode(42); + if (aot) + Assert.Contains($"AOT: image '{Path.GetFileNameWithoutExtension(projectFile)}' found", res.Output); + Assert.Contains("args[0] = x", res.Output); + Assert.Contains("args[1] = y", res.Output); + Assert.Contains("args[2] = z", res.Output); + } } public static IEnumerable BrowserBuildAndRunTestData() @@ -474,10 +477,10 @@ public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework UpdateBrowserMainJs(targetFramework, runtimeAssetsRelativePath); - new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) - .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} {(runtimeAssetsRelativePath != DefaultRuntimeAssetsRelativePath ? "-p:WasmRuntimeAssetsLocation=" + runtimeAssetsRelativePath : "")}") - .EnsureSuccessful(); + using ToolCommand cmd = new DotNetCommand(s_buildEnv, _testOutput) + .WithWorkingDirectory(_projectDir!); + cmd.Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} {(runtimeAssetsRelativePath != DefaultRuntimeAssetsRelativePath ? "-p:WasmRuntimeAssetsLocation=" + runtimeAssetsRelativePath : "")}") + .EnsureSuccessful(); using var runCommand = new RunCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!); @@ -578,10 +581,10 @@ public void Test_WasmStripILAfterAOT(string stripILAfterAOT, bool expectILStripp AssertAppBundle: false)); string runArgs = $"run --no-silent --no-build -c {config}"; - var res = new RunCommand(s_buildEnv, _testOutput, label: id) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput(runArgs) - .EnsureExitCode(42); + using ToolCommand cmd = new RunCommand(s_buildEnv, _testOutput, label: id) + .WithWorkingDirectory(_projectDir!); + CommandResult res = cmd.ExecuteWithCapturedOutput(runArgs) + .EnsureExitCode(42); string frameworkDir = Path.Combine(projectDirectory, "bin", config, BuildTestBase.DefaultTargetFramework, "browser-wasm", "AppBundle", "_framework"); string objBuildDir = Path.Combine(projectDirectory, "obj", config, BuildTestBase.DefaultTargetFramework, "browser-wasm", "wasm", "for-publish"); diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/InterpPgoTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/InterpPgoTests.cs index c1606d9875722..9399ee93ec87c 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/InterpPgoTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/InterpPgoTests.cs @@ -44,7 +44,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config) // Create a single browser instance and single context to host all our pages. // If we don't do this, each page will have its own unique cache and the table won't be loaded. using var runCommand = new RunCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!); + .WithWorkingDirectory(_projectDir!); await using var runner = new BrowserRunner(_testOutput); var url = await runner.StartServerAndGetUrlAsync(runCommand, $"run --no-silent -c {config} --no-build --project \"{_projectDir!}\" --forward-console"); url = $"{url}?test=InterpPgoTest&iterationCount={iterationCount}"; diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs index 4ef606b784e45..ea1037e27872a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs @@ -77,8 +77,8 @@ public async Task LoadSatelliteAssemblyFromReference() // Build the library var libraryCsprojPath = Path.GetFullPath(Path.Combine(_projectDir!, "..", "ResourceLibrary")); - new DotNetCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(libraryCsprojPath) + using DotNetCommand cmd = new DotNetCommand(s_buildEnv, _testOutput); + CommandResult res = cmd.WithWorkingDirectory(libraryCsprojPath) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) .ExecuteWithCapturedOutput("build -c Release") .EnsureSuccessful(); diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/WasmAppBuilderDebugLevelTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/WasmAppBuilderDebugLevelTests.cs index 83809b3c2a9a3..bf8c3272960b3 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/WasmAppBuilderDebugLevelTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/WasmAppBuilderDebugLevelTests.cs @@ -35,8 +35,8 @@ protected override void SetupProject(string projectId) protected override Task RunForBuild(string configuration) { - CommandResult res = new RunCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) + using RunCommand cmd = new RunCommand(s_buildEnv, _testOutput); + CommandResult res = cmd.WithWorkingDirectory(_projectDir!) .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {configuration}"); return Task.FromResult(ProcessRunOutput(res)); @@ -61,8 +61,8 @@ protected override Task RunForPublish(string configuration) { // WasmAppBuilder does publish to the same folder as build (it overrides the output), // and thus using dotnet run work correctly for publish as well. - CommandResult res = new RunCommand(s_buildEnv, _testOutput) - .WithWorkingDirectory(_projectDir!) + using RunCommand cmd = new RunCommand(s_buildEnv, _testOutput); + CommandResult res = cmd.WithWorkingDirectory(_projectDir!) .ExecuteWithCapturedOutput($"run --no-silent --no-build -c {configuration}"); return Task.FromResult(ProcessRunOutput(res)); diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs index 032e195569e42..2906541e45aed 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs @@ -43,10 +43,10 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse if (addFrameworkArg) extraArgs += $" -f {DefaultTargetFramework}"; - new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) - .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput($"new {template} {extraArgs}") - .EnsureSuccessful(); + using DotNetCommand cmd = new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false); + CommandResult result = cmd.WithWorkingDirectory(_projectDir!) + .ExecuteWithCapturedOutput($"new {template} {extraArgs}") + .EnsureSuccessful(); string projectfile = Path.Combine(_projectDir!, $"{id}.csproj");