Skip to content

Commit

Permalink
Add test using private reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Jun 15, 2022
1 parent e36103c commit aaa5def
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/tests/Interop/CommandLine/CommandLineTest.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
12 changes: 12 additions & 0 deletions src/tests/Interop/CommandLine/CommandLineTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="CommandLineTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>

0 comments on commit aaa5def

Please sign in to comment.