Skip to content

Commit 4cadf9a

Browse files
authored
[wasm] Return int from console template (#72623)
Also update the template tests to test that it propagates correctly as an exit code from the node process.
1 parent 8d5c303 commit 4cadf9a

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/mono/wasm/templates/templates/console/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

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

6+
return 0;
7+
68
public partial class MyClass
79
{
810
[JSExport]

src/mono/wasm/templates/templates/console/app-support.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ try {
166166
if (runArgs.runtimeArgs.length > 0)
167167
INTERNAL.mono_wasm_set_runtime_options(runArgs.runtimeArgs);
168168

169-
Object.assign(App, { MONO, BINDING, IMPORTS, Module, runArgs });
169+
Object.assign(App, { MONO, INTERNAL, BINDING, IMPORTS, Module, runArgs });
170170

171171
try {
172172
if (App.main) {

src/mono/wasm/templates/templates/console/main.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ App.main = async function (applicationArguments) {
1212
const text = exports.MyClass.Greeting();
1313
console.log(text);
1414

15-
await App.MONO.mono_run_main("console.0.dll", applicationArguments);
15+
return await App.MONO.mono_run_main("console.0.dll", applicationArguments);
1616
}

src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33

44
using System;
55
using System.IO;
6-
using System.Text;
76
using System.Threading.Tasks;
8-
using System.Text.RegularExpressions;
97
using Xunit;
108
using Xunit.Abstractions;
119
using Xunit.Sdk;
1210

13-
1411
#nullable enable
1512

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

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

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

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

0 commit comments

Comments
 (0)