Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
WBT.
  • Loading branch information
maraf committed Aug 19, 2022
commit 663ae1f6d602de687c869c0f298cd0c76d792265
20 changes: 17 additions & 3 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/WasmBuildAppTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public static int Main()
}
}", buildArgs, host, id);

[Theory]
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ false, RunHost.All })]
public void ExceptionFromMain(BuildArgs buildArgs, RunHost host, string id)
=> TestMain("main_exception", """
using System;
using System.Threading.Tasks;

public class TestClass {
public static int Main() => throw new Exception("MessageFromMyException");
}
""", buildArgs, host, id, expectedExitCode: 71, expectedOutput: "Error: MessageFromMyException");

private static string s_bug49588_ProgramCS = @"
using System;
public class TestClass {
Expand Down Expand Up @@ -165,7 +177,9 @@ protected void TestMain(string projectName,
RunHost host,
string id,
string extraProperties = "",
bool? dotnetWasmFromRuntimePack = null)
bool? dotnetWasmFromRuntimePack = null,
int expectedExitCode = 42,
string expectedOutput = "Hello, World!")
{
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs, extraProperties);
Expand All @@ -179,8 +193,8 @@ protected void TestMain(string projectName,
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), programText),
DotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack));

RunAndTestWasmApp(buildArgs, expectedExitCode: 42,
test: output => Assert.Contains("Hello, World!", output), host: host, id: id);
RunAndTestWasmApp(buildArgs, expectedExitCode: expectedExitCode,
test: output => Assert.Contains(expectedOutput, output), host: host, id: id);
}
}
}