- Verifies that Environment.Exit(exitCode) passes the code through
- Verifies that Environment.ExitCode passes the code through even after Main exits, e.g. from a foreground thread
Both of these currently fail due to a coreclr issue.
Commit migrated from https://github.com/dotnet/corefx/commit/
08e22134ee3ff02afed5cad8809e23633aa019e2
[ActiveIssue("https://github.com/dotnet/coreclr/issues/6206")]
[Theory]
- [MemberData(nameof(ExitCodeValues))]
- public static void ExitCode_VoidMainAppReturnsSetValue(int expectedExitCode)
+ [InlineData(1)] // setting ExitCode and exiting Main
+ [InlineData(2)] // setting ExitCode both from Main and from an Unloading event handler.
+ [InlineData(3)] // using Exit(exitCode)
+ public static void ExitCode_VoidMainAppReturnsSetValue(int mode)
{
+ int expectedExitCode = 123;
+
const string AppName = "VoidMainWithExitCodeApp.exe";
var psi = new ProcessStartInfo();
if (File.Exists(HostRunner))
{
psi.FileName = HostRunner;
- psi.Arguments = AppName + " " + expectedExitCode.ToString();
+ psi.Arguments = $"{AppName} {expectedExitCode} {mode}";
}
else
{
psi.FileName = AppName;
- psi.Arguments = expectedExitCode.ToString();
+ psi.Arguments = $"{expectedExitCode} {mode}";
}
using (Process p = Process.Start(psi))
using System.Threading;
using System.Threading.Tasks;
using Xunit;
+using Xunit.NetCore.Extensions;
namespace System.Tests
{
Assert.True(Environment.WorkingSet > 0, "Expected positive WorkingSet value");
}
+ [Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // fail fast crashes the process
+ [OuterLoop]
[Fact]
public void FailFast_ExpectFailureExitCode()
{
using System;
using System.Reflection;
+using System.Threading;
namespace VoidMainWithExitCodeApp
{
{
static void Main(string[] args)
{
- int exitCode = args.Length > 0 ? int.Parse(args[0]) : 0;
- typeof(Environment).GetTypeInfo().GetDeclaredProperty("ExitCode").SetValue(null, exitCode);
- // Environment.ExitCode = exitCode; // TODO: Remove reflection when package updated with latest Environment exposing ExitCode
+ int exitCode = int.Parse(args[0]);
+ int mode = int.Parse(args[1]);
+
+ PropertyInfo set_ExitCode = typeof(Environment).GetTypeInfo().GetDeclaredProperty("ExitCode");
+ MethodInfo Exit = typeof(Environment).GetTypeInfo().GetDeclaredMethod("Exit");
+
+ switch (mode)
+ {
+ case 1: // set ExitCode and exit
+ set_ExitCode.SetValue(null, exitCode); // TODO: Environment.ExitCode = exitCode;
+ break;
+
+ case 2: // set ExitCode, exit, and then set ExitCode from another foreground thread
+ new Thread(() => // foreground thread
+ {
+ Thread.Sleep(1000); // time for Main to exit
+ set_ExitCode.SetValue(null, exitCode); // TODO: Environment.ExitCode = exitCode;
+ }).Start();
+ set_ExitCode.SetValue(null, exitCode - 1); // TODO: Environment.ExitCode = exitCode - 1;
+ break;
+
+ case 3: // call Environment.Exit(exitCode)
+ Exit.Invoke(null, new object[] { exitCode }); // TODO: Environment.Exit(exitCode);
+ break;
+ }
}
}
}
"Microsoft.NETCore.Platforms": "1.0.2-beta-24222-03",
"System.Runtime": "4.1.1-beta-24222-03",
"System.Runtime.Extensions": "4.1.1-beta-24222-03",
- "System.Reflection": "4.1.1-beta-24222-03"
+ "System.Reflection": "4.1.1-beta-24222-03",
+ "System.Threading.Thread": "4.0.1-beta-24222-03"
},
"frameworks": {
"netstandard1.3": {}
"System.Runtime.InteropServices.RuntimeInformation": "4.0.1-beta-24222-03",
"System.Text.RegularExpressions": "4.2.0-beta-24222-03",
"System.Threading": "4.0.12-beta-24222-03",
+ "System.Threading.Thread": "4.0.1-beta-24222-03",
"System.Threading.Tasks": "4.0.12-beta-24222-03",
"test-runtime": {
"target": "project",