-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathEnvironment.Exit.cs
56 lines (49 loc) · 2.01 KB
/
Environment.Exit.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System.IO;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
namespace System.Tests
{
public class Environment_Exit
{
public static object[][] ExitCodeValues = new object[][]
{
new object[] { 0 },
new object[] { 1 },
new object[] { 42 },
new object[] { -1 },
new object[] { -45 },
new object[] { 255 },
};
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
[MemberData(nameof(ExitCodeValues))]
public static void CheckExitCode(int expectedExitCode)
{
RemoteExecutor.Invoke(s => int.Parse(s), expectedExitCode.ToString(), new RemoteInvokeOptions { ExpectedExitCode = expectedExitCode }).Dispose();
}
[Theory]
[MemberData(nameof(ExitCodeValues))]
public static void ExitCode_Roundtrips(int exitCode)
{
Environment.ExitCode = exitCode;
Assert.Equal(exitCode, Environment.ExitCode);
Environment.ExitCode = 0; // in case the test host has a void returning Main
}
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
[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.dll";
using (Process p = Process.Start(RemoteExecutor.HostRunner, new[] { AppName, expectedExitCode.ToString(), mode.ToString() }))
{
p.WaitForExit();
Assert.Equal(expectedExitCode, p.ExitCode);
}
}
}
}