From 16371274b4b43751035f22f13b094743dd5fa728 Mon Sep 17 00:00:00 2001 From: psfinaki Date: Wed, 19 Jun 2024 14:21:53 +0200 Subject: [PATCH 1/4] Fix an exception check in the tests --- .../FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs | 2 +- tests/FSharp.Core.UnitTests/LibraryTestFx.fs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs index 9af581dca52..c3c80e9bf9c 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs @@ -18,7 +18,7 @@ module OperatorsModuleDynamic = let _ = f () sprintf "Expected %O exception, got no exception" typeof<'a> |> Assert.Fail with - | :? 'a -> () + | :? 'a as e when e.GetType() = typeof<'a> -> () | :? Reflection.TargetInvocationException as r when (r.InnerException :? 'a) -> () | e -> sprintf "Expected %O or TargetInvocationException containing it, got: %O" typeof<'a> e |> Assert.Fail let CheckThrowsOverflowException = CheckThrowsExn diff --git a/tests/FSharp.Core.UnitTests/LibraryTestFx.fs b/tests/FSharp.Core.UnitTests/LibraryTestFx.fs index 6137eb79d75..63e8a33d2ec 100644 --- a/tests/FSharp.Core.UnitTests/LibraryTestFx.fs +++ b/tests/FSharp.Core.UnitTests/LibraryTestFx.fs @@ -18,7 +18,7 @@ let CheckThrowsExn<'a when 'a :> exn> (f : unit -> unit) = let _ = f () sprintf "Expected %O exception, got no exception" typeof<'a> |> Assert.Fail with - | :? 'a -> () + | :? 'a as e when e.GetType() = typeof<'a> -> () | e -> sprintf "Expected %O exception, got: %O" typeof<'a> e |> Assert.Fail let private CheckThrowsExn2<'a when 'a :> exn> s (f : unit -> unit) = From 18e1e7ab719dbbbcbdb82acfe10414743c7f037a Mon Sep 17 00:00:00 2001 From: psfinaki Date: Wed, 19 Jun 2024 16:31:20 +0200 Subject: [PATCH 2/4] Fix tests --- .../ArrayModule.fs | 6 +- .../Microsoft.FSharp.Collections/SeqModule.fs | 2 +- .../FSharpReflection.fs | 56 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs index 0f9931e0e6a..aa112e0b98b 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs @@ -372,9 +372,9 @@ type ArrayModule() = CheckThrowsArgumentNullException (fun () -> Array.blit nullArr 1 strDes 2 3 |> ignore) // bounds check - CheckThrowsArgumentException (fun () -> Array.blit intSrc -1 intDes 1 3 |> ignore) - CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes -1 3 |> ignore) - CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 1 -3 |> ignore) + CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc -1 intDes 1 3 |> ignore) + CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc 1 intDes -1 3 |> ignore) + CheckThrowsArgumentOutOfRangeException (fun () -> Array.blit intSrc 1 intDes 1 -3 |> ignore) CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 1 300 |> ignore) CheckThrowsArgumentException (fun () -> Array.blit intSrc 1 intDes 5 8 |> ignore) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs index 749203601fe..d80f5404a53 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs @@ -141,7 +141,7 @@ type SeqModule() = Assert.AreEqual(null, Seq.head <| Seq.replicate 1 null) Assert.AreEqual(["1";"1"],Seq.replicate 2 "1" |> Seq.toList) - CheckThrowsArgumentException (fun () -> Seq.replicate -1 null |> ignore) + CheckThrowsArgumentOutOfRangeException (fun () -> Seq.replicate -1 null |> ignore) [] diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs index 987b779df17..be9894bc22e 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Reflection/FSharpReflection.fs @@ -221,13 +221,13 @@ type FSharpValueTests() = // invalid type CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(1) |> ignore) - CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields( () ) |> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetExceptionFields( () ) |> ignore) // System Exception CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(new System.Exception("ex message")) |> ignore) // null - CheckThrowsArgumentException(fun () -> FSharpValue.GetExceptionFields(null) |> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetExceptionFields(null) |> ignore) [] member _.GetRecordField() = @@ -241,15 +241,15 @@ type FSharpValueTests() = Assert.AreEqual((FSharpValue.GetRecordField(genericRecordType1, propertyinfo2)), 1) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore) - CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfo1) |> ignore) // invalid property info - let propertyinfoint = (typeof).GetProperty("fieldstring") - CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore) + let propertyinfoint = (typeof).GetProperty("fieldstring") // null + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore) [] member _.GetStructRecordField() = @@ -259,15 +259,15 @@ type FSharpValueTests() = Assert.AreEqual((FSharpValue.GetRecordField(structRecord1, propertyinfo1)), "field1") // null value - CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore) - CheckThrowsArgumentException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField(null, propertyinfo1)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.GetRecordField( () , propertyinfo1)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfo1) |> ignore) // invalid property info - let propertyinfoint = (typeof).GetProperty("fieldstring") - CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore) + let propertyinfoint = (typeof).GetProperty("fieldstring") // null + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordField("invalid", propertyinfoint) |> ignore) [] member _.GetRecordFields() = @@ -280,8 +280,8 @@ type FSharpValueTests() = Assert.AreEqual((FSharpValue.GetRecordFields(genericRecordType1)).[0], "field1") // null value - CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields(null)|> ignore) - CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields( () )|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordFields(null)|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetRecordFields( () )|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.GetRecordFields("invalid") |> ignore) @@ -300,8 +300,8 @@ type FSharpValueTests() = Assert.AreEqual( FSharpValue.GetTupleField(tuple2, 1), "tuple2") // null value - CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField(null, 3)|> ignore) - CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField( () , 3)|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleField(null, 3)|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleField( () , 3)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleField("Invalid", 3)|> ignore) @@ -329,8 +329,8 @@ type FSharpValueTests() = Assert.AreEqual( (FSharpValue.GetTupleFields(tuple2)).[1], "tuple2") // null value - CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields(null)|> ignore) - CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields( () )|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleFields(null)|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.GetTupleFields( () )|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.GetTupleFields("Invalid")|> ignore) @@ -393,7 +393,7 @@ type FSharpValueTests() = Assert.AreEqual(FSharpValue.GetRecordFields(makeRecordGeneric).[0], "field1") // null value - CheckThrowsArgumentException(fun () ->FSharpValue.MakeRecord(null, null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.MakeRecord(null, null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.MakeRecord(typeof>, [| box 1; box("invalid param"); box("invalid param") |])|> ignore) @@ -471,7 +471,7 @@ type FSharpValueTests() = Assert.AreEqual( (unbox>(resultGenericRecordType)).field1, genericRecordType1.field1) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordConstructor(null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordConstructor(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordConstructor(typeof>) |> ignore) @@ -495,7 +495,7 @@ type FSharpValueTests() = Assert.AreEqual(genericrecordCtorInfo.ReflectedType, typeof>) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordConstructorInfo(null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordConstructorInfo(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordConstructorInfo(typeof>) |> ignore) @@ -517,7 +517,7 @@ type FSharpValueTests() = Assert.AreEqual(recordFieldReader(genericRecordType1), box("field1")) // null value - CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordFieldReader(null)|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.PreComputeRecordFieldReader(null)|> ignore) [] member _.PreComputeStructRecordFieldReader() = @@ -536,7 +536,7 @@ type FSharpValueTests() = Assert.AreEqual( (genericrecordReader(genericRecordType1)).[0], "field1") // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeRecordReader(null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeRecordReader(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeRecordReader(typeof>) |> ignore) @@ -566,7 +566,7 @@ type FSharpValueTests() = Assert.AreEqual( tupleNestedCtor([| box 1; box(2, "tuple") |] ), box(tuple3)) // null value - CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleConstructor(null)|> ignore) + CheckThrowsArgumentNullException(fun () -> FSharpValue.PreComputeTupleConstructor(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleConstructor(typeof>) |> ignore) @@ -604,7 +604,7 @@ type FSharpValueTests() = Assert.AreEqual(nestedTupleCtorInfo.ReflectedType, typeof>>) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTupleConstructorInfo(null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTupleConstructorInfo(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleConstructorInfo(typeof) |> ignore) @@ -634,7 +634,7 @@ type FSharpValueTests() = Assert.AreEqual(tupleNestedPropInfo.PropertyType, typeof>) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTuplePropertyInfo(null, 0)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTuplePropertyInfo(null, 0)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTuplePropertyInfo(typeof, 0) |> ignore) @@ -670,7 +670,7 @@ type FSharpValueTests() = Assert.AreEqual (longTupleReader longTuple, [| box ("yup", 1s); box 2; box 3; box 4; box 5; box 6; box 7; box 8; box 9; box 10; box 11; box (Some 12); box 13; box "nope"; box (struct (15, 16)); box 17; box 18; box (ValueSome 19) |]) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeTupleReader(null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeTupleReader(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeTupleReader(typeof) |> ignore) @@ -813,7 +813,7 @@ type FSharpValueTests() = Assert.AreEqual(discUnionMemberInfo.ReflectedType, typeof>) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeUnionTagMemberInfo(null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeUnionTagMemberInfo(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeUnionTagMemberInfo(typeof) |> ignore) @@ -851,7 +851,7 @@ type FSharpValueTests() = Assert.AreEqual(voptionTagReader(box(voptionNone)), 0) // null value - CheckThrowsArgumentException(fun () ->FSharpValue.PreComputeUnionTagReader(null)|> ignore) + CheckThrowsArgumentNullException(fun () ->FSharpValue.PreComputeUnionTagReader(null)|> ignore) // invalid value CheckThrowsArgumentException(fun () -> FSharpValue.PreComputeUnionTagReader(typeof) |> ignore) @@ -1179,7 +1179,7 @@ type FSharpTypeTests() = // invalid cases CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( [|null;null|]) |> ignore ) - CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( null) |> ignore ) + CheckThrowsArgumentNullException(fun () ->FSharpType.MakeStructTupleType( null) |> ignore ) CheckThrowsArgumentException(fun () ->FSharpType.MakeStructTupleType( [| |]) |> ignore ) type UnionCaseInfoTests() = From 2dbcd31ac2ec78104799b726f5f4fb0f5fc2e532 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 25 Jun 2024 12:42:30 +0200 Subject: [PATCH 3/4] Update tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs Co-authored-by: Tomas Grosup --- .../FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs index c3c80e9bf9c..9af581dca52 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/OperatorsModuleDynamic.fs @@ -18,7 +18,7 @@ module OperatorsModuleDynamic = let _ = f () sprintf "Expected %O exception, got no exception" typeof<'a> |> Assert.Fail with - | :? 'a as e when e.GetType() = typeof<'a> -> () + | :? 'a -> () | :? Reflection.TargetInvocationException as r when (r.InnerException :? 'a) -> () | e -> sprintf "Expected %O or TargetInvocationException containing it, got: %O" typeof<'a> e |> Assert.Fail let CheckThrowsOverflowException = CheckThrowsExn From bdbcb3bec13d47a88df62ab1f938428c14539cdb Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 25 Jun 2024 12:42:37 +0200 Subject: [PATCH 4/4] Update tests/FSharp.Core.UnitTests/LibraryTestFx.fs Co-authored-by: Tomas Grosup --- tests/FSharp.Core.UnitTests/LibraryTestFx.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Core.UnitTests/LibraryTestFx.fs b/tests/FSharp.Core.UnitTests/LibraryTestFx.fs index 63e8a33d2ec..6137eb79d75 100644 --- a/tests/FSharp.Core.UnitTests/LibraryTestFx.fs +++ b/tests/FSharp.Core.UnitTests/LibraryTestFx.fs @@ -18,7 +18,7 @@ let CheckThrowsExn<'a when 'a :> exn> (f : unit -> unit) = let _ = f () sprintf "Expected %O exception, got no exception" typeof<'a> |> Assert.Fail with - | :? 'a as e when e.GetType() = typeof<'a> -> () + | :? 'a -> () | e -> sprintf "Expected %O exception, got: %O" typeof<'a> e |> Assert.Fail let private CheckThrowsExn2<'a when 'a :> exn> s (f : unit -> unit) =