Skip to content

Commit

Permalink
Enable more cambridge tests for coreclr (#2071)
Browse files Browse the repository at this point in the history
* Add more tests

* indent

* Enable more cambridge tests for coreclr

* Fix typo

* really fix the typo

* system.runtime reference was incompatible with desktop
  • Loading branch information
KevinRansom authored Dec 22, 2016
1 parent eb8d0cf commit 5f206cd
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"System.Reflection.Emit.Lightweight": "4.3.0",
},
"imports": [ "netstandard1.1", "netstandard1.6", "portable-net45+win8+wp8+wpa81" ]
}
Expand Down
19 changes: 2 additions & 17 deletions tests/fsharp/core/attributes/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ open System.Diagnostics

(* ATTRIBUTES *)

#if !TESTS_AS_APP && !FX_PORTABLE_OR_NETSTANDARD
[<LoaderOptimization(LoaderOptimization.MultiDomainHost)>]
#endif

let main = ()

Expand Down Expand Up @@ -88,23 +90,6 @@ end;;
(* attribute on a return type *)
(* NOT YET: let [<return: Ignore("ignore")>] myMethod3 x = x + 1 *)

#if !FX_NO_CRYPTO
(* BUG 428 - compile time error - on obsolete attributes *)
let f (cert:System.Security.Cryptography.X509Certificates.X509Certificate) =
let x = cert.GetName () in
()


open System.Threading
let test32498() =
let guiTH = new Thread(new ThreadStart(fun () -> ())) in
guiTH.ApartmentState <- ApartmentState.STA

//let [<System.Runtime.CompilerServices.CompilerGlobalScope>] id x = x

//[<System.Runtime.CompilerServices.CompilerGlobalScope>] let id2 x = x
#endif


type A =
class
Expand Down
10 changes: 5 additions & 5 deletions tests/fsharp/core/control/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Core_control
#endif
#light

#if !FX_PORTABLE_OR_NETSTANDARD
#if FX_PORTABLE_OR_NETSTANDARD
open System.Threading.Tasks
#endif

Expand Down Expand Up @@ -666,7 +666,7 @@ module AsBeginEndTests =
(sprintf "cvew0-9rn7")
(let req = AsyncRequest( async { return 2087 } )
let iar = req.BeginAsync(null,null)
iar.AsyncWaitHandle.WaitOne(100,true) |> ignore
iar.AsyncWaitHandle.WaitOne(100) |> ignore
req.EndAsync(iar))
2087

Expand All @@ -675,7 +675,7 @@ module AsBeginEndTests =
(let req = AsyncRequest( async { return 2087 } )
let mutable called = 0
let iar = req.BeginAsync(System.AsyncCallback(fun _ -> called <- 10),null)
iar.AsyncWaitHandle.WaitOne(100,true) |> ignore
iar.AsyncWaitHandle.WaitOne(100) |> ignore
let v = req.EndAsync(iar)
v + called)
2097
Expand All @@ -686,7 +686,7 @@ module AsBeginEndTests =
let mutable called = 0
let iar = req.BeginAsync(System.AsyncCallback(fun iar -> called <- req.EndAsync(iar)),null)
while not iar.IsCompleted do
iar.AsyncWaitHandle.WaitOne(100,true) |> ignore
iar.AsyncWaitHandle.WaitOne(100) |> ignore

called)
2087
Expand All @@ -701,7 +701,7 @@ module AsBeginEndTests =
return 10 } )
let iar = req.BeginAsync(null,null)
printfn "waiting"
iar.AsyncWaitHandle.WaitOne(100,true) |> ignore
iar.AsyncWaitHandle.WaitOne(100) |> ignore
printfn "cancelling"
req.CancelAsync(iar)
(try req.EndAsync(iar) with :? System.OperationCanceledException as e -> 100 ))
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/core/patterns/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ module RegExp =
check "fwhin3op9" ((|Match|_|) "^.*.ml$" "abc.ml") (Some [])

