Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/mono/wasm/templates/templates/console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Console.WriteLine("Hello, Console!");

return 0;

public partial class MyClass
{
[JSExport]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ try {
if (runArgs.runtimeArgs.length > 0)
INTERNAL.mono_wasm_set_runtime_options(runArgs.runtimeArgs);

Object.assign(App, { MONO, BINDING, IMPORTS, Module, runArgs });
Object.assign(App, { MONO, INTERNAL, BINDING, IMPORTS, Module, runArgs });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed here: https://github.com/dotnet/runtime/blob/main/src/mono/wasm/templates/templates/console/app-support.mjs#L49-L66

Without it, we don't call mono_wasm_exit and the exit code would be always 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove that if (App && App.INTERNAL) { check anyway. It was useful in test-main.js, but not here, IIUC. Can we done in a follow up PR though.


try {
if (App.main) {
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/templates/templates/console/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ App.main = async function (applicationArguments) {
const text = exports.MyClass.Greeting();
console.log(text);

await App.MONO.mono_run_main("console.0.dll", applicationArguments);
return await App.MONO.mono_run_main("console.0.dll", applicationArguments);
}
8 changes: 3 additions & 5 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;


#nullable enable

namespace Wasm.Build.Tests
Expand All @@ -32,6 +29,7 @@ private void updateProgramCS() {
var path = Path.Combine(_projectDir!, "Program.cs");
string text = File.ReadAllText(path);
text = text.Replace(@"Console.WriteLine(""Hello, Console!"");", programText);
text = text.Replace("return 0;", "return 42;");
File.WriteAllText(path, text);
}

Expand Down Expand Up @@ -162,7 +160,7 @@ public void ConsoleBuildAndRun(string config)
AssertDotNetJsSymbols(Path.Combine(GetBinDir(config), "AppBundle"), fromRuntimePack: true);

(int exitCode, string output) = RunProcess(s_buildEnv.DotNet, _testOutput, args: $"run --no-build -c {config} x y z", workingDir: _projectDir);
Assert.Equal(0, exitCode);
Assert.Equal(42, exitCode);
Assert.Contains("args[0] = x", output);
Assert.Contains("args[1] = y", output);
Assert.Contains("args[2] = z", output);
Expand Down Expand Up @@ -209,7 +207,7 @@ public void ConsolePublishAndRun(string config, bool aot)
var res = new RunCommand(s_buildEnv, _testOutput, label: id)
.WithWorkingDirectory(_projectDir!)
.ExecuteWithCapturedOutput(runArgs)
.EnsureSuccessful();
.EnsureExitCode(42);

if (aot)
Assert.Contains($"AOT: image '{Path.GetFileNameWithoutExtension(projectFile)}' found", res.Output);
Expand Down