Skip to content

Commit

Permalink
Read only property WriteState=Unknown, disable tests on mono
Browse files Browse the repository at this point in the history
  • Loading branch information
buyaa-n committed Jul 10, 2021
1 parent bfd9f1b commit 86a287d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ public NullabilityInfo Create(PropertyInfo propertyInfo)

CheckNullabilityAttributes(nullability, getter.ReturnParameter.GetCustomAttributesData());
}
else
{
nullability.ReadState = NullabilityState.Unknown;
}

if (setter != null)
{
Expand All @@ -201,6 +205,10 @@ public NullabilityInfo Create(PropertyInfo propertyInfo)

CheckNullabilityAttributes(nullability, setter.GetParameters()[0].GetCustomAttributesData());
}
else
{
nullability.WriteState = NullabilityState.Unknown;
}

return nullability;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void EventTest(string eventName, NullabilityState readState, NullabilityS
public static IEnumerable<object[]> PropertyTestData()
{
yield return new object[] { "PropertyNullable", NullabilityState.Nullable, NullabilityState.Nullable, typeof(TypeWithNotNullContext) };
yield return new object[] { "PropertyNullableReadOnly", NullabilityState.Nullable, NullabilityState.Unknown, typeof(TypeWithNotNullContext) };
yield return new object[] { "PropertyUnknown", NullabilityState.Unknown, NullabilityState.Unknown, typeof(string) };
yield return new object[] { "PropertyNonNullable", NullabilityState.NotNull, NullabilityState.NotNull, typeof(NullabilityInfoContextTests) };
yield return new object[] { "PropertyValueTypeUnknown", NullabilityState.NotNull, NullabilityState.NotNull, typeof(short) };
Expand Down Expand Up @@ -100,7 +101,10 @@ public void PropertyTest(string propertyName, NullabilityState readState, Nullab
Assert.Equal(readState, nullability.ReadState);
Assert.Equal(readState, nullabilityContext.Create(property.GetMethod.ReturnParameter).ReadState);
Assert.Equal(writeState, nullability.WriteState);
Assert.Equal(writeState, nullabilityContext.Create(property.SetMethod.GetParameters()[0]).WriteState);
if (property.SetMethod != null)
{
Assert.Equal(writeState, nullabilityContext.Create(property.SetMethod.GetParameters()[0]).WriteState);
}
Assert.Equal(type, nullability.Type);
Assert.Empty(nullability.GenericTypeArguments);
Assert.Null(nullability.ElementType);
Expand All @@ -116,7 +120,7 @@ public static IEnumerable<object[]> ArrayPropertyTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(ArrayPropertyTestData))]
public void ArrayPropertyTest(string propertyName, NullabilityState elementState, NullabilityState propertyState)
{
Expand All @@ -138,7 +142,7 @@ public static IEnumerable<object[]> GenericArrayPropertyTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(GenericArrayPropertyTestData))]
public void GenericArrayPropertyTest(string propertyName, NullabilityState elementState, NullabilityState propertyState)
{
Expand All @@ -162,7 +166,7 @@ public static IEnumerable<object[]> JaggedArrayPropertyTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(JaggedArrayPropertyTestData))]
public void JaggedArrayPropertyTest(string propertyName, NullabilityState innermodtElementState, NullabilityState elementState, NullabilityState propertyState)
{
Expand All @@ -187,7 +191,7 @@ public static IEnumerable<object[]> TuplePropertyTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(TuplePropertyTestData))]
public void TuplePropertyTest(string propertyName, NullabilityState genericParam1, NullabilityState genericParam2, NullabilityState genericParam3, NullabilityState propertyState)
{
Expand All @@ -212,7 +216,7 @@ public static IEnumerable<object[]> GenericTuplePropertyTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(GenericTuplePropertyTestData))]
public void GenericTuplePropertyTest(string propertyName, NullabilityState genericParam1, NullabilityState genericParam2, NullabilityState genericParam3, NullabilityState propertyState)
{
Expand All @@ -238,7 +242,7 @@ public static IEnumerable<object[]> DictionaryPropertyTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(DictionaryPropertyTestData))]
public void DictionaryPropertyTest(string propertyName, NullabilityState keyState, NullabilityState valueElement, NullabilityState valueState, NullabilityState propertyState)
{
Expand All @@ -264,7 +268,7 @@ public static IEnumerable<object[]> GenericDictionaryPropertyTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(GenericDictionaryPropertyTestData))]
public void GenericDictionaryPropertyTest(string propertyName, NullabilityState keyState, NullabilityState valueElement, NullabilityState valueState, NullabilityState propertyState)
{
Expand Down Expand Up @@ -428,6 +432,7 @@ public void GenericStructConstraintTest(string fieldName, NullabilityState readS
}

[Fact]
[SkipOnMono("Nullability attributes trimmed on Mono")]
public void GenericListTest()
{
Type listNullable = typeof(List<string?>);
Expand All @@ -450,6 +455,7 @@ public void GenericListTest()
}

[Fact]
[SkipOnMono("Nullability attributes trimmed on Mono")]
public void GenericListAndDictionaryFieldTest()
{
Type typeNullable = typeof(GenericTest<string?>);
Expand Down Expand Up @@ -500,7 +506,7 @@ public static IEnumerable<object[]> MethodReturnParameterTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(MethodReturnParameterTestData))]
public void MethodReturnParameterTest(string methodName, NullabilityState elementState, NullabilityState readState)
{
Expand All @@ -525,7 +531,7 @@ public static IEnumerable<object[]> MethodGenericReturnParameterTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(MethodGenericReturnParameterTestData))]
public void MethodGenericReturnParameterTest(string methodName, NullabilityState readState, NullabilityState elementState)
{
Expand All @@ -548,7 +554,7 @@ public static IEnumerable<object[]> MethodParametersTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(MethodParametersTestData))]
public void MethodParametersTest(string methodName, NullabilityState stringState, NullabilityState dictKey, NullabilityState dictValueElement, NullabilityState dictValue, NullabilityState dictionaryState)
{
Expand All @@ -572,7 +578,7 @@ public static IEnumerable<object[]> MethodGenericParametersTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Disabling NullablePublicOnly feature not work for Mono tests")]
[MemberData(nameof(MethodGenericParametersTestData))]
public void MethodGenericParametersTest(string methodName, NullabilityState param1State, NullabilityState dictKey, NullabilityState dictValue, NullabilityState dictionaryState)
{
Expand All @@ -594,7 +600,7 @@ public static IEnumerable<object[]> StringTypeTestData()
}

[Theory]
[SkipOnMono("Temporarily disable on Mono")]
[SkipOnMono("Nullability attributes trimmed on Mono")]
[MemberData(nameof(StringTypeTestData))]
public void NullablePublicOnlyStringTypeTest(string methodName, NullabilityState param1State, NullabilityState param2State, NullabilityState param3State, Type[] types)
{
Expand All @@ -612,6 +618,7 @@ public void NullablePublicOnlyStringTypeTest(string methodName, NullabilityState
}

[Fact]
[SkipOnMono("Nullability attributes trimmed on Mono")]
public void NullablePublicOnlyOtherTypesTest()
{
Type type = typeof(Type);
Expand All @@ -628,7 +635,7 @@ public void NullablePublicOnlyOtherTypesTest()
PropertyInfo publicNullableProperty = type.GetProperty("DeclaringType", flags)!;
info = nullabilityContext.Create(publicNullableProperty);
Assert.Equal(NullabilityState.Nullable, info.ReadState);
Assert.Equal(NullabilityState.Nullable, info.WriteState);
Assert.Equal(NullabilityState.Unknown, info.WriteState);

PropertyInfo publicGetPrivateSetNullableProperty = typeof(FileSystemEntry).GetProperty("Directory", flags)!;
info = nullabilityContext.Create(publicGetPrivateSetNullableProperty);
Expand Down Expand Up @@ -828,6 +835,7 @@ public class TypeWithNotNullContext
public void MethodParametersUnknown(string s, IDictionary<Type, string[]> dict) { }
#nullable enable
public TypeWithNotNullContext? PropertyNullable { get; set; }
public TypeWithNotNullContext? PropertyNullableReadOnly { get; }
private NullabilityInfoContextTests PropertyNonNullable { get; set; } = null!;
internal float PropertyValueType { get; set; }
protected long? PropertyValueTypeNullable { get; set; }
Expand Down

0 comments on commit 86a287d

Please sign in to comment.