Skip to content

Commit

Permalink
[wasm] WBT - add some debug bits to collect information on a rare
Browse files Browse the repository at this point in the history
.. failure, where `Program.cs` fails to compile. In such a case make the
project contents available in the logs.

Issue: dotnet#86533
  • Loading branch information
radical committed Jul 27, 2023
1 parent 08acbb7 commit fc992f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
29 changes: 20 additions & 9 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,26 @@ public string CreateBlazorWasmTemplateProject(string id)
bool publish = false,
bool setWasmDevel = true,
params string[] extraArgs)
=> BuildProjectWithoutAssert(
id,
config,
new BuildProjectOptions(CreateProject: false, UseCache: false, Publish: publish),
extraArgs.Concat(new[]
{
"-p:BlazorEnableCompression=false",
setWasmDevel ? "-p:_WasmDevel=true" : string.Empty
}).ToArray());
{
try
{
return BuildProjectWithoutAssert(
id,
config,
new BuildProjectOptions(CreateProject: false, UseCache: false, Publish: publish),
extraArgs.Concat(new[]
{
"-p:BlazorEnableCompression=false",
setWasmDevel ? "-p:_WasmDevel=true" : string.Empty
}).ToArray());
}
catch (XunitException xe)
{
if (xe.Message.Contains("error CS1001: Identifier expected"))
Utils.DirectoryCopy(_projectDir!, Path.Combine(s_buildEnv.LogRootPath, id), testOutput: _testOutput);
throw;
}
}

public void AssertBundle(string buildOutput, BlazorBuildOptions blazorBuildOptions)
{
Expand Down
13 changes: 8 additions & 5 deletions src/mono/wasm/Wasm.Build.Tests/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Xunit;
using Xunit.Abstractions;

internal static class Utils
{
public static void DirectoryCopy(string sourceDirName, string destDirName, Func<string, bool>? predicate=null, bool copySubDirs=true, bool silent=false)
public static void DirectoryCopy(string sourceDirName, string destDirName, Func<string, bool>? predicate=null, bool copySubDirs=true, bool silent=false, ITestOutputHelper? testOutput = null)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
Expand All @@ -33,14 +36,14 @@ public static void DirectoryCopy(string sourceDirName, string destDirName, Func<
string fullPath = file.ToString();
if (predicate != null && !predicate(fullPath))
{
// if (!silent)
// e(MessageImportance.Low, $"Skipping {fullPath}");
if (!silent)
testOutput?.WriteLine($"Skipping {fullPath}");
continue;
}

string tempPath = Path.Combine(destDirName, file.Name);
// if (!silent)
// Logger?.LogMessage(MessageImportance.Low, $"Copying {fullPath} to {tempPath}");
if (!silent)
testOutput?.WriteLine($"Copying {fullPath} to {tempPath}");
file.CopyTo(tempPath, false);
}

Expand Down

0 comments on commit fc992f4

Please sign in to comment.