DependencyManagerInteractiveTests.fs 40.8 KB
Newer Older
1 2
// Copyright (c) Microsoft Corporation.  All Rights Reserved.  See License.txt in the project root for license information.

K
Kevin Ransom (msft) 已提交
3
namespace FSharp.Compiler.Scripting.DependencyManager.UnitTests
4 5 6

open System
open System.IO
7
open System.Reflection
8
open System.Runtime.InteropServices
K
Kevin Ransom (msft) 已提交
9 10
open System.Threading

11
open FSharp.Compiler.Interactive.Shell
12
open FSharp.Compiler.DependencyManager
D
Don Syme 已提交
13
open FSharp.Compiler.Diagnostics
14
open FSharp.DependencyManager.Nuget
15 16
open FSharp.Test.ScriptHelpers
open FSharp.Test.Utilities
K
Kevin Ransom (msft) 已提交
17

18 19
open Internal.Utilities

K
Kevin Ransom (msft) 已提交
20
open Xunit
21

22 23 24 25
module Native =
    [<DllImport("NoneExistentDll")>]
    extern int NoneSuch()

K
Kevin Ransom (msft) 已提交
26 27
type scriptHost (?langVersion: LangVersion) = inherit FSharpScript(langVersion=defaultArg langVersion LangVersion.Preview)

28 29
type DependencyManagerInteractiveTests() =

D
Don Syme 已提交
30
    let getValue ((value: Result<FsiValue option, exn>), (errors: FSharpDiagnostic[])) =
31 32 33 34 35 36
        if errors.Length > 0 then
            failwith <| sprintf "Evaluation returned %d errors:\r\n\t%s" errors.Length (String.Join("\r\n\t", errors))
        match value with
        | Ok(value) -> value
        | Error ex -> raise ex

D
Don Syme 已提交
37
    let getErrors ((_value: Result<FsiValue option, exn>), (errors: FSharpDiagnostic[])) =
K
Kevin Ransom (msft) 已提交
38
        errors
39

K
Kevin Ransom (msft) 已提交
40
    let ignoreValue = getValue >> ignore
B
Brett V. Forsgren 已提交
41

K
Kevin Ransom (msft) 已提交
42
    [<Fact>]
D
Don Syme 已提交
43
    member _.``SmokeTest - #r nuget``() =
44
        let text = """
45
#r @"nuget:Newtonsoft.Json, Version=9.0.1"
46
0"""
K
Kevin Ransom (msft) 已提交
47
        use script = new scriptHost()
48 49
        let opt = script.Eval(text) |> getValue
        let value = opt.Value
K
Kevin Ransom (msft) 已提交
50 51
        Assert.Equal(typeof<int>, value.ReflectionType)
        Assert.Equal(0, value.ReflectionValue :?> int)
52

K
Kevin Ransom (msft) 已提交
53
    [<Fact>]
D
Don Syme 已提交
54
    member _.``SmokeTest - #r nuget package not found``() =
55 56 57
        let text = """
#r @"nuget:System.Collections.Immutable.DoesNotExist, version=1.5.0"
0"""
K
Kevin Ransom (msft) 已提交
58
        use script = new scriptHost()
59 60
        let opt, errors = script.Eval(text)
        Assert.Equal(errors.Length, 1)
B
Brett V. Forsgren 已提交
61

K
Kevin Ransom (msft) 已提交
62 63 64
(*
    [<Theory>]
    [<InlineData("""#r "#i "unknown:Astring" """, """ """)>]
D
Don Syme 已提交
65
    member _.``syntax produces error messages in FSharp 4.7``(code:string, message: string) =
K
Kevin Ransom (msft) 已提交
66 67 68 69
        use script = new scriptHost()
        let errors = script.Eval(code) |> getErrors
        Assert.Contains(message, errors |> Array.map(fun e -> e.Message))
*)
K
Kevin Ransom (msft) 已提交
70
    [<Fact>]
D
Don Syme 已提交
71
    member _.``Use Dependency Manager to resolve dependency FSharp.Data``() =
72 73 74

        let nativeProbingRoots () = Seq.empty<string>

75
        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
76 77 78 79 80 81
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)
82 83 84 85

        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")

        if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
K
Kevin Ransom (msft) 已提交
86
            let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"|], reportError, "net472")
K
Kevin Ransom (msft) 已提交
87 88 89
            Assert.Equal(true, result.Success)
            Assert.Equal(1, result.Resolutions |> Seq.length)
            Assert.Equal(1, result.SourceFiles |> Seq.length)
90
            Assert.Equal(2, result.Roots |> Seq.length)
91

K
Kevin Ransom (msft) 已提交
92
        let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"|], reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
93 94 95 96
        Assert.Equal(true, result.Success)
        Assert.Equal(1, result.Resolutions |> Seq.length)
        Assert.Equal(1, result.SourceFiles |> Seq.length)
        Assert.Equal(1, result.Roots |> Seq.length)
97 98
        ()

99
    [<Fact>]
D
Don Syme 已提交
100
    member _.``Dependency Manager Reports package root for nuget package with no build artifacts``() =
101 102 103

        let nativeProbingRoots () = Seq.empty<string>

104
        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
105 106 107 108 109 110 111 112 113
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")

K
Kevin Ransom (msft) 已提交
114
        let result = dp.Resolve(idm, ".fsx", [|"r", "Microsoft.Data.Sqlite, 3.1.8"|], reportError, "net7.0")
115 116 117 118 119 120
        Assert.Equal(true, result.Success)
        Assert.True((result.Resolutions |> Seq.length) > 1)
        Assert.Equal(1, result.SourceFiles |> Seq.length)
        Assert.True(Option.isSome(result.Roots |> Seq.tryFind(fun root -> root.EndsWith("microsoft.data.sqlite/3.1.8/"))))
        ()

B
Brett V. Forsgren 已提交
121

K
Kevin Ransom (msft) 已提交
122
    [<Fact>]
D
Don Syme 已提交
123
    member _.``Dependency add with nonexistent package should fail``() =
124 125 126

        let nativeProbingRoots () = Seq.empty<string>

127
        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
128 129 130 131 132 133
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)
134 135 136 137

        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")

        if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
K
Kevin Ransom (msft) 已提交
138
            let result = dp.Resolve(idm, ".fsx", [|"r", "System.Collections.Immutable.DoesNotExist"|], reportError, "net472")
K
Kevin Ransom (msft) 已提交
139 140 141 142
            Assert.Equal(false, result.Success)
            Assert.Equal(0, result.Resolutions |> Seq.length)
            Assert.Equal(0, result.SourceFiles |> Seq.length)
            Assert.Equal(0, result.Roots |> Seq.length)
143

K
Kevin Ransom (msft) 已提交
144
        let result = dp.Resolve(idm, ".fsx", [|"r", "System.Collections.Immutable.DoesNotExist"|], reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
145 146 147 148
        Assert.Equal(false, result.Success)
        Assert.Equal(0, result.Resolutions |> Seq.length)
        Assert.Equal(0, result.SourceFiles |> Seq.length)
        Assert.Equal(0, result.Roots |> Seq.length)
149 150
        ()

B
Brett V. Forsgren 已提交
151

D
Don Syme 已提交
152
    [<Fact(Skip="failing on main")>]
D
Don Syme 已提交
153
    member _.``Multiple Instances of DependencyProvider should be isolated``() =
154

155 156 157
        let assemblyProbingPaths () = Seq.empty<string>
        let nativeProbingRoots () = Seq.empty<string>

158
        use dp1 = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
159 160 161 162 163 164
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)
165 166 167

        let idm1 = dp1.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
        if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
K
Kevin Ransom (msft) 已提交
168
            let result1 = dp1.Resolve(idm1, ".fsx", [|"r", "FSharp.Data,3.3.3"|], reportError, "net472")
K
Kevin Ransom (msft) 已提交
169 170
            Assert.Equal(true, result1.Success)
            Assert.Equal(1, result1.Resolutions |> Seq.length)
171
            Assert.True((result1.Resolutions |> Seq.head).Contains("/net45/"))
K
Kevin Ransom (msft) 已提交
172
            Assert.Equal(1, result1.SourceFiles |> Seq.length)
173
            Assert.Equal(2, result1.Roots |> Seq.length)
K
Kevin Ransom (msft) 已提交
174
            Assert.True((result1.Roots |> Seq.head).EndsWith("/fsharp.data/3.3.3/"))
175
            Assert.True((result1.Roots |> Seq.last).EndsWith("/microsoft.netframework.referenceassemblies/1.0.0/"))
176

K
Kevin Ransom (msft) 已提交
177
        let result2 = dp1.Resolve(idm1, ".fsx", [|"r", "FSharp.Data,3.3.3"|], reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
178 179
        Assert.Equal(true, result2.Success)
        Assert.Equal(1, result2.Resolutions |> Seq.length)
180
        let expected2 = "/netstandard2.0/"
K
Kevin Ransom (msft) 已提交
181 182 183 184
        Assert.True((result2.Resolutions |> Seq.head).Contains(expected2))
        Assert.Equal(1, result2.SourceFiles |> Seq.length)
        Assert.Equal(1, result2.Roots |> Seq.length)
        Assert.True((result2.Roots |> Seq.head).EndsWith("/fsharp.data/3.3.3/"))
185

186
        use dp2 = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
187 188 189
        let idm2 = dp2.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")

        if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
K
Kevin Ransom (msft) 已提交
190
            let result3 = dp2.Resolve(idm2, ".fsx", [|"r", "System.Json, Version=4.6.0"|], reportError, "net472")
K
Kevin Ransom (msft) 已提交
191 192
            Assert.Equal(true, result3.Success)
            Assert.Equal(1, result3.Resolutions |> Seq.length)
193
            Assert.True((result3.Resolutions |> Seq.head).Contains("/netstandard2.0/"))
K
Kevin Ransom (msft) 已提交
194 195 196
            Assert.Equal(1, result3.SourceFiles |> Seq.length)
            Assert.Equal(1, result3.SourceFiles |> Seq.length)
            Assert.True((result3.Roots |> Seq.head).EndsWith("/system.json/4.6.0/"))
197

K
Kevin Ransom (msft) 已提交
198
        let result4 = dp2.Resolve(idm2, ".fsx", [|"r", "System.Json, Version=4.6.0"|], reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
199 200
        Assert.Equal(true, result4.Success)
        Assert.Equal(1, result4.Resolutions |> Seq.length)
201
        let expected4 = "/netstandard2.0/"
K
Kevin Ransom (msft) 已提交
202 203 204 205
        Assert.True((result4.Resolutions |> Seq.head).Contains(expected4))
        Assert.Equal(1, result4.SourceFiles |> Seq.length)
        Assert.Equal(1, result4.Roots |> Seq.length)
        Assert.True((result4.Roots |> Seq.head).EndsWith("/system.json/4.6.0/"))
206 207
        ()

K
Kevin Ransom (msft) 已提交
208
    [<Fact>]
D
Don Syme 已提交
209
    member _.``Nuget Reference package with dependencies we should get package roots and dependent references``() =
210

211 212
        let nativeProbingRoots () = Seq.empty<string>

213
        use dp1 = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
214 215 216 217 218 219
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)
220 221 222 223

        let idm1 = dp1.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")

        if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
K
Kevin Ransom (msft) 已提交
224
            let result1 = dp1.Resolve(idm1, ".fsx", [|"r", "Microsoft.Extensions.Configuration.Abstractions, 3.1.1"|], reportError, "net472")
K
Kevin Ransom (msft) 已提交
225 226
            Assert.Equal(true, result1.Success)
            Assert.Equal(6, result1.Resolutions |> Seq.length)
227
            Assert.True((result1.Resolutions |> Seq.head).Contains("/netstandard2.0/"))
K
Kevin Ransom (msft) 已提交
228
            Assert.Equal(1, result1.SourceFiles |> Seq.length)
229
            Assert.Equal(7, result1.Roots |> Seq.length)
K
Kevin Ransom (msft) 已提交
230
            Assert.True((result1.Roots |> Seq.head).EndsWith("/microsoft.extensions.configuration.abstractions/3.1.1/"))
231 232 233

        // Netstandard gets fewer dependencies than desktop, because desktop framework doesn't contain assemblies like System.Memory
        // Those assemblies must be delivered by nuget for desktop apps
K
Kevin Ransom (msft) 已提交
234
        let result2 = dp1.Resolve(idm1, ".fsx", [|"r", "Microsoft.Extensions.Configuration.Abstractions, 3.1.1"|], reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
235 236
        Assert.Equal(true, result2.Success)
        Assert.Equal(2, result2.Resolutions |> Seq.length)
237
        let expected = "/netcoreapp3.1/"
K
Kevin Ransom (msft) 已提交
238 239 240 241
        Assert.True((result2.Resolutions |> Seq.head).Contains(expected))
        Assert.Equal(1, result2.SourceFiles |> Seq.length)
        Assert.Equal(2, result2.Roots |> Seq.length)
        Assert.True((result2.Roots |> Seq.head).EndsWith("/microsoft.extensions.configuration.abstractions/3.1.1/"))
242 243 244
        ()

/// Native dll resolution is not implemented on desktop
245
#if NETCOREAPP
246
    [<Fact(Skip="downloads very large ephemeral packages"); >]
D
Don Syme 已提交
247
    member _.``Script using TorchSharp``() =
248 249 250 251 252 253 254 255 256
        let text = """
#r "nuget:RestoreSources=https://donsyme.pkgs.visualstudio.com/TorchSharp/_packaging/packages2/nuget/v3/index.json"
#r "nuget:libtorch-cpu,0.3.52118"
#r "nuget:TorchSharp,0.3.52118"

TorchSharp.Tensor.LongTensor.From([| 0L .. 100L |]).Device
"""

        if RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
K
Kevin Ransom (msft) 已提交
257
            use script = new scriptHost()
258 259
            let opt = script.Eval(text) |> getValue
            let value = opt.Value
K
Kevin Ransom (msft) 已提交
260 261
            Assert.Equal(typeof<string>, value.ReflectionType)
            Assert.Equal("cpu", value.ReflectionValue :?> string)
262 263 264
        ()


K
Kevin Ransom (msft) 已提交
265
    [<Fact>]
D
Don Syme 已提交
266
    member _.``Use Dependency Manager to restore packages with native dependencies, build and run script that depends on the results``() =
267
        let packagemanagerlines = [|
K
Kevin Ransom (msft) 已提交
268 269
            "r", "Microsoft.ML,version=1.4.0-preview"
            "r", "Microsoft.ML.AutoML,version=0.16.0-preview"
270
            "r", "Microsoft.Data.Analysis,version=0.4.0"
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
        |]

        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let mutable resolverPackageRoots = Seq.empty<string>
        let mutable resolverPackageRoots = Seq.empty<string>
        let mutable resolverReferences = Seq.empty<string>

        let nativeProbingRoots () = resolverPackageRoots
        let assemblyProbingPaths () = resolverReferences

        // Restore packages, Get Reference dll paths and package roots
        let result =
289
            use dp = new DependencyProvider(AssemblyResolutionProbe(assemblyProbingPaths), NativeResolutionProbe(nativeProbingRoots), false)
290
            let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
291
            dp.Resolve(idm, ".fsx", packagemanagerlines, reportError, "net7.0")
292

K
Kevin Ransom (msft) 已提交
293
        Assert.True(result.Success, "resolve failed")
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320

        resolverPackageRoots <- result.Roots
        resolverReferences <- result.Resolutions

// Build and execute reference
        let referenceText =
#if DISABLED_DUE_TO_ISSUE_8588
//
// https://github.com/dotnet/fsharp/issues/8588
            // For this test case use Assembly Qualified References
            ("", result.Resolutions)
            ||> Seq.fold(fun acc r ->
                let assemblyName = AssemblyName.GetAssemblyName(r)
                acc + "#r @\"" + assemblyName.FullName + "\"" + Environment.NewLine)
#else
            // use standard #r for now
            ("", result.Resolutions)
            ||> Seq.fold(fun acc r ->
                acc + "#r @\"" + r + "\"" + Environment.NewLine)
#endif

        let code = @"
$(REFERENCES)

open System
open System.IO
open System.Linq
321
open Microsoft.Data.Analysis
322 323 324 325 326 327 328 329 330 331 332

let Shuffle (arr:int[]) =
    let rnd = Random()
    for i in 0 .. arr.Length - 1 do
        let r = i + rnd.Next(arr.Length - i)
        let temp = arr.[r]
        arr.[r] <- arr.[i]
        arr.[i] <- temp
    arr

let housingPath = ""housing.csv""
333 334 335
let housingData = DataFrame.LoadCsv(housingPath)
let randomIndices = (Shuffle(Enumerable.Range(0, (int (housingData.Rows.Count) - 1)).ToArray()))
let testSize = int (float (housingData.Rows.Count) * 0.1)
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
let trainRows = randomIndices.[testSize..]
let testRows = randomIndices.[..testSize]
let housing_train = housingData.[trainRows]

open Microsoft.ML
open Microsoft.ML.Data
open Microsoft.ML.AutoML

let mlContext = MLContext()
let experiment = mlContext.Auto().CreateRegressionExperiment(maxExperimentTimeInSeconds = 15u)
let result = experiment.Execute(housing_train, labelColumnName = ""median_house_value"")
let details = result.RunDetails
printfn ""%A"" result
123
"
        let scriptText = code.Replace("$(REFERENCES)", referenceText)

        // Use the dependency manager to resolve assemblies and native paths
354
        use dp = new DependencyProvider(AssemblyResolutionProbe(assemblyProbingPaths), NativeResolutionProbe(nativeProbingRoots), false)
355 356 357 358

        use script = new FSharpScript()
        let opt = script.Eval(scriptText)  |> getValue
        let value = opt.Value
K
Kevin Ransom (msft) 已提交
359
        Assert.Equal(123, value.ReflectionValue :?> int32)
360

K
Kevin Ransom (msft) 已提交
361
    [<Fact>]
D
Don Syme 已提交
362
    member _.``Use NativeResolver to resolve native dlls.``() =
363
        let packagemanagerlines = [|
K
Kevin Ransom (msft) 已提交
364 365
            "r", "Microsoft.ML,version=1.4.0-preview"
            "r", "Microsoft.ML.AutoML,version=0.16.0-preview"
366
            "r", "Microsoft.Data.Analysis,version=0.4.0"
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
        |]

        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let mutable resolverPackageRoots = Seq.empty<string>
        let mutable resolverPackageRoots = Seq.empty<string>

        let mutable resolverReferences = Seq.empty<string>
        let nativeProbingRoots () = resolverPackageRoots
        let assemblyPaths () = resolverReferences

        // Restore packages, Get Reference dll paths and package roots
        let result =
385
            use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
386
            let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
387
            dp.Resolve(idm, ".fsx", packagemanagerlines, reportError, "net7.0")
388

K
Kevin Ransom (msft) 已提交
389
        Assert.True(result.Success, "resolve failed")
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405

        resolverPackageRoots <- result.Roots
        resolverReferences <- result.Resolutions

        use _nativeDepencyResolver = new NativeDllResolveHandler(NativeResolutionProbe(nativeProbingRoots))

        // Build and execute script
        let referenceText =
            ("", result.Resolutions) ||> Seq.fold(fun acc r -> acc + @"#r @""" + r + "\"" + Environment.NewLine)

        let code = @"
$(REFERENCES)

open System
open System.IO
open System.Linq
406
open Microsoft.Data.Analysis
407 408 409 410 411 412 413 414 415 416 417

let Shuffle (arr:int[]) =
    let rnd = Random()
    for i in 0 .. arr.Length - 1 do
        let r = i + rnd.Next(arr.Length - i)
        let temp = arr.[r]
        arr.[r] <- arr.[i]
        arr.[i] <- temp
    arr

let housingPath = ""housing.csv""
418 419 420
let housingData = DataFrame.LoadCsv(housingPath)
let randomIndices = (Shuffle(Enumerable.Range(0, (int (housingData.Rows.Count) - 1)).ToArray()))
let testSize = int (float (housingData.Rows.Count) * 0.1)
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
let trainRows = randomIndices.[testSize..]
let testRows = randomIndices.[..testSize]
let housing_train = housingData.[trainRows]

open Microsoft.ML
open Microsoft.ML.Data
open Microsoft.ML.AutoML

let mlContext = MLContext()
let experiment = mlContext.Auto().CreateRegressionExperiment(maxExperimentTimeInSeconds = 15u)
let result = experiment.Execute(housing_train, labelColumnName = ""median_house_value"")
let details = result.RunDetails
printfn ""%A"" result
123
"
        let scriptText = code.Replace("$(REFERENCES)", referenceText)

        use script = new FSharpScript()
        let opt = script.Eval(scriptText)  |> getValue
        let value = opt.Value
K
Kevin Ransom (msft) 已提交
441
        Assert.Equal(123, value.ReflectionValue :?> int32)
442

K
Kevin Ransom (msft) 已提交
443
    [<Fact>]
D
Don Syme 已提交
444
    member _.``Use AssemblyResolver to resolve assemblies``() =
445
        let packagemanagerlines = [|
K
Kevin Ransom (msft) 已提交
446 447
            "r", "Microsoft.ML,version=1.4.0-preview"
            "r", "Microsoft.ML.AutoML,version=0.16.0-preview"
448
            "r", "Microsoft.Data.Analysis,version=0.4.0"
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
        |]

        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let mutable resolverPackageRoots = Seq.empty<string>
        let mutable resolverReferences = Seq.empty<string>

        let nativeProbingRoots () = resolverPackageRoots
        let assemblyProbingPaths () = resolverReferences

        // Restore packages, Get Reference dll paths and package roots
        let result =
466
            use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
467
            let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
468
            dp.Resolve(idm, ".fsx", packagemanagerlines, reportError, "net7.0")
469

K
Kevin Ransom (msft) 已提交
470
        Assert.True(result.Success, "resolve failed")
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501

        resolverPackageRoots <- result.Roots
        resolverReferences <- result.Resolutions

        use _assemblyResolver = new AssemblyResolveHandler(AssemblyResolutionProbe(assemblyProbingPaths))

        // Build and execute script
        let referenceText =
            ("", result.Resolutions)
            ||> Seq.fold(fun acc r ->
                acc + "    @\"" + r + "\";" + Environment.NewLine)

        let code = """
open System.Reflection

let x = [|
$(REFERENCES)
    |]

x |> Seq.iter(fun r ->
    let name = AssemblyName.GetAssemblyName(r)
    let asm = Assembly.Load(name)
    printfn "%A" (asm.FullName)
    )
123
"""
        let scriptText = code.Replace("$(REFERENCES)", referenceText)

        use script = new FSharpScript()
        let opt = script.Eval(scriptText)  |> getValue
        let value = opt.Value
K
Kevin Ransom (msft) 已提交
502
        Assert.Equal(123, value.ReflectionValue :?> int32)
503

K
Kevin Ransom (msft) 已提交
504
    [<Fact>]
D
Don Syme 已提交
505
    member _.``Verify that referencing FSharp.Core fails with FSharp Scripts``() =
K
Kevin Ransom (msft) 已提交
506
        let packagemanagerlines = [| "r", "FSharp.Core,version=4.7.1" |]
K
Kevin Ransom (msft) 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522

        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let mutable resolverPackageRoots = Seq.empty<string>
        let mutable resolverReferences = Seq.empty<string>

        let nativeProbingRoots () = resolverPackageRoots
        let assemblyProbingPaths () = resolverReferences

        // Restore packages, Get Reference dll paths and package roots
        let result =
523
            use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
K
Kevin Ransom (msft) 已提交
524
            let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
525
            dp.Resolve(idm, ".fsx", packagemanagerlines, reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
526 527

        // Expected: error FS3217: PackageManager can not reference the System Package 'FSharp.Core'
K
Kevin Ransom (msft) 已提交
528
        Assert.False(result.Success, "resolve succeeded but should have failed")
K
Kevin Ransom (msft) 已提交
529

K
Kevin Ransom (msft) 已提交
530
    [<Fact>]
D
Don Syme 已提交
531
    member _.``Verify that referencing FSharp.Core succeeds with CSharp Scripts``() =
K
Kevin Ransom (msft) 已提交
532
        let packagemanagerlines = [| "r", "FSharp.Core,version=4.7.1" |]
K
Kevin Ransom (msft) 已提交
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548

        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let mutable resolverPackageRoots = Seq.empty<string>
        let mutable resolverReferences = Seq.empty<string>

        let nativeProbingRoots () = resolverPackageRoots
        let assemblyProbingPaths () = resolverReferences

        // Restore packages, Get Reference dll paths and package roots
        let result =
549
            use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
K
Kevin Ransom (msft) 已提交
550
            let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
551
            dp.Resolve(idm, ".csx", packagemanagerlines, reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
552

K
Kevin Ransom (msft) 已提交
553
        Assert.True(result.Success, "resolve failed but should have succeeded")
K
Kevin Ransom (msft) 已提交
554

555

K
Kevin Ransom (msft) 已提交
556
    [<Fact>]
D
Don Syme 已提交
557
    member _.``Verify that Dispose on DependencyProvider unhooks ResolvingUnmanagedDll event handler``() =
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572

        let mutable found = false
        let nativeProbingRoots () =
            found <- true
            Seq.empty<string>

        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        // Set up native resolver to resolve dll's
        do
573
            use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
574 575 576

            // Invoking a non-existent dll via pinvoke cause a probe. which should invoke the call back
            try Native.NoneSuch() |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
577
            Assert.True (found, "Failed to invoke the nativeProbingRoots callback")
578 579 580 581

        // Here the dispose was invoked which should clear the ResolvingUnmanagedDll handler
        found <- false
        try Native.NoneSuch() |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
582
        Assert.False (found, "Invoke the nativeProbingRoots callback -- Error the ResolvingUnmanagedDll still fired ")
583 584 585 586 587

        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots))
        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")

        if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
K
Kevin Ransom (msft) 已提交
588
            let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"|], reportError, "net472")
K
Kevin Ransom (msft) 已提交
589 590 591
            Assert.Equal(true, result.Success)
            Assert.Equal(1, result.Resolutions |> Seq.length)
            Assert.Equal(1, result.SourceFiles |> Seq.length)
592
            Assert.Equal(2, result.Roots |> Seq.length)
593

K
Kevin Ransom (msft) 已提交
594
        let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"|], reportError, "net7.0")
K
Kevin Ransom (msft) 已提交
595 596 597 598
        Assert.Equal(true, result.Success)
        Assert.Equal(1, result.Resolutions |> Seq.length)
        Assert.Equal(1, result.SourceFiles |> Seq.length)
        Assert.Equal(1, result.Roots |> Seq.length)
599 600
        ()

601

K
Kevin Ransom (msft) 已提交
602
    [<Fact>]
D
Don Syme 已提交
603
    member _.``Verify that Dispose on DependencyProvider unhooks ResolvingUnmanagedDll and AssemblyResolver event handler``() =
604 605 606 607 608 609 610 611 612 613 614 615 616

        let mutable assemblyFound = false
        let assemblyProbingPaths () =
            assemblyFound <- true
            Seq.empty<string>

        let mutable nativeFound = false
        let nativeProbingRoots () =
            nativeFound <- true
            Seq.empty<string>

        // Set up native resolver to resolve dll's
        do
617
            use dp = new DependencyProvider(AssemblyResolutionProbe(assemblyProbingPaths), NativeResolutionProbe(nativeProbingRoots), false)
618 619 620

            // Invoking a non-existent dll via pinvoke cause a probe. which should invoke the call back
            try Native.NoneSuch() |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
621
            Assert.True (nativeFound, "Failed to invoke the nativeProbingRoots callback")
622 623 624

            // Invoking a non-existent assembly causes a probe. which should invoke the call back
            try Assembly.Load("NoneSuchAssembly") |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
625
            Assert.True (assemblyFound, "Failed to invoke the AssemblyResolve handler")
626 627 628 629 630 631

        // Here the dispose was invoked which should clear the ResolvingUnmanagedDll handler
        nativeFound <- false
        assemblyFound <- false

        try Native.NoneSuch() |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
632
        Assert.False (nativeFound, "Invoke the nativeProbingRoots callback -- Error the ResolvingUnmanagedDll still fired ")
633 634

        try Assembly.Load("NoneSuchAssembly") |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
635
        Assert.False (assemblyFound, "Invoke the assemblyProbingRoots callback -- Error the AssemblyResolve still fired ")
636 637
#endif

K
Kevin Ransom (msft) 已提交
638
    [<Fact>]
D
Don Syme 已提交
639
    member _.``Verify that Dispose on AssemblyResolveHandler unhooks AssemblyResolve event handler``() =
640 641 642 643 644 645 646 647 648 649 650 651

        let mutable assemblyFound = false
        let assemblyProbingPaths () =
            assemblyFound <- true
            Seq.empty<string>

        // Set up AssemblyResolver to resolve dll's
        do
            use dp = new AssemblyResolveHandler(AssemblyResolutionProbe(assemblyProbingPaths))

            // Invoking a non-existent assembly causes a probe. which should invoke the call back
            try Assembly.Load("NoneSuchAssembly") |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
652
            Assert.True (assemblyFound, "Failed to invoke the AssemblyResolve handler")
653 654 655 656 657

        // Here the dispose was invoked which should clear the ResolvingUnmanagedDll handler
        assemblyFound <- false

        try Assembly.Load("NoneSuchAssembly") |> ignore with _ -> ()
K
Kevin Ransom (msft) 已提交
658
        Assert.False (assemblyFound, "Invoke the assemblyProbingRoots callback -- Error the AssemblyResolve still fired ")
K
Kevin Ransom (msft) 已提交
659

660
    [<Fact>]
D
Don Syme 已提交
661
    member _.``Verify that Dispose cleans up the native paths added``() =
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
        let nativeProbingRoots () = Seq.empty<string>

        let appendSemiColon (p:string) =
            if not(p.EndsWith(";", StringComparison.OrdinalIgnoreCase)) then
                p + ";"
            else
                p

        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error -> printfn "PackageManagementError %d : %s" code message
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let mutable initialPath:string = null
        let mutable currentPath:string = null
        let mutable finalPath:string =  null
        do
            initialPath <- appendSemiColon (Environment.GetEnvironmentVariable("PATH"))
682
            use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
            let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
            let mutable currentPath:string = null
            if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
                let result = dp.Resolve(idm, ".fsx", [|"r", "Microsoft.Data.Sqlite,3.1.7"|], reportError, "netstandard2.0")
                Assert.Equal(true, result.Success)
                currentPath <-  appendSemiColon (Environment.GetEnvironmentVariable("PATH"))
        finalPath <- appendSemiColon (Environment.GetEnvironmentVariable("PATH"))
        Assert.True(currentPath <> initialPath)     // The path was modified by #r "nuget: ..."
        Assert.Equal(finalPath, initialPath)        // IDispose correctly cleaned up the path

        initialPath <- null
        currentPath <- null
        finalPath <-  null
        do
            initialPath <- appendSemiColon (Environment.GetEnvironmentVariable("PATH"))
            let mutable currentPath:string = null
699
            use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
700
            let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
701
            let result = dp.Resolve(idm, ".fsx", [|"r", "Microsoft.Data.Sqlite,3.1.7"|], reportError, "net7.0")
702 703 704 705 706 707 708
            Assert.Equal(true, result.Success)
            currentPath <-  appendSemiColon (Environment.GetEnvironmentVariable("PATH"))
        finalPath <- appendSemiColon (Environment.GetEnvironmentVariable("PATH"))
        Assert.True(currentPath <> initialPath)      // The path was modified by #r "nuget: ..."
        Assert.Equal(finalPath, initialPath)        // IDispose correctly cleaned up the path

        ()
K
Kevin Ransom (msft) 已提交
709

K
Kevin Ransom (msft) 已提交
710
    [<Fact>]
D
Don Syme 已提交
711
    member _.``Verify that #help produces help text for fsi + dependency manager``() =
K
Kevin Ransom (msft) 已提交
712 713 714
        let expected = [|
            """  F# Interactive directives:"""
            """"""
K
Kevin Ransom (msft) 已提交
715 716 717 718 719
            """    #r "file.dll";;                               // Reference (dynamically load) the given DLL"""
            """    #i "package source uri";;                     // Include package source uri when searching for packages"""
            """    #I "path";;                                   // Add the given search path for referenced DLLs"""
            """    #load "file.fs" ...;;                         // Load the given file(s) as if compiled and referenced"""
            """    #time ["on"|"off"];;                          // Toggle timing on/off"""
J
jkone27 已提交
720
            """    #clear;;                                      // Clear screen"""
K
Kevin Ransom (msft) 已提交
721 722
            """    #help;;                                       // Display help"""
            """    #quit;;                                       // Exit"""
K
Kevin Ransom (msft) 已提交
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
            """"""
            """  F# Interactive command line options:"""
            """"""

            // this is the end of the line each different platform has a different mechanism for starting fsi
            // Actual output looks similar to: """      See 'testhost --help' for options"""
            """--help' for options"""

            """"""
            """"""
        |]

        let mutable found = 0
        let lines = System.Collections.Generic.List()
        use sawExpectedOutput = new ManualResetEvent(false)
        let verifyOutput (line: string) =
            let compareLine (s: string) =
                if s = "" then line = ""
                else line.EndsWith(s)
            lines.Add(line)
            match expected |> Array.tryFind(compareLine) with
            | None -> ()
            | Some t ->
                found <- found + 1
                if found = expected.Length then sawExpectedOutput.Set() |> ignore

        let text = "#help"
        use output = new RedirectConsoleOutput()
        use script = new FSharpScript(quiet = false, langVersion = LangVersion.V47)
        let mutable found = 0
        output.OutputProduced.Add (fun line -> verifyOutput line)
        let opt = script.Eval(text) |> getValue
        Assert.True(sawExpectedOutput.WaitOne(TimeSpan.FromSeconds(5.0)), sprintf "Expected to see error sentinel value written\nexpected:%A\nactual:%A" expected lines)


K
Kevin Ransom (msft) 已提交
758
    [<Fact>]
D
Don Syme 已提交
759
    member _.``Verify that #help produces help text for fsi + dependency manager language version preview``() =
K
Kevin Ransom (msft) 已提交
760 761 762
        let expected = [|
            """  F# Interactive directives:"""
            """"""
K
Kevin Ransom (msft) 已提交
763 764 765 766 767 768 769 770
            """    #r "file.dll";;                               // Reference (dynamically load) the given DLL"""
            """    #i "package source uri";;                     // Include package source uri when searching for packages"""
            """    #I "path";;                                   // Add the given search path for referenced DLLs"""
            """    #load "file.fs" ...;;                         // Load the given file(s) as if compiled and referenced"""
            """    #time ["on"|"off"];;                          // Toggle timing on/off"""
            """    #help;;                                       // Display help"""
            """    #r "nuget:FSharp.Data, 3.1.2";;               // Load Nuget Package 'FSharp.Data' version '3.1.2'"""
            """    #r "nuget:FSharp.Data";;                      // Load Nuget Package 'FSharp.Data' with the highest version"""
J
jkone27 已提交
771
            """    #clear;;                                      // Clear screen"""
K
Kevin Ransom (msft) 已提交
772
            """    #quit;;                                       // Exit"""
K
Kevin Ransom (msft) 已提交
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
            """"""
            """  F# Interactive command line options:"""
            """"""

            // this is the end of the line each different platform has a different mechanism for starting fsi
            // Actual output looks similar to: """      See 'testhost --help' for options"""
            """--help' for options"""

            """"""
            """"""
        |]

        let mutable found = 0
        let lines = System.Collections.Generic.List()
        use sawExpectedOutput = new ManualResetEvent(false)
        let verifyOutput (line: string) =
            let compareLine (s: string) =
                if s = "" then line = ""
                else line.EndsWith(s)
            lines.Add(line)
            match expected |> Array.tryFind(compareLine) with
            | None -> ()
            | Some t ->
                found <- found + 1
                if found = expected.Length then sawExpectedOutput.Set() |> ignore

        let text = "#help"
        use output = new RedirectConsoleOutput()
        use script = new FSharpScript(quiet = false, langVersion = LangVersion.Preview)
        let mutable found = 0
        output.OutputProduced.Add (fun line -> verifyOutput line)
        let opt = script.Eval(text) |> getValue
        Assert.True(sawExpectedOutput.WaitOne(TimeSpan.FromSeconds(5.0)), sprintf "Expected to see error sentinel value written\nexpected:%A\nactual:%A" expected lines)
806 807 808


    [<Fact>]
D
Don Syme 已提交
809
    member _.``Verify that timeout --- times out and fails``() =
810 811 812 813
        let nativeProbingRoots () = Seq.empty<string>
        let mutable foundCorrectError = false
        let mutable foundWrongError = false

814
        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
815 816 817 818
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error ->
819
                    if code = 999 then foundCorrectError <- true
820 821 822 823 824
                    else foundWrongError <- true
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
825
        let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"|], reportError, "net7.0", timeout=0)           // Fail in 0 milliseconds
826 827 828 829 830 831
        Assert.Equal(false, result.Success)
        Assert.Equal(foundCorrectError, true)
        Assert.Equal(foundWrongError, false)
        ()

    [<Fact>]
D
Don Syme 已提交
832
    member _.``Verify that script based timeout overrides api based - timeout on script``() =
833 834 835 836
        let nativeProbingRoots () = Seq.empty<string>
        let mutable foundCorrectError = false
        let mutable foundWrongError = false

837
        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
838 839 840 841
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error ->
842
                    if code = 999 then foundCorrectError <- true
843 844 845 846 847
                    else foundWrongError <- true
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
848
        let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"; "r", "timeout=0"|], reportError, "net7.0", null, "", "", "", -1)           // Wait forever
849 850 851 852 853 854
        Assert.Equal(false, result.Success)
        Assert.Equal(foundCorrectError, true)
        Assert.Equal(foundWrongError, false)
        ()

    [<Fact>]
D
Don Syme 已提交
855
    member _.``Verify that script based timeout overrides api based - timeout on api , forever on script``() =
856 857 858 859
        let nativeProbingRoots () = Seq.empty<string>
        let mutable foundCorrectError = false
        let mutable foundWrongError = false

860
        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), false)
