From aaa5defdf0655b41e4b61472c58b7c2fe5f4c718 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Wed, 15 Jun 2022 17:01:37 +0800 Subject: [PATCH] Add test using private reflection --- .../Interop/CommandLine/CommandLineTest.cs | 34 +++++++++++++++++++ .../CommandLine/CommandLineTest.csproj | 12 +++++++ 2 files changed, 46 insertions(+) create mode 100644 src/tests/Interop/CommandLine/CommandLineTest.cs create mode 100644 src/tests/Interop/CommandLine/CommandLineTest.csproj diff --git a/src/tests/Interop/CommandLine/CommandLineTest.cs b/src/tests/Interop/CommandLine/CommandLineTest.cs new file mode 100644 index 0000000000000..4c78b6e1c8787 --- /dev/null +++ b/src/tests/Interop/CommandLine/CommandLineTest.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; +using System.Reflection; +using TestLibrary; +using Xunit; + +namespace CommandLineTest +{ + class Program + { + int Main() + { + // Currently native command line is only implemented on CoreCLR Windows + if (!TestLibrary.Utilities.IsMonoRuntime && !TestLibrary.Utilities.IsNativeAot) + { + // Clear the command line args set for managed entry point + var field = typeof(Environment).GetField("s_commandLineArgs", BindingFlags.Static | BindingFlags.NonPublic); + Assert.NotNull(field); + field.SetValue(null, null); + + string[] args = Environment.GetCommandLineArgs(); + if (OperatingSystem.IsWindows()) + { + // The command line should be "corerun assemblyname.dll" for coreclr test + Assert.Equal(2, args.Length); + Assert.Equal("corerun", Path.GetFileNameWithoutExtension(args[0])); + Assert.Equal(typeof(Program).Assembly.GetName().Name, Path.GetFileNameWithoutExtension(args[1])); + } + } + + return 100; + } + } +} \ No newline at end of file diff --git a/src/tests/Interop/CommandLine/CommandLineTest.csproj b/src/tests/Interop/CommandLine/CommandLineTest.csproj new file mode 100644 index 0000000000000..df25278d2bd86 --- /dev/null +++ b/src/tests/Interop/CommandLine/CommandLineTest.csproj @@ -0,0 +1,12 @@ + + + Exe + true + + + + + + + +