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 + + + + + + + +