Skip to content

Commit e5c4c0d

Browse files
committed
Detect runtime assertions in blazor runs
1 parent 8950797 commit e5c4c0d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,16 +932,20 @@ public void BlazorAddRazorButton(string buttonText, string customCode, string me
932932
File.WriteAllText(counterRazorPath, oldContent + additionalCode);
933933
}
934934

935+
// Keeping these methods with explicit Build/Publish in the name
936+
// so in the test code it is evident which is being run!
935937
public Task BlazorRunForBuildWithDotnetRun(string config, Func<IPage, Task>? test=null, string extraArgs="--no-build")
936938
=> BlazorRunTest($"run -c {config} {extraArgs}", _projectDir!, test);
937939

938-
939940
public Task BlazorRunForPublishWithWebServer(string config, Func<IPage, Task>? test=null, string extraArgs="")
940941
=> BlazorRunTest($"{s_xharnessRunnerCommand} wasm webserver --app=. --web-server-use-default-files {extraArgs}",
941942
Path.GetFullPath(Path.Combine(FindBlazorBinFrameworkDir(config, forPublish: true), "..")),
942943
test);
943944

944-
public async Task BlazorRunTest(string runArgs, string workingDirectory, Func<IPage, Task>? test=null)
945+
public async Task BlazorRunTest(string runArgs,
946+
string workingDirectory,
947+
Func<IPage, Task>? test = null,
948+
bool detectRuntimeFailures = true)
945949
{
946950
using var runCommand = new RunCommand(s_buildEnv, _testOutput)
947951
.WithWorkingDirectory(workingDirectory);
@@ -965,6 +969,12 @@ void OnConsoleMessage(IConsoleMessage msg)
965969
if (EnvironmentVariables.ShowBuildOutput)
966970
Console.WriteLine($"[{msg.Type}] {msg.Text}");
967971
_testOutput.WriteLine($"[{msg.Type}] {msg.Text}");
972+
973+
if (detectRuntimeFailures)
974+
{
975+
if (msg.Text.Contains("[MONO] * Assertion") || msg.Text.Contains("Error: [MONO] "))
976+
throw new XunitException($"Detected a runtime failure at line: {msg.Text}");
977+
}
968978
}
969979
}
970980

0 commit comments

Comments
 (0)