-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move signature tests from cambridge suite to component tests (#14317)
* Component tests for signature roundtrip
- Loading branch information
Showing
24 changed files
with
11,732 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/FSharp.Compiler.ComponentTests/Signatures/SigGenerationRoundTripTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module FSharp.Compiler.ComponentTests.Signatures.SigGenerationRoundTripTests | ||
|
||
open Xunit | ||
open FSharp.Test | ||
open FSharp.Test.Compiler | ||
open System.IO | ||
|
||
let testCasesDir = Path.Combine(__SOURCE_DIRECTORY__,"TestCasesForGenerationRoundTrip") | ||
let allTestCases = | ||
Directory.EnumerateFiles(testCasesDir) | ||
|> Seq.toArray | ||
|> Array.map Path.GetFileName | ||
|> Array.map (fun f -> [|f :> obj|]) | ||
|
||
[<Theory>] | ||
[<MemberData(nameof(allTestCases))>] | ||
let ``Generate and compile`` implFileName = | ||
let implContents = File.ReadAllText (Path.Combine(testCasesDir,implFileName)) | ||
|
||
let generatedSignature = | ||
Fs implContents | ||
|> withLangVersionPreview | ||
|> withDefines ["TESTS_AS_APP";"COMPILED"] | ||
|> printSignatures | ||
|
||
Fsi generatedSignature | ||
|> withAdditionalSourceFile (FsSource implContents) | ||
|> withLangVersionPreview | ||
|> withDefines ["TESTS_AS_APP";"COMPILED"] | ||
|> ignoreWarnings | ||
|> asExe | ||
|> compile | ||
|> shouldSucceed | ||
|
8 changes: 8 additions & 0 deletions
8
...mpiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/access-minimal-repro.fsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Core_access | ||
|
||
[<Sealed>] | ||
type MyClassPropertyGetters = | ||
member internal x.InstInternal = 12 | ||
member private x.InstPrivate = 12 | ||
member public x.InstPublic = 12 | ||
member x.InstDefault = 12 |
287 changes: 287 additions & 0 deletions
287
tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/access.fsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,287 @@ | ||
module Core_access | ||
|
||
#light | ||
let failures = ref [] | ||
|
||
let report_failure (s : string) = | ||
stderr.Write" NO: " | ||
stderr.WriteLine s | ||
failures.Value <- failures.Value @ [s] | ||
|
||
let test (s : string) b = | ||
stderr.Write(s) | ||
if b then stderr.WriteLine " OK" | ||
else report_failure (s) | ||
|
||
(*--------------------*) | ||
|
||
// Test cases for bug://1562 | ||
// Checking that generated signature can be compiled against the file. | ||
|
||
type internal typInternal = | AAA1 | ||
type private typPrivate = | AAA2 | ||
type public typPublic = | AAA3 | ||
type typDefault = | AAA4 | ||
type internal rrr = | AAA | ||
|
||
let internal ValInternal = 1212 | ||
let private ValPrivate = 1212 | ||
let public ValPublic = 1212 | ||
let ValDefault = 1212 | ||
|
||
[<Sealed>] | ||
type MyClassFields = | ||
val internal fieldInternal : int | ||
val private fieldPrivate : int | ||
val public fieldPublic : int | ||
|
||
[<Sealed>] | ||
type MyClassMutableFields = | ||
val mutable internal mfieldInternal : int | ||
val mutable private mfieldPrivate : int | ||
val mutable public mfieldPublic : int | ||
|
||
[<Sealed>] | ||
type MyClassStaticMembers = | ||
static member internal SInternal = 12 | ||
static member private SPrivate = 12 | ||
static member public SPublic = 12 | ||
static member SDefault = 12 | ||
static member internal SMInternal() = 12 | ||
static member private SMPrivate() = 12 | ||
static member public SMPublic() = 12 | ||
static member SMDefault() = 12 | ||
|
||
[<Sealed>] | ||
type MyClassPropertiyGetters = | ||
member internal x.InstInternal = 12 | ||
member private x.InstPrivate = 12 | ||
member public x.InstPublic = 12 | ||
member x.InstDefault = 12 | ||
|
||
type MyClassExplicitCtors = | ||
val v : int | ||
internal new(x) = { v = x } | ||
private new(x,y) = { v = x + y} | ||
public new(x,y,z) = { v = x + y + z} | ||
|
||
type MyClassExplicitCtors2 = | ||
new() = {} | ||
internal new(x) = let v : int = x in {} | ||
private new(x,y) = let v : int = x + y in {} | ||
public new(x,y,z) = let v : int = x + y + z in {} | ||
|
||
[<Sealed>] | ||
type MyClassPropertyGetSetterMatrix = | ||
//-- | ||
member obj.PropGetSetInternalInternal | ||
with internal get() = 1 | ||
and internal set(x:int) = () | ||
member obj.PropGetSetInternalPrivate | ||
with internal get() = 1 | ||
and private set(x:int) = () | ||
member obj.PropGetSetInternalPublic | ||
with internal get() = 1 | ||
and public set(x:int) = () | ||
//-- | ||
member obj.PropGetSetPrivateInternal | ||
with private get() = 1 | ||
and internal set(x:int) = () | ||
member obj.PropGetSetPrivatePrivate | ||
with private get() = 1 | ||
and private set(x:int) = () | ||
member obj.PropGetSetPrivatePublic | ||
with private get() = 1 | ||
and public set(x:int) = () | ||
//-- | ||
member obj.PropGetSetPublicInternal | ||
with public get() = 1 | ||
and internal set(x:int) = () | ||
member obj.PropGetSetPublicPrivate | ||
with public get() = 1 | ||
and private set(x:int) = () | ||
member obj.PropGetSetPublicPublic | ||
with public get() = 1 | ||
and public set(x:int) = () | ||
|
||
[<Sealed>] | ||
type MyClassImplicitCtorInternal internal() = | ||
member obj.Res = 12 | ||
|
||
[<Sealed>] | ||
type MyClassImplicitCtorPrivate private() = | ||
member obj.Res = 12 | ||
|
||
module internal ModInternal = begin end | ||
module private ModPrivate = begin end | ||
module public ModPublic = begin end | ||
|
||
type recordRepInternal = internal { rfA1 : int } | ||
type recordRepPrivate = private { rfA2 : int } | ||
type recordRepPublic = public { rfA3 : int } | ||
|
||
type dtypeRepInternal = internal | AA1 | BB1 | ||
type dtypeRepPrivate = private | AA2 | BB2 | ||
type dtypeRepPublic = public | AA3 | BB3 | ||
|
||
type internal dtypeRepPublic2 = private | AA3 | BB3 | ||
type private dtypeRepPublic3 = internal | AA3 | BB3 | ||
|
||
type internal dtypeRepPublic4 = | ||
private | ||
| AA3 | ||
| BB3 | ||
|
||
module internal M = | ||
module private PP = | ||
type dtypeRepPublic5 = | ||
| AA3 | ||
| BB3 | ||
|
||
module private M2 = | ||
module internal P = | ||
let vv = 12 | ||
|
||
|
||
module RestrictedRecordsAndUnionsUsingPrivateAndInternalTypes = | ||
|
||
module public Test1 = | ||
|
||
type internal Data = | ||
{ | ||
Datum: int | ||
} | ||
|
||
type public Datum = | ||
internal | ||
{ | ||
Thing: Data | ||
} | ||
|
||
type public Datum2 = | ||
internal | A of Data * Data | B of Data | ||
|
||
module public Test2 = | ||
|
||
type internal Data = | ||
{ | ||
Datum: int | ||
} | ||
|
||
type internal Datum = | ||
{ | ||
Thing: Data | ||
} | ||
|
||
type internal Datum2 = | ||
| A of Data * Data | B of Data | ||
|
||
module public Test3 = | ||
|
||
type public Data = | ||
internal | ||
{ | ||
Datum: int | ||
} | ||
|
||
type internal Datum = | ||
{ | ||
Thing: Data | ||
} | ||
|
||
type internal Datum2 = | ||
internal | A of Data * Data | B of Data | ||
|
||
|
||
module public Test4 = | ||
|
||
type internal Data = | ||
{ | ||
Datum: int | ||
} | ||
|
||
type public Datum = | ||
internal | ||
{ | ||
Thing: Data | ||
} | ||
|
||
type public Datum2 = | ||
internal | A of Data * Data | B of Data | ||
|
||
|
||
module public Test5 = | ||
|
||
type private Data = | ||
{ | ||
Datum: int | ||
} | ||
|
||
type public Datum = | ||
private | ||
{ | ||
Thing: Data | ||
} | ||
|
||
type public Datum2 = | ||
private | A of Data * Data | B of Data | ||
|
||
|
||
module Test6 = | ||
module internal HelperModule = | ||
|
||
type public Data = | ||
private | ||
{ | ||
Datum: int | ||
} | ||
|
||
let internal handle (data:Data): int = data.Datum | ||
|
||
module public Module = | ||
|
||
type public Data = | ||
private | ||
{ | ||
Thing: HelperModule.Data | ||
} | ||
|
||
let public getInt (data:Data): int = HelperModule.handle data.Thing | ||
|
||
module Test7 = | ||
module internal HelperModule = | ||
|
||
type Data = | ||
{ | ||
Datum: int | ||
} | ||
|
||
let handle (data:Data): int = data.Datum | ||
|
||
module Module = | ||
|
||
type Data = | ||
internal | ||
{ | ||
Thing: HelperModule.Data | ||
} | ||
|
||
let getInt (data:Data): int = HelperModule.handle data.Thing | ||
|
||
|
||
(*--------------------*) | ||
|
||
#if TESTS_AS_APP | ||
let RUN() = failures.Value | ||
#else | ||
let aa = | ||
match failures.Value with | ||
| [] -> | ||
stdout.WriteLine "Test Passed" | ||
System.IO.File.WriteAllText("test.ok","ok") | ||
exit 0 | ||
| _ -> | ||
stdout.WriteLine "Test Failed" | ||
exit 1 | ||
#endif | ||
|
Oops, something went wrong.