let testFun() =
File.WriteAllLines("test.fs", seq { for (IsMatch "(.*).fs" f) in allFiles System.Environment.CurrentDirectory do yield! "-------------------------------" :: "\n" :: "\n" :: ("// FILE: "+f) :: "" :: "module "+(f |> Path.GetDirectoryName |> Path.GetFileName |> (fun s -> s.ToUpper()))+ " =" :: [ for line in Array.toList (File.ReadAllLines(f)) -> " "+line ] } |> Seq.toArray)
File.WriteAllLines("test.fs", seq { for (IsMatch "(.*).fs" f) in allFiles (System.IO.Directory.GetCurrentDirectory()) do yield! "-------------------------------" :: "\n" :: "\n" :: ("// FILE: "+f) :: "" :: "module "+(f |> Path.GetDirectoryName |> Path.GetFileName |> (fun s -> s.ToUpper()))+ " =" :: [ for line in Array.toList (File.ReadAllLines(f)) -> " "+line ] } |> Seq.toArray)

module RandomWalk =
let ran = new System.Random()
Expand Down
81 changes: 81 additions & 0 deletions tests/fsharp/coreclr_utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ module CoreClrUtilities
cl.Split(' ')
#endif

let commit (results : _[]) =
match results with
| [||] -> null
| [| m |] -> m
| _ -> raise (AmbiguousMatchException())

[<Flags>]
type BindingFlags =
| DeclaredOnly = 2
Expand Down Expand Up @@ -76,17 +82,45 @@ module CoreClrUtilities
| :? System.Reflection.TypeInfo as c -> if c.IsNested then MemberType.NestedType else MemberType.TypeInfo
|_ -> MemberType.None
mapIsMethodOrConstructor ||| mapIsEvent ||| mapIsField ||| mapIsProperty ||| mapIsTypeInfoOrNested


let inline hasFlag (flag : BindingFlags) f = (f &&& flag) = flag
let isDeclaredFlag f = hasFlag BindingFlags.DeclaredOnly f
let isPublicFlag f = hasFlag BindingFlags.Public f
let isStaticFlag f = hasFlag BindingFlags.Static f
let isInstanceFlag f = hasFlag BindingFlags.Instance f
let isNonPublicFlag f = hasFlag BindingFlags.NonPublic f

let isAcceptable bindingFlags isStatic isPublic =
// 1. check if member kind (static\instance) was specified in flags
((isStaticFlag bindingFlags && isStatic) || (isInstanceFlag bindingFlags && not isStatic)) &&
// 2. check if member accessibility was specified in flags
((isPublicFlag bindingFlags && isPublic) || (isNonPublicFlag bindingFlags && not isPublic))

let publicFlags = BindingFlags.Public ||| BindingFlags.Instance ||| BindingFlags.Static


type System.Reflection.MemberInfo with
member this.GetCustomAttributes(inherits:bool) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, inherits) |> Seq.toArray)
member this.GetCustomAttributes(attrTy:Type) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy) |> Seq.toArray)
member this.GetCustomAttributes(attrTy, inherits) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy, inherits) |> Seq.toArray)
member this.MemberType = mapMemberType this

type System.Reflection.MethodInfo with
member this.GetCustomAttributes(inherits:bool) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, inherits) |> Seq.toArray)
member this.GetCustomAttributes(attrTy:Type) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy) |> Seq.toArray)
member this.GetCustomAttributes(attrTy, inherits) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy, inherits) |> Seq.toArray)
member this.MemberType = mapMemberType this

type System.Reflection.PropertyInfo with
member this.GetCustomAttributes(inherits:bool) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, inherits) |> Seq.toArray)
member this.GetCustomAttributes(attrTy:Type) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy) |> Seq.toArray)
member this.GetCustomAttributes(attrTy, inherits) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy, inherits) |> Seq.toArray)
member this.MemberType = mapMemberType this

type System.Reflection.Assembly with
member this.GetCustomAttributes() : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this) |> Seq.toArray)
member this.GetCustomAttributes(attrTy, _inherits) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this, attrTy) |> Seq.toArray)
member this.GetTypes() =
this.DefinedTypes
|> Seq.map (fun ti -> ti.AsType())
Expand All @@ -97,3 +131,50 @@ module CoreClrUtilities
with get () = System.Globalization.CultureInfo.CurrentCulture
and set culture = System.Globalization.CultureInfo.CurrentCulture <- culture

type System.Type with

