Skip to content

Commit

Permalink
[wasm] Return int from console template (#72623)
Browse files Browse the repository at this point in the history
Also update the template tests to test that it propagates correctly as
an exit code from the node process.
  • Loading branch information
radekdoulik authored Jul 22, 2022
1 parent 8d5c303 commit 4cadf9a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
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
2 changes: 1 addition & 1 deletion src/mono/wasm/templates/templates/console/app-support.mjs
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 });

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

0 comments on commit 4cadf9a

Please sign in to comment.