Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add tests for S.Reflection types #11981

Merged
merged 15 commits into from
Sep 29, 2016
Merged

Conversation

alexperovich
Copy link
Member

This change adds tests for the following System.Reflection types:

  • Module
  • Pointer
  • RuntimeReflectionExtensions
  • TypeDelegator
  • TypeInfo

Fixes #11766

This change adds tests for the following System.Reflection types:
- Module
- Pointer
- RuntimeReflectionExtensions
- TypeDelegator
- TypeInfo

Fixes #11766
@alexperovich
Copy link
Member Author

@davidwrighton PTAL

PropertyInfo property = typeof(PointerHolder).GetProperty("Property");
property.SetValue(obj, Pointer.Box((void*)value, typeof(char*)));
Assert.Equal(value, (int)obj.Property);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test that passing the parameter in as a boxed IntPtr does something. (I believe that's also supposed to work)

Copy link
Member

@davidwrighton davidwrighton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the Pointer portions of these changes and they look good to me.

@karelz karelz added area-System.Reflection test enhancement Improvements of test source code labels Sep 26, 2016
@alexperovich
Copy link
Member Author

@weshaggard @atsushikan

@ghost
Copy link

ghost commented Sep 26, 2016

corefx guideline: "var" can only be used in one of these:

var x = new Something()
var x = (Something)expr
var x = expr as Something

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like VS bumped a bunch of .csproj - please remove these from the commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.


namespace System.Reflection.Tests
{
public class TestType : Stream
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason why TestType derives from an api type?

I'm not sure where Stream stands in the api bringup effort but if we restore new members to that have to be overridden, you'll have to update this class and the various tests that depend on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted something with a large number of methods. I will change this to a custom type.

{
var fields = TypeInfo.DeclaredFields.ToList();
Assert.Equal(2, fields.Count);
Assert.Equal("StuffHappened", fields[0].Name);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're taking a dependency on the order in DeclaredFields returns fields - there's no guarantee of order.

This applies to all the Type apis that enumerate members on types. It's probably better to do an order-agnostic set compare.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change this.

{
Module.GetField(null);
});
Assert.Null(ex.InnerException);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be going overboard. Checking that it throws ArgumentNullException should be sufficient.

List<CustomAttributeData> customAttributes = Module.CustomAttributes.ToList();
Assert.Equal(2, customAttributes.Count);
var fooAttribute = customAttributes[0];
Assert.Equal(typeof(FooAttribute), fooAttribute.AttributeType);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to preview

Another ordering dependency


public class TypeInfoTests
{
public TypeInfo TypeInfo => typeof(TestType).GetTypeInfo();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming this property "TypeInfo" is confusing. Might be preferable just to inline so that people can more easily read the tests in isolation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill rename it.

@alexperovich
Copy link
Member Author

@dotnet-bot test Innerloop CentOS7.1 Debug Build and Test please (Jenkins Client issue)

[Fact]
public void GetFields()
{
List<FieldInfo> fields = TestModule.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).ToList();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be sorted by name for test to work reliably.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add that

@ghost
Copy link

ghost commented Sep 29, 2016

LGTM.

@alexperovich
Copy link
Member Author

@dotnet-bot test Innerloop CentOS7.1 Release Build and Test please (Build Timeout)

@alexperovich alexperovich merged commit f6f97c2 into dotnet:master Sep 29, 2016
@alexperovich alexperovich deleted the reflectionTests branch September 29, 2016 23:26
@karelz karelz modified the milestone: 1.2.0 Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Add tests for S.Reflection types

This change adds tests for the following System.Reflection types:
- Module
- Pointer
- RuntimeReflectionExtensions
- TypeDelegator
- TypeInfo

Fixes dotnet/corefx#11766

* Use checked in IL binary.

* Add tests passing IntPtr to reflection apis

* Ignore case in Module.Name check.

* Ignore ordering in GetRuntimeFields()

* Fixup Project Files

* Remove resharper file that found its way in.

* Remove some ordering dependencies

* s/var/{type}

* Rename TypeInfo property to TestTypeInfo

* Sort fields by name for consistency


Commit migrated from dotnet/corefx@f6f97c2
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Reflection test enhancement Improvements of test source code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants