Skip to content

Commit fd74e2c

Browse files
committed
add test and prospecttive fix for missing framework versions
1 parent dbbd46a commit fd74e2c

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\TreeVisitorTests.fs">
6767
<Link>TreeVisitorTests.fs</Link>
6868
</Compile>
69+
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\ScriptOptionsTests.fs">
70+
<Link>ScriptOptionsTests.fs</Link>
71+
</Compile>
6972
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\Program.fs" Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
7073
<Link>Program.fs</Link>
7174
</Compile>

fcs/FSharp.Compiler.Service.Tests/FsxCompletionProviderTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor.Tests.Roslyn
2323
open System
2424
open System.Collections.Generic
2525
open System.IO
26-
open System.Linq
26+
open System.Linq
2727
open System.Reflection
2828

2929
open NUnit.Framework

src/fsharp/DotNetFrameworkDependencies.fs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,19 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
115115
let desktopProductVersionMonikers = [|
116116
// major, minor, build, revision, moniker
117117
4, 8, 3815, 0, "net48"
118+
4, 8, 3761, 0, "net48"
118119
4, 7, 3190, 0, "net472"
120+
4, 7, 3062, 0, "net472"
119121
4, 7, 2600, 0, "net471"
122+
4, 7, 2558, 0, "net471"
120123
4, 7, 2053, 0, "net47"
124+
4, 7, 2046, 0, "net47"
121125
4, 6, 1590, 0, "net462"
126+
4, 6, 57, 0, "net462"
122127
4, 6, 1055, 0, "net461"
123128
4, 6, 81, 0, "net46"
124129
4, 0, 30319, 34209, "net452"
130+
4, 0, 30319, 17020, "net452"
125131
4, 0, 30319, 18408, "net451"
126132
4, 0, 30319, 17929, "net45"
127133
4, 0, 30319, 1, "net4"
@@ -138,14 +144,16 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
138144
with _ -> defaultMscorlibVersion
139145

140146
// Get the ProductVersion of this framework compare with table yield compatible monikers
141-
let _, _, _, _, moniker =
147+
match
142148
desktopProductVersionMonikers
143-
|> Array.find (fun (major, minor, build, revision, _) ->
149+
|> Array.tryFind (fun (major, minor, build, revision, _) ->
144150
(majorPart >= major) &&
145151
(minorPart >= minor) &&
146152
(buildPart >= build) &&
147-
(privatePart >= revision))
148-
moniker
153+
(privatePart >= revision)) with
154+
| Some (_,_,_,_,moniker) -> moniker
155+
| None -> // if no moniker can be found, assume latest stable?
156+
"net48"
149157

150158
/// Gets the tfm E.g netcore3.0, net472
151159
let executionTfm =
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#if INTERACTIVE
2+
#r "../../artifacts/bin/fcs/net461/FSharp.Compiler.Service.dll" // note, build FSharp.Compiler.Service.Tests.fsproj to generate this, this DLL has a public API so can be used from F# Interactive
3+
#r "../../artifacts/bin/fcs/net461/nunit.framework.dll"
4+
#load "FsUnit.fs"
5+
#load "Common.fs"
6+
#else
7+
module Tests.Service.ScriptOptions
8+
#endif
9+
10+
open NUnit.Framework
11+
open FsUnit
12+
open System
13+
open FSharp.Compiler
14+
open FSharp.Compiler.SourceCodeServices
15+
open FSharp.Compiler.Service.Tests.Common
16+
17+
18+
let scriptSource = """
19+
open System
20+
let pi = Math.PI
21+
"""
22+
23+
[<TestCase(true, false, [| "--targetprofile:mscorlib" |])>]
24+
[<TestCase(false, true, [| "--targetprofile:mscorlib" |])>]
25+
[<Test>]
26+
let ``can generate options for different frameworks regardless of execution environment``(assumeNetFx, useSdk, flags) =
27+
let path = IO.Path.GetTempPath()
28+
let file = IO.Path.GetTempFileName()
29+
let tempFile = IO.Path.Combine(path, file)
30+
let (options, errors) =
31+
checker.GetProjectOptionsFromScript(tempFile, Text.SourceText.ofString scriptSource, assumeDotNetFramework = assumeNetFx, useSdkRefs = useSdk, otherFlags = flags)
32+
|> Async.RunSynchronously
33+
match errors with
34+
| [] -> ()
35+
| errors -> failwithf "Error while parsing script with assumeDotNetFramework:%b, useSdkRefs:%b, and otherFlags:%A:\n%A" assumeNetFx useSdk flags errors

0 commit comments

Comments
 (0)