-
Notifications
You must be signed in to change notification settings - Fork 789
/
Tests.LanguageService.Script.fs
1674 lines (1486 loc) · 82.7 KB
/
Tests.LanguageService.Script.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
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
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace Tests.LanguageService.Script
open System
open System.IO
open System.Reflection
open NUnit.Framework
open Salsa.Salsa
open Salsa.VsOpsUtils
open UnitTests.TestLib.Salsa
open UnitTests.TestLib.Utils
open UnitTests.TestLib.LanguageService
open UnitTests.TestLib.ProjectSystem
[<TestFixture>]
[<Category "LanguageService">]
type UsingMSBuild() as this =
inherit LanguageServiceBaseTests()
let notAA l = None,l
let createSingleFileFsx (code : string) =
let (_, p, f) = this.CreateSingleFileProject(code, fileKind = SourceFileKind.FSX)
(p, f)
let createSingleFileFsxFromLines (code : string list) =
let (_, p, f) = this.CreateSingleFileProject(code, fileKind = SourceFileKind.FSX)
(p, f)
(* Timings ----------------------------------------------------------------------------- *)
let stopWatch = new System.Diagnostics.Stopwatch()
let ResetStopWatch() = stopWatch.Reset(); stopWatch.Start()
let time1 op a message =
ResetStopWatch()
let result = op a
printf "%s %d ms\n" message stopWatch.ElapsedMilliseconds
result
let ShowErrors(project:OpenProject) =
for error in (GetErrors(project)) do
printf "%s\n" (error.ToString())
let AssertListContainsInOrder(s:string list,cs:string list) =
let s : string array = Array.ofList s
let s : string = String.Join("\n",s)
AssertContainsInOrder(s,cs)
/// Assert that there is no squiggle.
let AssertNoSquiggle(squiggleOption) =
match squiggleOption with
| None -> ()
| Some(severity,message) ->
Assert.Fail(sprintf "Expected no squiggle but got '%A' with message: %s" severity message)
let VerifyErrorListContainedExpectedStr(expectedStr:string,project : OpenProject) =
let errorList = GetErrors(project)
let GetErrorMessages(errorList : Error list) =
[ for i = 0 to errorList.Length - 1 do
yield errorList.[i].Message]
Assert.IsTrue(errorList
|> GetErrorMessages
|> Seq.exists (fun errorMessage ->
errorMessage.Contains(expectedStr)))
let AssertNoErrorsOrWarnings(project:OpenProject) =
let count = List.length (GetErrors(project))
if count<>0 then
printf "Saw %d errors and expected none.\n" count
printf "Errors are: \n"
for e in GetErrors project do
printf " path = <<<%s>>>\n" e.Path
printf " message = <<<%s> \n" e.Message
AssertEqual(0,count)
let AssertExactlyCountErrorSeenContaining(project:OpenProject,text,expectedCount) =
let nMatching = (GetErrors(project)) |> List.filter (fun e ->e.ToString().Contains(text)) |> List.length
match nMatching with
| 0 ->
failwith (sprintf "No errors containing \"%s\"" text)
| x when x = expectedCount -> ()
| _ ->
failwith (sprintf "Multiple errors containing \"%s\"" text)
let AssertExactlyOneErrorSeenContaining(project:OpenProject,text) =
AssertExactlyCountErrorSeenContaining(project,text,1)
/// Assert that a given squiggle is an Error (or warning) containing the given text
let AssertSquiggleIsErrorContaining,AssertSquiggleIsWarningContaining, AssertSquiggleIsErrorNotContaining,AssertSquiggleIsWarningNotContaining =
let AssertSquiggle expectedSeverity nameOfExpected nameOfNotExpected assertf (squiggleOption,containing) =
match squiggleOption with
| None -> Assert.Fail("Expected a squiggle but none was seen.")
| Some(severity,message) ->
Assert.IsTrue((severity=expectedSeverity), sprintf "Expected %s but saw %s: %s" nameOfExpected nameOfNotExpected message)
assertf(message,containing)
AssertSquiggle Microsoft.VisualStudio.FSharp.LanguageService.Severity.Error "Error" "Warning" AssertContains,
AssertSquiggle Microsoft.VisualStudio.FSharp.LanguageService.Severity.Warning "Warning" "Error" AssertContains,
AssertSquiggle Microsoft.VisualStudio.FSharp.LanguageService.Severity.Error "Error" "Warning" AssertNotContains,
AssertSquiggle Microsoft.VisualStudio.FSharp.LanguageService.Severity.Warning "Warning" "Error" AssertNotContains
//Verify the error list in fsx file contained the expected string
member private this.VerifyFSXErrorListContainedExpectedString(fileContents : string, expectedStr : string) =
let (_, project, file) = this.CreateSingleFileProject(fileContents, fileKind = SourceFileKind.FSX)
VerifyErrorListContainedExpectedStr(expectedStr,project)
//Verify no error list in fsx file
member private this.VerifyFSXNoErrorList(fileContents : string) =
let (_, project, file) = this.CreateSingleFileProject(fileContents, fileKind = SourceFileKind.FSX)
AssertNoErrorsOrWarnings(project)
//Verify QuickInfo Contained In Fsx file
member public this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile (code : string) marker expected =
let (_, _, file) = this.CreateSingleFileProject(code, fileKind = SourceFileKind.FSX)
MoveCursorToEndOfMarker(file, marker)
let tooltip = GetQuickInfoAtCursor file
AssertContains(tooltip, expected)
//Verify QuickInfo Contained In Fsx file
member public this.AssertQuickInfoContainsAtStartOfMarkerInFsxFile (code : string) marker expected =
let (_, _, file) = this.CreateSingleFileProject((code : string), fileKind = SourceFileKind.FSX)
MoveCursorToStartOfMarker(file, marker)
let tooltip = GetQuickInfoAtCursor file
AssertContains(tooltip, expected)
//Verify QuickInfo Not Contained In Fsx file
member public this.AssertQuickInfoNotContainsAtEndOfMarkerInFsxFile code marker notexpected =
let (_, _, file) = this.CreateSingleFileProject((code : string), fileKind = SourceFileKind.FSX)
MoveCursorToEndOfMarker(file, marker)
let tooltip = GetQuickInfoAtCursor file
AssertNotContains(tooltip, notexpected)
/// There was a problem with Salsa that caused squiggles not to be shown for .fsx files.
[<Test>]
member public this.``Fsx.Squiggles.ShowInFsxFiles``() =
let fileContent = """open Thing1.Thing2"""
this.VerifyFSXErrorListContainedExpectedString(fileContent,"Thing1")
/// Regression test for FSharp1.0:4861 - #r to nonexistent file causes the first line to be squiggled
/// There was a problem with Salsa that caused squiggles not to be shown for .fsx files.
[<Test>]
member public this.``Fsx.Hash.RProperSquiggleForNonExistentFile``() =
let fileContent = """#r "NonExistent" """
this.VerifyFSXErrorListContainedExpectedString(fileContent,"was not found or is invalid")
/// Nonexistent hash. There was a problem with Salsa that caused squiggles not to be shown for .fsx files.
[<Test>]
member public this.``Fsx.Hash.RDoesNotExist.Bug3325``() =
let fileContent = """#r "ThisDLLDoesNotExist" """
this.VerifyFSXErrorListContainedExpectedString(fileContent,"'ThisDLLDoesNotExist' was not found or is invalid")
// There was a spurious error message on the first line.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ExactlyOneError.Bug4861``() =
let code =
["#light" // First line is important in this repro
"#r \"Nonexistent\""
]
let (project, _) = createSingleFileFsxFromLines code
AssertExactlyCountErrorSeenContaining(project, "Nonexistent", 1) // ...and not an error on the first line.
[<Test>]
member public this.``Fsx.InvalidHashLoad.ShouldBeASquiggle.Bug3012``() =
let fileContent = """
#light
#load "Bar.fs"
"""
this.VerifyFSXErrorListContainedExpectedString(fileContent,"Bar.fs")
// Transitive to existing property.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ScriptClosure.TransitiveLoad1``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public Property = 0"
])
let file1 = OpenFile(project,"File1.fs")
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"File1.fs\""
])
let script2 = OpenFile(project,"Script2.fsx")
let script2 = AddFileFromText(project,"Script1.fsx",
["#load \"Script1.fsx\""
"Namespace.Foo.Property"
])
let script2 = OpenFile(project,"Script2.fsx")
TakeCoffeeBreak(this.VS)
AssertNoErrorsOrWarnings(project)
// Transitive to nonexisting property.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ScriptClosure.TransitiveLoad2``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public Property = 0"
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"File1.fs\""
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"Script2.fsx\""
"Namespace.Foo.NonExistingProperty"
])
let script1 = OpenFile(project,"Script1.fsx")
TakeCoffeeBreak(this.VS)
AssertExactlyOneErrorSeenContaining(project, "NonExistingProperty")
/// FEATURE: Typing a #r into a file will cause it to be recognized by intellisense.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.HashR.AddedIn``() =
let code =
["#light"
"//#r \"System.Transactions.dll\"" // Pick anything that isn't in the standard set of assemblies.
"open System.Transactions"
]
let (project, file) = createSingleFileFsxFromLines code
VerifyErrorListContainedExpectedStr("Transactions",project)
let gpatcc = GlobalParseAndTypeCheckCounter.StartNew(this.VS)
ReplaceFileInMemory file
["#light"
"#r \"System.Transactions.dll\"" // <-- Uncomment this line
"open System.Transactions"
]
AssertNoErrorsOrWarnings(project)
gpatcc.AssertExactly(notAA[file],notAA[file], true (* expectCreate, because dependent DLL set changed *))
// FEATURE: Adding a #load to a file will cause types from that file to be visible in intellisense
[<Test>]
member public this.``Fsx.HashLoad.Added``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let fs = AddFileFromText(project,"File1.fs",
["#light"
"namespace MyNamespace"
" module MyModule ="
" let x = 1"
])
let fsx = AddFileFromText(project,"File2.fsx",
["#light"
"//#load \"File1.fs\""
"open MyNamespace.MyModule"
"printfn \"%d\" x"
])
let fsx = OpenFile(project,"File2.fsx")
VerifyErrorListContainedExpectedStr("MyNamespace",project)
ReplaceFileInMemory fsx
["#light"
"#load \"File1.fs\""
"open MyNamespace.MyModule"
"printfn \"%d\" x"
]
TakeCoffeeBreak(this.VS)
AssertNoErrorsOrWarnings(project)
// FEATURE: Removing a #load to a file will cause types from that file to no longer be visible in intellisense
[<Test>]
member public this.``Fsx.HashLoad.Removed``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let fs = AddFileFromText(project,"File1.fs",
["#light"
"namespace MyNamespace"
" module MyModule ="
" let x = 1"
])
let fsx = AddFileFromText(project,"File2.fsx",
["#light"
"#load \"File1.fs\""
"open MyNamespace.MyModule"
"printfn \"%d\" x"
])
let fsx = OpenFile(project,"File2.fsx")
AssertNoErrorsOrWarnings(project)
ReplaceFileInMemory fsx
["#light"
"//#load \"File1.fs\""
"open MyNamespace.MyModule"
"printfn \"%d\" x"
]
TakeCoffeeBreak(this.VS)
VerifyErrorListContainedExpectedStr("MyNamespace",project)
[<Test>]
member public this.``Fsx.HashLoad.Conditionals``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let fs = AddFileFromText(project,"File1.fs",
["module InDifferentFS"
"#if INTERACTIVE"
"let x = 1"
"#else"
"let y = 2"
"#endif"
"#if DEBUG"
"let A = 3"
"#else"
"let B = 4"
"#endif"
])
let fsx = AddFileFromText(project,"File2.fsx",
[
"#load \"File1.fs\""
"InDifferentFS."
])
let fsx = OpenFile(project,"File2.fsx")
MoveCursorToEndOfMarker(fsx, "InDifferentFS.")
let completion = AutoCompleteAtCursor fsx
let completion = completion |> Array.map (fun (CompletionItem(name, _, _, _, _)) -> name) |> set
Assert.AreEqual(Set.count completion, 2, "Expected 2 elements in the completion list")
Assert.IsTrue(completion.Contains "x", "Completion list should contain x because INTERACTIVE is defined")
Assert.IsTrue(completion.Contains "B", "Completion list should contain B because DEBUG is not defined")
/// FEATURE: Removing a #r into a file will cause it to no longer be seen by intellisense.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.HashR.Removed``() =
let code =
["#light"
"#r \"System.Transactions.dll\"" // Pick anything that isn't in the standard set of assemblies.
"open System.Transactions"
]
let (project, file) = createSingleFileFsxFromLines code
TakeCoffeeBreak(this.VS)
AssertNoErrorsOrWarnings(project)
let gpatcc = GlobalParseAndTypeCheckCounter.StartNew(this.VS)
ReplaceFileInMemory file
["#light"
"//#r \"System.Transactions.dll\"" // <-- Comment this line
"open System.Transactions"
]
SaveFileToDisk(file)
TakeCoffeeBreak(this.VS)
VerifyErrorListContainedExpectedStr("Transactions",project)
gpatcc.AssertExactly(notAA[file], notAA[file], true (* expectCreate, because dependent DLL set changed *))
// Corecursive load to existing property.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.ScriptClosure.TransitiveLoad3``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public Property = 0"
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"Script1.fsx\""
"#load \"File1.fs\""
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"Script2.fsx\""
"#load \"File1.fs\""
"Namespace.Foo.Property"
])
let script1 = OpenFile(project,"Script1.fsx")
TakeCoffeeBreak(this.VS)
AssertNoErrorsOrWarnings(project)
// #load of .fsi is respected (for non-hidden property)
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.ScriptClosure.TransitiveLoad9``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fsi\""
"#load \"File1.fs\""
"Namespace.Foo.Property"
])
let script1 = OpenFile(project,"Script1.fsx")
AssertNoErrorsOrWarnings(project)
// #load of .fsi is respected at second #load level (for non-hidden property)
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.ScriptClosure.TransitiveLoad10``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fsi\""
"#load \"File1.fs\""
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"Script1.fsx\""
"Namespace.Foo.Property"
])
let script2 = OpenFile(project,"Script2.fsx")
AssertNoErrorsOrWarnings(project)
// #load of .fsi is respected when dispersed between two #load levels (for non-hidden property)
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.ScriptClosure.TransitiveLoad11``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fsi\""
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"Script1.fsx\""
"#load \"File1.fs\""
"Namespace.Foo.Property"
])
let script2 = OpenFile(project,"Script2.fsx")
AssertNoErrorsOrWarnings(project)
// #load of .fsi is respected when dispersed between two #load levels (the other way) (for non-hidden property)
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.ScriptClosure.TransitiveLoad12``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fs\""
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"File1.fsi\""
"#load \"Script1.fsx\""
"Namespace.Foo.Property"
])
let script2 = OpenFile(project,"Script2.fsx")
AssertNoErrorsOrWarnings(project)
// #nowarn seen in closed .fsx is global to the closure
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.ScriptClosure.TransitiveLoad16``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let thisProject = AddFileFromText(project,"ThisProject.fsx",
["#nowarn \"44\""
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"ThisProject.fsx\"" // Should bring in #nowarn "44" so we don't see this warning:
"[<System.Obsolete(\"x\")>]"
"let fn x = 0"
"let y = fn 1"
])
let script1 = OpenFile(project,"Script1.fsx")
MoveCursorToEndOfMarker(script1,"let y = f")
TakeCoffeeBreak(this.VS)
AssertNoErrorsOrWarnings(project)
/// FEATURE: #r in .fsx to a .dll name works.
[<Test>]
member public this.``Fsx.NoError.HashR.DllWithNoPath``() =
let fileContent = """
#light
#r "System.Transactions.dll"
open System.Transactions"""
this.VerifyFSXNoErrorList(fileContent)
[<Test>]
// 'System' is in the default set. Make sure we can still resolve it.
member public this.``Fsx.NoError.HashR.BugDefaultReferenceFileIsAlsoResolved``() =
let fileContent = """
#light
#r "System"
"""
this.VerifyFSXNoErrorList(fileContent)
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.HashR.DoubleReference``() =
let fileContent = """
#light
#r "System"
#r "System"
"""
this.VerifyFSXNoErrorList(fileContent)
[<Test>]
[<Category("fsx closure")>]
// 'CustomMarshalers' is loaded from the GAC _and_ it is available on XP and above.
member public this.``Fsx.NoError.HashR.ResolveFromGAC``() =
let fileContent = """
#light
#r "CustomMarshalers"
"""
this.VerifyFSXNoErrorList(fileContent)
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoError.HashR.ResolveFromFullyQualifiedPath``() =
let fullyqualifiepathtoddll = System.IO.Path.Combine( System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), "System.configuration.dll" )
let code = ["#light";"#r @\"" + fullyqualifiepathtoddll + "\""]
let (project, _) = createSingleFileFsxFromLines code
AssertNoErrorsOrWarnings(project)
[<Test>]
[<Category("fsx closure")>]
[<Ignore("Re-enable this test --- https://github.com/dotnet/fsharp/issues/5238")>]
member public this.``Fsx.NoError.HashR.RelativePath1``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1 = AddFileFromText(project,"lib.fs",
["module Lib"
"let X = 42"
])
let bld = Build(project)
let script1Dir = Path.Combine(ProjectDirectory(project), "ccc")
let script1Path = Path.Combine(script1Dir, "Script1.fsx")
let script2Dir = Path.Combine(ProjectDirectory(project), "aaa\\bbb")
let script2Path = Path.Combine(script2Dir, "Script2.fsx")
Directory.CreateDirectory(script1Dir) |> ignore
Directory.CreateDirectory(script2Dir) |> ignore
File.Move(bld.ExecutableOutput, Path.Combine(ProjectDirectory(project), "aaa\\lib.exe"))
let script1 = File.WriteAllLines(script1Path,
["#load \"../aaa/bbb/Script2.fsx\""
"printfn \"%O\" Lib.X"
])
let script2 = File.WriteAllLines(script2Path,
["#r \"../lib.exe\""
])
let script1 = OpenFile(project, script1Path)
TakeCoffeeBreak(this.VS)
MoveCursorToEndOfMarker(script1,"#load")
let ans = GetSquiggleAtCursor(script1)
AssertNoSquiggle(ans)
[<Test; Category("fsx closure")>]
[<Ignore("Re-enable this test --- https://github.com/dotnet/fsharp/issues/5238")>]
member public this.``Fsx.NoError.HashR.RelativePath2``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1 = AddFileFromText(project,"lib.fs",
["module Lib"
"let X = 42"
])
let bld = Build(project)
let script1Dir = Path.Combine(ProjectDirectory(project), "ccc")
let script1Path = Path.Combine(script1Dir, "Script1.fsx")
let script2Dir = Path.Combine(ProjectDirectory(project), "aaa")
let script2Path = Path.Combine(script2Dir, "Script2.fsx")
Directory.CreateDirectory(script1Dir) |> ignore
Directory.CreateDirectory(script2Dir) |> ignore
File.Move(bld.ExecutableOutput, Path.Combine(ProjectDirectory(project), "aaa\\lib.exe"))
let script1 = File.WriteAllLines(script1Path,
["#load \"../aaa/Script2.fsx\""
"printfn \"%O\" Lib.X"
])
let script2 = File.WriteAllLines(script2Path,
["#r \"lib.exe\""
])
let script1 = OpenFile(project, script1Path)
TakeCoffeeBreak(this.VS)
MoveCursorToEndOfMarker(script1,"#load")
let ans = GetSquiggleAtCursor(script1)
AssertNoSquiggle(ans)
/// FEATURE: #load in an .fsx file will include that file in the 'build' of the .fsx.
[<Test>]
member public this.``Fsx.NoError.HashLoad.Simple``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let fs = AddFileFromText(project,"File1.fs",
["#light"
"namespace MyNamespace"
" module MyModule ="
" let x = 1"
])
let fsx = AddFileFromText(project,"File2.fsx",
["#light"
"#load \"File1.fs\""
"open MyNamespace.MyModule"
"printfn \"%d\" x"
])
let fsx = OpenFile(project,"File2.fsx")
AssertNoErrorsOrWarnings(project)
// In this bug the #loaded file contains a level-4 warning (copy to avoid mutation). This warning was reported at the #load in file2.fsx but shouldn't have been.s
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.NoWarn.OnLoadedFile.Bug4837``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let fs = AddFileFromText(project,"File1.fs",
["module File1Module"
"let x = System.DateTime.Now - System.DateTime.Now"
"x.Add(x) |> ignore"
])
let fsx = AddFileFromText(project,"File2.fsx",
[
"#load \"File1.fs\""
])
let fsx = OpenFile(project,"File2.fsx")
AssertNoErrorsOrWarnings(project)
/// FEATURE: .fsx files have automatic imports of certain system assemblies.
//There is a test bug here. The actual scenario works. Need to revisit.
[<Test>]
[<Category("ReproX")>]
member public this.``Fsx.NoError.AutomaticImportsForFsxFiles``() =
let fileContent = """
#light
open System
open System.Xml
open System.Drawing
open System.Runtime.Remoting
open System.Runtime.Serialization.Formatters.Soap
open System.Data
open System.Drawing
open System.Web
open System.Web.Services
open System.Windows.Forms"""
this.VerifyFSXNoErrorList(fileContent)
// Corecursive load to nonexisting property.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ExactlyOneError.ScriptClosure.TransitiveLoad4``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public Property = 0"
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"Script1.fsx\""
"#load \"File1.fs\""
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"Script2.fsx\""
"#load \"File1.fs\""
"Namespace.Foo.NonExistingProperty"
])
let script1 = OpenFile(project,"Script1.fsx")
AssertExactlyOneErrorSeenContaining(project, "NonExistingProperty")
// #load of .fsi is respected
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ExactlyOneError.ScriptClosure.TransitiveLoad5``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fsi\""
"#load \"File1.fs\""
"Namespace.Foo.HiddenProperty"
])
let script1 = OpenFile(project,"Script1.fsx")
AssertExactlyOneErrorSeenContaining(project, "HiddenProperty")
// #load of .fsi is respected at second #load level
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ExactlyOneError.ScriptClosure.TransitiveLoad6``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fsi\""
"#load \"File1.fs\""
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"Script1.fsx\""
"Namespace.Foo.HiddenProperty"
])
let script2 = OpenFile(project,"Script2.fsx")
AssertExactlyOneErrorSeenContaining(project, "HiddenProperty")
// #load of .fsi is respected when dispersed between two #load levels
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ExactlyOneError.ScriptClosure.TransitiveLoad7``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fsi\""
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"Script1.fsx\""
"#load \"File1.fs\""
"Namespace.Foo.HiddenProperty"
])
let script2 = OpenFile(project,"Script2.fsx")
AssertExactlyOneErrorSeenContaining(project, "HiddenProperty")
// #load of .fsi is respected when dispersed between two #load levels (the other way)
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ExactlyOneError.ScriptClosure.TransitiveLoad8``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file1fsi = AddFileFromText(project,"File1.fsi",
["namespace Namespace"
"type Foo ="
" class"
" static member Property : int" // Not exposing 'HiddenProperty'
" end"
])
let file1 = AddFileFromText(project,"File1.fs",
["namespace Namespace"
"type Foo = "
" static member public HiddenProperty = 0"
" static member public Property = 0"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fs\""
])
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"File1.fsi\""
"#load \"Script1.fsx\""
"Namespace.Foo.HiddenProperty"
])
let script2 = OpenFile(project,"Script2.fsx")
AssertExactlyOneErrorSeenContaining(project, "HiddenProperty")
// Bug seen during development: A #load in an .fs would be followed.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ExactlyOneError.ScriptClosure.TransitiveLoad15``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let file2 = AddFileFromText(project,"File2.fs",
["namespace Namespace"
"type Type() ="
" static member Property = 0"
])
let file1 = AddFileFromText(project,"File1.fs",
["#load \"File2.fs\"" // This is not allowed but it was working anyway.
"namespace File2Namespace"
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"File1.fs\""
"Namespace.Type.Property"
])
let script1 = OpenFile(project,"Script1.fsx")
TakeCoffeeBreak(this.VS)
AssertExactlyOneErrorSeenContaining(project, "Namespace")
[<Test>]
member public this.``Fsx.Bug4311HoverOverReferenceInFirstLine``() =
let fileContent = """#r "PresentationFramework.dll"
#r "PresentationCore.dll" """
let marker = "#r \"PresentationFrame"
this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile fileContent marker "PresentationFramework.dll"
this.AssertQuickInfoNotContainsAtEndOfMarkerInFsxFile fileContent marker "multiple results"
[<Test>]
member public this.``Fsx.QuickInfo.Bug4979``() =
let code =
["System.ConsoleModifiers.Shift |> ignore "
"(3).ToString().Length |> ignore "]
let (project, file) = createSingleFileFsxFromLines code
MoveCursorToEndOfMarker(file, "System.ConsoleModifiers.Sh")
let tooltip = GetQuickInfoAtCursor file
AssertContains(tooltip, @"<summary>The left or right SHIFT modifier key.</summary>")
MoveCursorToEndOfMarker(file, "(3).ToString().Len")
let tooltip = GetQuickInfoAtCursor file
AssertContains(tooltip, @"[Signature:P:System.String.Length]") // A message from the mock IDocumentationBuilder
AssertContains(tooltip, @"[Filename:")
AssertContains(tooltip, @"netstandard.dll]") // The assembly we expect the documentation to get taken from
// Especially under 4.0 we need #r of .NET framework assemblies to resolve from like,
//
// %program files%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
//
// because this is where the .XML files are.
//
// When executing scripts, however, we need to _not_ resolve from these directories because
// they may be metadata-only assemblies.
//
// "Reference Assemblies" was only introduced in 3.5sp1, so not all 2.0 F# boxes will have it, so only run on 4.0
[<Test>]
member public this.``Fsx.Bug5073``() =
let fileContent = """#r "System" """
let marker = "#r \"System"
this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile fileContent marker @"Reference Assemblies\Microsoft"
this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile fileContent marker ".NET Framework"
/// FEATURE: Hovering over a resolved #r file will show a data tip with the fully qualified path to that file.
[<Test>]
member public this.``Fsx.HashR_QuickInfo.ShowFilenameOfResolvedAssembly``() =
this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile
"""#r "System.Transactions" """ // Pick anything that isn't in the standard set of assemblies.
"#r \"System.Tra" "System.Transactions.dll"
[<Test>]
member public this.``Fsx.HashR_QuickInfo.BugDefaultReferenceFileIsAlsoResolved``() =
this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile
"""#r "System" """ // 'System' is in the default set. Make sure we can still resolve it.
"#r \"Syst" "System.dll"
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.HashR_QuickInfo.DoubleReference``() =
let fileContent = """#r "System" // Mark1
#r "System" // Mark2 """ // The same reference repeated twice.
this.AssertQuickInfoContainsAtStartOfMarkerInFsxFile fileContent "tem\" // Mark1" "System.dll"
this.AssertQuickInfoContainsAtStartOfMarkerInFsxFile fileContent "tem\" // Mark2" "System.dll"
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.HashR_QuickInfo.ResolveFromGAC``() =
this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile
"""#r "CustomMarshalers" """ // 'mscorcfg' is loaded from the GAC _and_ it is available on XP and above.
"#r \"Custo" ".NET Framework"
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.HashR_QuickInfo.ResolveFromFullyQualifiedPath``() =
let fullyqualifiepathtoddll = System.IO.Path.Combine( System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), "System.configuration.dll" ) // Can be any fully qualified path to an assembly
let expectedtooltip = System.Reflection.Assembly.ReflectionOnlyLoadFrom(fullyqualifiepathtoddll).FullName
let fileContent = "#r @\"" + fullyqualifiepathtoddll + "\""
let marker = "#r @\"" + fullyqualifiepathtoddll.Substring(0,fullyqualifiepathtoddll.Length/2) // somewhere in the middle of the string
this.AssertQuickInfoContainsAtEndOfMarkerInFsxFile fileContent marker expectedtooltip
//this.AssertQuickInfoNotContainsAtEndOfMarkerInFsxFile fileContent marker ".dll"
[<Test>]
member public this.``Fsx.InvalidHashReference.ShouldBeASquiggle.Bug3012``() =
let code =
["#light"
"#r \"Bar.dll\""]
let (project, file) = createSingleFileFsxFromLines code
MoveCursorToEndOfMarker(file,"#r \"Ba")
let squiggle = GetSquiggleAtCursor(file)
TakeCoffeeBreak(this.VS)
Assert.IsTrue(snd squiggle.Value |> fun str -> str.Contains("Bar.dll"))
// Bug seen during development: The unresolved reference error would x-ray through to the root.
[<Test>]
[<Category("fsx closure")>]
member public this.``Fsx.ScriptClosure.TransitiveLoad14``() =
use _guard = this.UsingNewVS()
let solution = this.CreateSolution()
let project = CreateProject(solution,"testproject")
let script2 = AddFileFromText(project,"Script2.fsx",
["#load \"Script1.fsx\""
"#r \"NonExisting\""
])
let script1 = AddFileFromText(project,"Script1.fsx",
["#load \"Script2.fsx\""
"#r \"System\""
])
let script1 = OpenFile(project,"Script1.fsx")