861 862 863 864 865 866 867 868 869 870
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error ->
                    if code = 3401 then foundCorrectError <- true
                    else foundWrongError <- true
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")
K
Kevin Ransom (msft) 已提交
871
        let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"; "r", "timeout=none"|], reportError, "net7.0", null, "", "", "", -1)           // Wait forever
872 873 874 875 876
        Assert.Equal(true, result.Success)
        Assert.Equal(foundCorrectError, false)
        Assert.Equal(foundWrongError, false)
        ()

877 878 879 880 881 882 883 884 885 886 887 888
        
    [<Fact>]
    member _.``Verify that clear cache doesn't fail and clears the cache``() =
        let nativeProbingRoots () = Seq.empty<string>
        let mutable foundCorrectError = false
        let mutable foundWrongError = false

        use dp = new DependencyProvider(NativeResolutionProbe(nativeProbingRoots), true)
        let reportError =
            let report errorType code message =
                match errorType with
                | ErrorReportType.Error ->
889
                    if code = 999 then foundCorrectError <- true
890 891 892 893 894 895 896
                    else foundWrongError <- true
                | ErrorReportType.Warning -> printfn "PackageManagementWarning %d : %s" code message
            ResolvingErrorReport (report)

        let idm = dp.TryFindDependencyManagerByKey(Seq.empty, "", reportError, "nuget")

        // Resolve and cache the results won't time out
K
Kevin Ransom (msft) 已提交
897
        let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"; "r", "timeout=10000"|], reportError, "net7.0", null, "", "", "", -1)           // Wait forever
898 899 900 901 902 903 904 905

        // Clear the results
        foundCorrectError <- false
        foundWrongError <- false

        // Now clear the cache --- this will ensure that resolving produces a timeout error.  If we read from the cache the test will fail
        dp.ClearResultsCache(Seq.empty, "", reportError)

K
Kevin Ransom (msft) 已提交
906
        let result = dp.Resolve(idm, ".fsx", [|"r", "FSharp.Data,3.3.3"; "r", "timeout=0"|], reportError, "net7.0", null, "", "", "", -1)           // Wait forever
907 908 909 910
        Assert.Equal(false, result.Success)
        Assert.Equal(foundCorrectError, true)
        Assert.Equal(foundWrongError, false)
        ()
911