Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master to feature/tasks #9621

Merged
merged 3 commits into from
Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ module internal Utilities =
| value when not (String.IsNullOrEmpty(value)) ->
Some value // Value set externally
| _ ->
// Probe for netsdk install
// Probe for netsdk install, dotnet. and dotnet.exe is a constant offset from the location of System.Int32
let dotnetLocation =
let dotnetApp =
let platform = Environment.OSVersion.Platform
if platform = PlatformID.Unix then "dotnet" else "dotnet.exe"
let assemblyLocation = typeof<DependencyManagerAttribute>.GetTypeInfo().Assembly.Location
let assemblyLocation = typeof<Int32>.GetTypeInfo().Assembly.Location
Path.Combine(assemblyLocation, "../../..", dotnetApp)

if File.Exists(dotnetLocation) then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework

[<TestFixture>]
module ``PreComputedTupleConstructor Tests`` =

[<Test>]
let ``PreComputedTupleConstructor of int and string``() =
// Regression test for FSHARP1.0:5113
// MT DCR: Reflection.FSharpValue.PreComputeTupleConstructor fails when executed for NetFx 2.0 by a Dev10 compiler

let testDelegate = TestDelegate (fun () ->
Reflection.FSharpValue.PreComputeTupleConstructor(typeof<int * string>) [| box 12; box "text" |] |> ignore)

Assert.DoesNotThrow testDelegate |> ignore

[<Test>]
let ``PreComputedTupleConstructor with wrong order of arguments``() =
// Regression test for FSHARP1.0:5113
// MT DCR: Reflection.FSharpValue.PreComputeTupleConstructor fails when executed for NetFx 2.0 by a Dev10 compiler

let testDelegate = TestDelegate (fun () ->
Reflection.FSharpValue.PreComputeTupleConstructor(typeof<int * string>) [| box "text"; box 12; |] |> ignore)

Assert.Throws<System.ArgumentException> testDelegate |> ignore
28 changes: 28 additions & 0 deletions tests/fsharp/Compiler/Libraries/Core/Reflection/SprintfTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework

[<TestFixture>]
module ``Sprintf Tests`` =

type MyR = {c:int;b:int;a:int}

[<Test>]
let ``Sprintf %A of record type``() =
// Regression test for FSHARP1.0:5113

let s1 = sprintf "%A" {a=1;b=2;c=3}
let s2 = sprintf "%A" {c=3;b=2;a=1}

Assert.areEqual s1 s2

type MyT = MyC of int * string * bool

[<Test>]
let ``Sprintf %A of discriminated union type``() =
// Regression test for FSHARP1.0:5113

let DU = MyC (1,"2",true)
Assert.areEqual "MyC (1, \"2\", true)" (sprintf "%A" DU)
63 changes: 63 additions & 0 deletions tests/fsharp/Compiler/Libraries/Core/Unchecked/DefaultOfTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open NUnit.Framework

[<TestFixture>]
module ``DefaultOf Tests`` =

type DUType =
| A
| B of int
| C of DUType * DUType

type RecordType = { A : int; B : string; C : DUType }

type ClassType = string

type InterfaceType =
abstract DoStuff : unit -> unit

type EnumType =
| A = 1
| B = 2
| C = 4

type StructType = struct
val m_ivalue : int
val m_svalue : string
member this.IValue = this.m_ivalue
member this.SValue = this.m_svalue
end

[<Test>]
let `` Unchecked defaultof reference types``() =
Assert.areEqual Unchecked.defaultof<ClassType> null
Assert.areEqual (box Unchecked.defaultof<DUType>) null
Assert.areEqual (box Unchecked.defaultof<RecordType>) null
Assert.areEqual (box Unchecked.defaultof<InterfaceType>) null

[<Test>]
let ``Unchecked defaultof stack types``() =
Assert.areEqual Unchecked.defaultof<int> 0
Assert.areEqual Unchecked.defaultof<float> 0.0
Assert.areEqual Unchecked.defaultof<EnumType> (enum 0)
Assert.areEqual Unchecked.defaultof<StructType>.IValue 0
Assert.areEqual Unchecked.defaultof<StructType>.SValue null

type R = { x : int; y : string }
type U = | A of int | B of string
type S = struct val mutable x : int end
type C() = class end

[<Test>]
let ``Unchecked defaultof and equality``() =
// FSharp1.0:5417 - Unchecked.defaultof<_> on records/unions can cause structural equality check to throw
// Check that Unchecked.defaultof<_> works correctly on various types, mostly structs/unions/records

Assert.areEqual Unchecked.defaultof<R> Unchecked.defaultof<R>
Assert.areEqual Unchecked.defaultof<U> Unchecked.defaultof<U>
Assert.areEqual Unchecked.defaultof<S> Unchecked.defaultof<S>
Assert.areEqual Unchecked.defaultof<C> Unchecked.defaultof<C>
Assert.areEqual Unchecked.defaultof<int> Unchecked.defaultof<int>
3 changes: 3 additions & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<Compile Include="Compiler\Libraries\Core\Operators\RoundTests.fs" />
<Compile Include="Compiler\Libraries\Core\Operators\SignTests.fs" />
<Compile Include="Compiler\Libraries\Core\Operators\StringTests.fs" />
<Compile Include="Compiler\Libraries\Core\Reflection\SprintfTests.fs" />
<Compile Include="Compiler\Libraries\Core\Reflection\PreComputedTupleConstructorTests.fs" />
<Compile Include="Compiler\Libraries\Core\Unchecked\DefaultOfTests.fs" />
<None Include="app.config" />
<None Include="update.base.line.with.actuals.fsx" />

Expand Down
10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/Libraries/Core/Reflection/DU.fs

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/Libraries/Core/Reflection/Record.fs

This file was deleted.

4 changes: 0 additions & 4 deletions tests/fsharpqa/Source/Libraries/Core/Reflection/env.lst

This file was deleted.

51 changes: 0 additions & 51 deletions tests/fsharpqa/Source/Libraries/Core/Unchecked/DefaultOf01.fs

This file was deleted.

17 changes: 0 additions & 17 deletions tests/fsharpqa/Source/Libraries/Core/Unchecked/DefaultOf02.fs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/fsharpqa/Source/Libraries/Core/Unchecked/env.lst

This file was deleted.