member this.Assembly = this.GetTypeInfo().Assembly
// use different sources based on Declared flag
member this.GetConstructor(_bindingFlags, _binder, argsT:Type[], _parameterModifiers) = this.GetConstructor(argsT)
member this.GetConstructor(parameterTypes : Type[]) =
this.GetTypeInfo().DeclaredConstructors
|> Seq.filter (fun ci ->
not ci.IsStatic && //exclude type initializer
(
let parameters = ci.GetParameters()
(parameters.Length = parameterTypes.Length) &&
(parameterTypes, parameters) ||> Array.forall2 (fun ty pi -> pi.ParameterType.Equals ty)
)
)
|> Seq.toArray
|> commit
member this.GetCustomAttributes(attrTy, inherits) : obj[] = downcast box(CustomAttributeExtensions.GetCustomAttributes(this.GetTypeInfo(), attrTy, inherits) |> Seq.toArray)
member this.GetGenericParameterConstraints() = this.GetTypeInfo().GetGenericParameterConstraints()
member this.GetMethods(bindingFlags) =
(if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredMethods else this.GetRuntimeMethods())
|> Seq.filter (fun m -> isAcceptable bindingFlags m.IsStatic m.IsPublic)
|> Seq.toArray
member this.GetMethods() = this.GetMethods(publicFlags)
member this.GetMethod(name, ?bindingFlags) =
let bindingFlags = defaultArg bindingFlags publicFlags
this.GetMethods(bindingFlags)
|> Array.filter(fun m -> m.Name = name)
|> commit
member this.GetMethod(name, _bindingFlags, _binder, argsT:Type[], _parameterModifiers) =
this.GetMethod(name, argsT)
member this.GetProperties(?bindingFlags) =
let bindingFlags = defaultArg bindingFlags publicFlags
(if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredProperties else this.GetRuntimeProperties())
|> Seq.filter (fun pi->
let mi = match pi.GetMethod with | null -> pi.SetMethod | _ -> pi.GetMethod
if mi = null then false
else isAcceptable bindingFlags mi.IsStatic mi.IsPublic
)
|> Seq.toArray
member this.GetProperty(name, ?bindingFlags) =
let bindingFlags = defaultArg bindingFlags publicFlags
this.GetProperties(bindingFlags)
|> Array.filter (fun pi -> pi.Name = name)
|> commit
member this.IsGenericType = this.GetTypeInfo().IsGenericType
member this.IsValueType = this.GetTypeInfo().IsValueType
13 changes: 10 additions & 3 deletions tests/fsharp/single-test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type Permutation =
| AS_DLL
#endif

let singleTestBuildAndRunAux cfg p =
let singleTestBuildAndRunCore cfg (copyFiles:string) p =

//remove FSharp.Core.dll from the target directory to ensure that compiler uses the correct FSharp.Core.dll
do if fileExists cfg "FSharp.Core.dll" then rm cfg "FSharp.Core.dll"

Expand All @@ -36,12 +37,12 @@ let singleTestBuildAndRunAux cfg p =

makeDirectory (getDirectoryName outFile)
let fscArgs =
sprintf """--debug:portable --debug+ --out:%s --target:exe -g --define:FX_RESHAPED_REFLECTION --define:NETSTANDARD1_6 --define:FSCORE_PORTABLE_NEW --define:FX_PORTABLE_OR_NETSTANDARD "%s" %s """
sprintf """--debug:portable --debug+ --out:%s --target:exe -g --define:FX_RESHAPED_REFLECTION --define:NETSTANDARD1_6 --define:FSCORE_PORTABLE_NEW --define:FX_PORTABLE_OR_NETSTANDARD --define:FX_RESHAPED_REFLECTION "%s" %s """
outFile
extraSource
(String.concat " " sources)

let fsccArgs = sprintf """--OutputDir:%s %s""" outDir fscArgs
let fsccArgs = sprintf """--OutputDir:%s --CopyDlls:%s %s""" outDir copyFiles fscArgs

fsi cfg "--exec %s %s %s"
cfg.fsi_flags
Expand Down Expand Up @@ -146,6 +147,12 @@ let singleTestBuildAndRunAux cfg p =
testOkFile.CheckExists()
#endif

let singleTestBuildAndRunAux cfg p =
singleTestBuildAndRunCore cfg "" p

let singleTestBuildAndRunWithCopyDlls cfg copyFiles p =
singleTestBuildAndRunCore cfg copyFiles p

let singleTestBuildAndRun dir p =
let cfg = testConfig dir
singleTestBuildAndRunAux cfg p
Expand Down
Loading

0 comments on commit 5f206cd

Please sign in to comment.