Skip to content

Commit f72ab4c

Browse files
authored
Re-enable surface area tests in master branch (#7332)
* Re-enable surface area tests in master branch * net40 surface area
1 parent faffb13 commit f72ab4c

File tree

6 files changed

+124
-5113
lines changed

6 files changed

+124
-5113
lines changed

tests/FSharp.Core.UnitTests/FSharp.Core.UnitTests.fsproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@
8080
<Compile Include="FSharp.Core\Microsoft.FSharp.Quotations\FSharpQuotations.fs" />
8181
<Compile Include="TypeForwarding.fs" />
8282
<Compile Include="StructTuples.fs" />
83-
<Compile Include="SurfaceArea.coreclr.fs" Condition="$(TargetFramework.StartsWith('netcoreapp')) and '$(FX_VERIFY_SURFACEAREA)' == 'true'" />
84-
<Compile Include="SurfaceArea.net40.fs" Condition="$(TargetFramework.StartsWith('net4')) and '$(FX_VERIFY_SURFACEAREA)' == 'true'" />
83+
84+
<Compile Include="SurfaceArea.coreclr.fs" Condition="$(TargetFramework.StartsWith('netcoreapp'))" />
85+
<Compile Include="SurfaceArea.net40.fs" Condition="$(TargetFramework.StartsWith('net4'))" />
8586
</ItemGroup>
8687

8788
<ItemGroup>

tests/FSharp.Core.UnitTests/LibraryTestFx.fs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,67 +61,55 @@ let sleep(n : int32) =
6161
System.Threading.Thread.Sleep(n)
6262
#endif
6363

64-
#if VERIFY_SURFACEAREA
6564
module SurfaceArea =
6665
open System.Reflection
6766
open System
6867
open System.Text.RegularExpressions
69-
68+
7069
// gets string form of public surface area for the currently-loaded FSharp.Core
7170
let private getActual () =
72-
71+
7372
// get current FSharp.Core
74-
let asm =
75-
#if FX_RESHAPED_REFLECTION
76-
typeof<int list>.GetTypeInfo().Assembly
77-
#else
78-
typeof<int list>.Assembly
79-
#endif
80-
73+
let asm = typeof<int list>.GetTypeInfo().Assembly
74+
let fsCoreFullName = asm.FullName
75+
8176
// public types only
82-
let types =
83-
#if FX_RESHAPED_REFLECTION
84-
asm.ExportedTypes |> Seq.filter (fun ty -> let ti = ty.GetTypeInfo() in ti.IsPublic || ti.IsNestedPublic) |> Array.ofSeq
85-
#else
86-
asm.GetExportedTypes()
87-
#endif
77+
let types = asm.ExportedTypes |> Seq.filter (fun ty -> let ti = ty.GetTypeInfo() in ti.IsPublic || ti.IsNestedPublic) |> Array.ofSeq
8878

79+
let typenames = new System.Collections.Generic.List<string>()
8980
// extract canonical string form for every public member of every type
9081
let getTypeMemberStrings (t : Type) =
9182
// for System.Runtime-based profiles, need to do lots of manual work
92-
#if FX_RESHAPED_REFLECTION
9383
let getMembers (t : Type) =
9484
let ti = t.GetTypeInfo()
95-
let cast (info : #MemberInfo) = (t, info :> MemberInfo)
85+
let cast (info: #MemberInfo) = (t, info :> MemberInfo)
86+
let isDeclaredInFSharpCore (m:MemberInfo) = m.DeclaringType.Assembly.FullName = fsCoreFullName
9687
seq {
97-
yield! t.GetRuntimeEvents() |> Seq.filter (fun m -> m.AddMethod.IsPublic) |> Seq.map cast
98-
yield! t.GetRuntimeProperties() |> Seq.filter (fun m -> m.GetMethod.IsPublic) |> Seq.map cast
99-
yield! t.GetRuntimeMethods() |> Seq.filter (fun m -> m.IsPublic) |> Seq.map cast
100-
yield! t.GetRuntimeFields() |> Seq.filter (fun m -> m.IsPublic) |> Seq.map cast
88+
yield! t.GetRuntimeEvents() |> Seq.filter (fun m -> m.AddMethod.IsPublic && m |> isDeclaredInFSharpCore) |> Seq.map cast
89+
yield! t.GetRuntimeProperties() |> Seq.filter (fun m -> m.GetMethod.IsPublic && m |> isDeclaredInFSharpCore) |> Seq.map cast
90+
yield! t.GetRuntimeMethods() |> Seq.filter (fun m -> m.IsPublic && m |> isDeclaredInFSharpCore) |> Seq.map cast
91+
yield! t.GetRuntimeFields() |> Seq.filter (fun m -> m.IsPublic && m |> isDeclaredInFSharpCore) |> Seq.map cast
10192
yield! ti.DeclaredConstructors |> Seq.filter (fun m -> m.IsPublic) |> Seq.map cast
10293
yield! ti.DeclaredNestedTypes |> Seq.filter (fun ty -> ty.IsNestedPublic) |> Seq.map cast
10394
} |> Array.ofSeq
10495

96+
10597
getMembers t
10698
|> Array.map (fun (ty, m) -> sprintf "%s: %s" (ty.ToString()) (m.ToString()))
107-
#else
108-
t.GetMembers()
109-
|> Array.map (fun v -> sprintf "%s: %s" (v.ReflectedType.ToString()) (v.ToString()))
110-
#endif
111-
99+
112100
let actual =
113101
types |> Array.collect getTypeMemberStrings
114102

115103
asm,actual
116-
104+
117105
// verify public surface area matches expected
118106
let verify expected platform (fileName : string) =
119107
let normalize (s:string) =
120108
Regex.Replace(s, "(\\r\\n|\\n|\\r)+", "\r\n").Trim()
121109

122110
let asm, actualNotNormalized = getActual ()
123111
let actual = actualNotNormalized |> Seq.map normalize |> Seq.filter (String.IsNullOrWhiteSpace >> not) |> set
124-
112+
125113
let expected =
126114
// Split the "expected" string into individual lines, then normalize it.
127115
(normalize expected).Split([|"\r\n"; "\n"; "\r"|], StringSplitOptions.RemoveEmptyEntries)
@@ -173,4 +161,3 @@ module SurfaceArea =
173161
sb.ToString ()
174162

175163
Assert.Fail msg
176-
#endif

0 commit comments

Comments
 (0)