Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ab5a63

Browse files
committed
Reflection tests
1 parentc2cb706 commit9ab5a63

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openSystem
2+
openSystem.Linq
3+
openSystem.Reflection
4+
5+
typethisAssembly(_dummy:System.Object)=classend
6+
7+
modulepublicMyLiteralFields=
8+
[<Literal>]
9+
letpublicliteralFieldX=7
10+
11+
printfn"MyFields.literalFieldX =%d" MyLiteralFields.literalFieldX
12+
13+
// Use dotnet reflection to verify that x is a Literal Constant
14+
// This works on full desktop / coreclr and also fsi
15+
letasm= thisAssembly(null).GetType().GetTypeInfo().Assembly
16+
lettyp= asm.GetTypes()|> Array.filter(fun t-> t.FullName.EndsWith("+MyLiteralFields"))|> Array.tryLast
17+
letresult=
18+
match typwith
19+
| Some typ->
20+
// Gets literalFieldX checks to see if it is marked "Literal"
21+
letfieldInfo= typ.GetTypeInfo().DeclaredFields|> Seq.tryFind(fun fi-> fi.Name.StartsWith("literalFieldX"))
22+
match fieldInfowith
23+
| Some fieldInfo->
24+
if fieldInfo.IsLiteral=truethen0else2
25+
| None->
26+
printfn"Failed to find fieldliteralFieldX ="
27+
3
28+
| None->
29+
printfn"Failed to find module public MyLiteralFields ="
30+
1
31+
if result=0then printfn"Succeeded"else printfn"Failed:%d" result
32+
exit result
33+

‎tests/fsharp/tests.fs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,8 @@ module ToolsTests =
14561456

14571457

14581458
moduleRegressionTests=
1459-
1460-
[<Test >]
1459+
1460+
//[<Test >]
14611461
let``literal-value-bug-1-FSC_BASIC``()=
14621462
letcfg= testConfig"regression/literal-value-bug-1"
14631463

@@ -1477,7 +1477,13 @@ module RegressionTests =
14771477
|_->
14781478
Assert.Fail(sprintf"'%s' and '%s' differ;%A"(getfullpath cfg outFile)(getfullpath cfg expectedFile) diff)
14791479

1480-
[<Test >]
1480+
[<Test>]
1481+
let``literal-value-bug-2-FSC_BASIC``()= singleTestBuildAndRun"regression/literal-value-bug-2" FSC_BASIC
1482+
1483+
[<Test>]
1484+
let``literal-value-bug-2-FSI_BASIC``()= singleTestBuildAndRun"regression/literal-value-bug-2" FSI_BASIC
1485+
1486+
[<Test>]
14811487
let``struct-tuple-bug-1-FSC_BASIC``()= singleTestBuildAndRun"regression/struct-tuple-bug-1" FSC_BASIC
14821488

14831489
[<Test >]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp