|
| 1 | +// #Conformance #Regression |
| 2 | +#if TESTS_AS_APP |
| 3 | +module Core_enum |
| 4 | +#endif |
| 5 | + |
| 6 | +open System.Reflection |
| 7 | +let failures = ref [] |
| 8 | + |
| 9 | +let report_failure (s : string) = |
| 10 | + stderr.Write" Failed: " |
| 11 | + stderr.WriteLine s |
| 12 | + failures := !failures @ [s] |
| 13 | + |
| 14 | +let test (s : string) b = |
| 15 | + stderr.Write(s) |
| 16 | + if b then stderr.WriteLine " Passed" |
| 17 | + else report_failure (s) |
| 18 | + |
| 19 | +let check s b1 b2 = test s (b1 = b2) |
| 20 | + |
| 21 | +type internal internalEnum = Red=0 | Yellow=1 | Blue=2 |
| 22 | +type public publicEnum = Red=0 | Yellow=1 | Blue=2 |
| 23 | + |
| 24 | +module enum = |
| 25 | + |
| 26 | + let AreCasesPublic (t:System.Type) = |
| 27 | + let bindingFlags = BindingFlags.Static ||| BindingFlags.Public |
| 28 | + try |
| 29 | + let red = t.GetField("Red", bindingFlags) |
| 30 | + let yellow = t.GetField("Yellow", bindingFlags) |
| 31 | + let blue = t.GetField("Blue", bindingFlags) |
| 32 | + let value__ = t.GetField("value__", bindingFlags ||| BindingFlags.Instance) |
| 33 | + |
| 34 | + if isNull red || not (red.IsPublic) then failwith (sprintf "Type: %s) - Red is not public. All enum cases should always be public" t.FullName) |
| 35 | + if isNull yellow || not (yellow.IsPublic) then failwith (sprintf "Type: %s) - Yellow is not public. All enum cases should always be public" t.FullName) |
| 36 | + if isNull blue || not (blue.IsPublic) then failwith (sprintf "Type: %s) - Blue is not public. All enum cases should always be public" t.FullName) |
| 37 | + if isNull value__ || not (value__.IsPublic) then failwith (sprintf "Type: %s) - value__ is not public. value__ should always be public" t.FullName) |
| 38 | + true |
| 39 | + with _ -> false |
| 40 | + |
| 41 | + do check "publicEnum" (AreCasesPublic typeof<publicEnum>) true |
| 42 | + do check "internalEnum" (AreCasesPublic typeof<internalEnum>) true |
| 43 | + |
| 44 | + |
| 45 | +#if TESTS_AS_APP |
| 46 | +let RUN() = !failures |
| 47 | +#else |
| 48 | +let aa = |
| 49 | + match !failures with |
| 50 | + | [] -> |
| 51 | + stdout.WriteLine "Test Passed" |
| 52 | + System.IO.File.WriteAllText("test.ok","ok") |
| 53 | + exit 0 |
| 54 | + | _ -> |
| 55 | + stdout.WriteLine "Test Failed" |
| 56 | + exit 1 |
| 57 | +#endif |
| 58 | + |
0 commit comments