-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtargets.fsx
3713 lines (3242 loc) · 156 KB
/
targets.fsx
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
open System
open System.Diagnostics.Tracing
open System.IO
open System.Reflection
open System.Xml
open System.Xml.Linq
open Actions
open AltCode.Fake.DotNet
open AltCover_Fake.DotNet.DotNet
open AltCover_Fake.DotNet.Testing
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.DotNet.NuGet.NuGet
open Fake.DotNet.Testing.NUnit3
open Fake.Testing
open Fake.DotNet.Testing
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing
open Fake.IO.Globbing.Operators
open FSharpLint.Application
open FSharpLint.Framework
open NUnit.Framework
let Copyright = ref String.Empty
let Version = ref String.Empty
let consoleBefore = (Console.ForegroundColor, Console.BackgroundColor)
let OpenCoverFilter = "+[AltCove*]* -[*]Microsoft.* -[*]System.* +[*]N.*"
let AltCoverFilter(p : Primitive.PrepareParams) =
{ p with MethodFilter = "WaitForExitCustom" :: (p.MethodFilter |> Seq.toList)
AssemblyExcludeFilter =
[ "Adapter"; "Tests" ] @ (p.AssemblyExcludeFilter |> Seq.toList)
AssemblyFilter =
[ "Mono"; @"\.Recorder"; @"\.DataCollector"; "Sample"; "nunit"; "Newton"; "xunit"; "BlackFox" ]
@ (p.AssemblyFilter |> Seq.toList)
TypeFilter = [ @"System\."; @"Sample3\.Class2" ] @ (p.TypeFilter |> Seq.toList) }
let AltCoverFilterX(p : Primitive.PrepareParams) =
{ p with MethodFilter = "WaitForExitCustom" :: (p.MethodFilter |> Seq.toList)
AssemblyExcludeFilter = "Adapter" :: (p.AssemblyExcludeFilter |> Seq.toList)
AssemblyFilter =
[ "Mono"; @"\.Recorder"; @"\.DataCollector"; "Sample"; "nunit"; "Newton"; "xunit"; "BlackFox" ]
@ (p.AssemblyFilter |> Seq.toList)
TypeFilter = [ @"System\."; @"Sample3\.Class2"; "Tests" ] @ (p.TypeFilter |> Seq.toList) }
let AltCoverFilterG(p : Primitive.PrepareParams) =
{ p with MethodFilter = "WaitForExitCustom" :: (p.MethodFilter |> Seq.toList)
AssemblyExcludeFilter =
[ "Adapter"; "Tests" ] @ (p.AssemblyExcludeFilter |> Seq.toList)
AssemblyFilter =
[ "Mono"; @"\.Recorder\.g"; "Sample"; "nunit"; "Newton"; "xunit"; "BlackFox" ]
@ (p.AssemblyFilter |> Seq.toList)
TypeFilter = [ @"System\."; @"Sample3\.Class2" ] @ (p.TypeFilter |> Seq.toList) }
let programFiles = Environment.environVar "ProgramFiles"
let programFiles86 = Environment.environVar "ProgramFiles(x86)"
let dotnetPath = "dotnet" |> Fake.Core.ProcessUtils.tryFindFileOnPath
let dotnetOptions (o : DotNet.Options) =
match dotnetPath with
| Some f -> { o with DotNetCliPath = f }
| None -> o
let monoOnWindows =
if Environment.isWindows then
[ programFiles; programFiles86 ]
|> List.filter (String.IsNullOrWhiteSpace >> not)
|> List.map (fun s -> s @@ "Mono/bin/mono.exe")
|> List.tryFind File.Exists
else None
let dotnetPath86 =
if Environment.isWindows then
let perhaps =
[ programFiles86 ]
|> List.filter (String.IsNullOrWhiteSpace >> not)
|> List.map (fun s -> s @@ "dotnet\dotnet.EXE")
|> List.tryFind File.Exists
match perhaps with
| Some path ->
try // detect if we have the SDK
DotNet.info
(fun opt ->
{ opt with Common = { dotnetOptions opt.Common with DotNetCliPath = path } })
|> ignore
perhaps
with _ -> None
| _ -> None
else None
let nugetCache =
Path.Combine
(Environment.GetFolderPath Environment.SpecialFolder.UserProfile, ".nuget/packages")
let pwsh =
if Environment.isWindows then
Tools.findToolInSubPath "pwsh.exe" (programFiles @@ "PowerShell")
else "pwsh"
let cliArguments =
{ MSBuild.CliArguments.Create() with ConsoleLogParameters = []
DistributedLoggers = None
DisableInternalBinLog = true }
let withWorkingDirectoryVM dir o =
{ dotnetOptions o with WorkingDirectory = Path.getFullName dir
Verbosity = Some DotNet.Verbosity.Minimal }
let withWorkingDirectoryOnly dir o =
{ dotnetOptions o with WorkingDirectory = Path.getFullName dir }
let withCLIArgs (o : Fake.DotNet.DotNet.TestOptions) =
{ o with MSBuildParams = cliArguments }
let withMSBuildParams (o : Fake.DotNet.DotNet.BuildOptions) =
{ o with MSBuildParams = cliArguments }
let NuGetAltCover =
let xml = "./MCS/packages.config" |> Path.getFullName |> XDocument.Load
xml.Descendants(XName.Get("package"))
|> Seq.filter(fun x -> x.Attribute(XName.Get("id")).Value.ToLowerInvariant().Equals("altcover"))
|> Seq.map(fun x -> "./packages/altcover." + x.Attribute(XName.Get("version")).Value + "/tools/net45/AltCover.exe")
|> Seq.map Path.getFullName
|> Seq.filter File.Exists
|> Seq.tryHead
let ForceTrueOnly = DotNet.CLIArgs.Force true
let FailTrue = DotNet.CLIArgs.FailFast true
let GreenSummary = DotNet.CLIArgs.ShowSummary "Green"
let ForceTrue = DotNet.CLIArgs.Many [ ForceTrueOnly; GreenSummary ]
let _Target s f =
Target.description s
Target.create s f
// Preparation
_Target "Preparation" ignore
_Target "Clean" (fun _ ->
printfn "Cleaning the build and deploy folders"
Actions.Clean())
_Target "SetVersion" (fun _ ->
let appveyor = Environment.environVar "APPVEYOR_BUILD_VERSION"
let travis = Environment.environVar "TRAVIS_JOB_NUMBER"
let version = Actions.GetVersionFromYaml()
let ci =
if String.IsNullOrWhiteSpace appveyor then
if String.IsNullOrWhiteSpace travis then String.Empty
else version.Replace("{build}", travis + "-travis")
else appveyor
let (v, majmin, y) = Actions.LocalVersion ci version
Version := v
let copy = sprintf "© 2010-%d by Steve Gilham <[email protected]>" y
Copyright := "Copyright " + copy
Directory.ensure "./_Generated"
Actions.InternalsVisibleTo(!Version)
let v' = !Version
[ "./_Generated/AssemblyVersion.fs"; "./_Generated/AssemblyVersion.cs" ]
|> List.iter
(fun file ->
AssemblyInfoFile.create file [ AssemblyInfo.Product "AltCover"
AssemblyInfo.Version(majmin + ".0.0")
AssemblyInfo.FileVersion v'
AssemblyInfo.Company "Steve Gilham"
AssemblyInfo.Trademark ""
AssemblyInfo.Copyright copy ]
(Some AssemblyInfoFileConfig.Default))
let hack = """namespace AltCover
module SolutionRoot =
let location = """ + "\"\"\"" + (Path.getFullName ".") + "\"\"\""
let path = "_Generated/SolutionRoot.fs"
// Update the file only if it would change
let old =
if File.Exists(path) then File.ReadAllText(path)
else String.Empty
if not (old.Equals(hack)) then File.WriteAllText(path, hack))
// Basic compilation
_Target "Compilation" ignore
_Target "BuildRelease" (fun _ ->
try
"AltCover.sln"
|> MSBuild.build (fun p ->
{ p with Verbosity = Some MSBuildVerbosity.Normal
ConsoleLogParameters = []
DistributedLoggers = None
DisableInternalBinLog = true
Properties =
[ "Configuration", "Release"
"DebugSymbols", "True" ] })
"./altcover.core.sln"
|> DotNet.build
(fun p ->
{ p.WithCommon dotnetOptions with Configuration =
DotNet.BuildConfiguration.Release }
|> withMSBuildParams)
with x ->
printfn "%A" x
reraise())
_Target "BuildDebug" (fun _ ->
"AltCover.sln"
|> MSBuild.build (fun p ->
{ p with Verbosity = Some MSBuildVerbosity.Normal
ConsoleLogParameters = []
DistributedLoggers = None
DisableInternalBinLog = true
Properties =
[ "Configuration", "Debug"
"DebugSymbols", "True" ] })
Directory.ensure "./_SourceLink"
Shell.copyFile "./_SourceLink/Class2.cs" "./Sample14/Sample14/Class2.txt"
if Environment.isWindows then
let temp = Environment.environVar "TEMP"
Shell.copyFile (temp @@ "/Sample14.SourceLink.Class3.cs") "./Sample14/Sample14/Class3.txt"
else
Directory.ensure "/tmp/.AltCover_SourceLink"
Shell.copyFile "/tmp/.AltCover_SourceLink/Sample14.SourceLink.Class3.cs" "./Sample14/Sample14/Class3.txt"
[ "./altcover.core.sln"; "./Sample14/Sample14.sln" ]
|> Seq.iter (fun s -> s
|> DotNet.build
(fun p ->
{ p.WithCommon dotnetOptions with Configuration = DotNet.BuildConfiguration.Debug }
|> withMSBuildParams))
Shell.copy "./_SourceLink" (!!"./Sample14/Sample14/bin/Debug/netcoreapp2.1/*")
)
_Target "AvaloniaDebug" (fun _ ->
DotNet.restore (fun o -> o.WithCommon(withWorkingDirectoryVM "AltCover.Avalonia")) ""
"./AltCover.Visualizer/altcover.visualizer.core.sln"
|> MSBuild.build (fun p ->
{ p with Verbosity = Some MSBuildVerbosity.Normal
ConsoleLogParameters = []
DistributedLoggers = None
DisableInternalBinLog = true
Properties =
[ "Configuration", "Debug"
"DebugSymbols", "True" ] })
)
_Target "AvaloniaRelease" (fun _ ->
DotNet.restore (fun o -> o.WithCommon(withWorkingDirectoryVM "AltCover.Avalonia")) ""
"./AltCover.Visualizer/altcover.visualizer.core.sln"
|> MSBuild.build (fun p ->
{ p with Verbosity = Some MSBuildVerbosity.Normal
ConsoleLogParameters = []
DistributedLoggers = None
DisableInternalBinLog = true
Properties =
[ "Configuration", "Release"
"DebugSymbols", "True" ] })
)
_Target "BuildMonoSamples" (fun _ ->
let mcs = "_Binaries/MCS/Release+AnyCPU/MCS.exe"
[ ("./_Mono/Sample1",
[ "-debug"; "-out:./_Mono/Sample1/Sample1.exe"; "./Sample1/Program.cs" ])
("./_Mono/Sample3",
[ "-target:library"; "-debug"; "-out:./_Mono/Sample3/Sample3.dll";
"-lib:./packages/Mono.Cecil.0.10.4/lib/net40"; "-r:Mono.Cecil.dll";
"./Sample3/Class1.cs" ]) ]
|> Seq.iter
(fun (dir, cmd) ->
Directory.ensure dir
("Mono compilation of '" + String.Join(" ", cmd) + "' failed")
|> Actions.Run(mcs, ".", cmd))
Actions.FixMVId [ "./_Mono/Sample1/Sample1.exe"; "./_Mono/Sample3/Sample3.dll" ])
// Code Analysis
_Target "Analysis" ignore
_Target "Lint" (fun _ ->
let failOnIssuesFound (issuesFound : bool) =
Assert.That(issuesFound, Is.False, "Lint issues were found")
try
let settings =
Configuration.SettingsFileName
|> Path.getFullName
|> File.ReadAllText
let lintConfig = FSharpLint.Application.ConfigurationManagement.loadConfigurationFile settings
let options =
{ Lint.OptionalLintParameters.Default with Configuration = Some lintConfig }
!!"**/*.fsproj"
|> Seq.collect (fun n -> !!(Path.GetDirectoryName n @@ "*.fs"))
|> Seq.distinct
|> Seq.map (fun f ->
match Lint.lintFile options f with
| Lint.LintResult.Failure x -> failwithf "%A" x
| Lint.LintResult.Success w ->
w
|> Seq.filter (fun x ->
match x.Fix with
| None -> false
| Some fix -> fix.FromText <> "AltCover_Fake")) // special case
|> Seq.concat
|> Seq.fold (fun _ x ->
printfn "Info: %A\r\n Range: %A\r\n Fix: %A\r\n====" x.Info x.Range x.Fix
true) false
|> failOnIssuesFound
with ex ->
printfn "%A" ex
reraise())
_Target "Gendarme" (fun _ -> // Needs debug because release is compiled --standalone which contaminates everything
Directory.ensure "./_Reports"
let toolPath = (Tools.findToolInSubPath "gendarme.exe" "./packages")
let rules =
if Environment.isWindows then "./Build/rules.xml"
else "./Build/rules-mono.xml"
let baseRules = Path.getFullName "./Build/rules-fake.xml"
let fakerules =
if Environment.isWindows then baseRules
else
// Gendarme mono doesn't into .pdb files
let lines = baseRules
|> File.ReadAllLines
|> Seq.map (fun l -> l.Replace ("AvoidSwitchStatementsRule", "AvoidSwitchStatementsRule | AvoidLongMethodsRule"))
let fixup = Path.getFullName "./_Generated/rules-fake.xml"
File.WriteAllLines(fixup, lines)
fixup
[ (rules,
[ "_Binaries/AltCover/Debug+AnyCPU/AltCover.exe"
"_Binaries/AltCover.Shadow/Debug+AnyCPU/AltCover.Shadow.dll" ])
("./Build/rules-posh.xml",
[ "_Binaries/AltCover.PowerShell/Debug+AnyCPU/AltCover.PowerShell.dll"
"_Binaries/AltCover.FSApi/Debug+AnyCPU/AltCover.FSApi.dll" ])
("./Build/rules-gtk.xml",
[ "_Binaries/AltCover.Visualizer/Debug+AnyCPU/AltCover.Visualizer.exe" ])
(fakerules,
["_Binaries/AltCover.Fake.DotNet.Testing.AltCover/Debug+AnyCPU/AltCover.Fake.DotNet.Testing.AltCover.dll"]) ]
|> Seq.iter (fun (ruleset, files) ->
Gendarme.run { Gendarme.Params.Create() with WorkingDirectory = "."
Severity = Gendarme.Severity.All
Confidence = Gendarme.Confidence.All
Configuration = ruleset
Console = true
Log = "./_Reports/gendarme.html"
LogKind = Gendarme.LogKind.Html
Targets = files
ToolPath = toolPath
FailBuildOnDefect = true }))
_Target "FxCop" (fun _ -> // Needs debug because release is compiled --standalone which contaminates everything
Directory.ensure "./_Reports"
let rules = [ "-Microsoft.Design#CA1004"
"-Microsoft.Design#CA1006"
"-Microsoft.Design#CA1011" // maybe sometimes
"-Microsoft.Design#CA1062" // null checks, In F#!
"-Microsoft.Maintainability#CA1506"
"-Microsoft.Naming#CA1704"
"-Microsoft.Naming#CA1707"
"-Microsoft.Naming#CA1709"
"-Microsoft.Naming#CA1715"
"-Microsoft.Usage#CA2208"
]
[ ([
"_Binaries/AltCover/Debug+AnyCPU/AltCover.exe"
], [ "AltCover.AltCover"
"AltCover.Api"
"AltCover.Args"
"AltCover.Augment"
"AltCover.Collect"
"AltCover.CollectParams"
"AltCover.CommandLine"
"AltCover.Filter"
"AltCover.FilterClass"
"AltCover.Fix"
"AltCover.GetVersion"
"AltCover.Instrument"
"AltCover.KeyRecord"
"AltCover.KeyStore"
"AltCover.Logging"
"AltCover.Main"
"AltCover.Naming"
"AltCover.Node"
"AltCover.PowerShell"
"AltCover.Prepare"
"AltCover.PrepareParams"
"AltCover.ProgramDatabase"
"AltCover.Report"
"AltCover.Runner"
"AltCover.Visitor" ], rules)
([
"_Binaries/AltCover.Shadow/Debug+AnyCPU/AltCover.Shadow.dll"
], [ "AltCover.Recorder.Assist"
"AltCover.Recorder.Counter"
"AltCover.Recorder.Assist"
"AltCover.Recorder.Tracer"
"AltCover.Recorder.Instance" ], rules)
([
"_Binaries/AltCover.PowerShell/Debug+AnyCPU/AltCover.PowerShell.dll"
], [], [ "-Microsoft.Design#CA1059"
"-Microsoft.Usage#CA2235"
"-Microsoft.Performance#CA1819"
"-Microsoft.Design#CA1020"
"-Microsoft.Design#CA1004"
"-Microsoft.Design#CA1006"
"-Microsoft.Design#CA1011"
"-Microsoft.Design#CA1062"
"-Microsoft.Maintainability#CA1506"
"-Microsoft.Naming#CA1704"
"-Microsoft.Naming#CA1707"
"-Microsoft.Naming#CA1709"
"-Microsoft.Naming#CA1715" ])
([
"_Binaries/AltCover.FSApi/Debug+AnyCPU/AltCover.FSApi.dll"
], [], [ "-Microsoft.Usage#CA2235"
"-Microsoft.Performance#CA1819"
"-Microsoft.Design#CA1020"
"-Microsoft.Design#CA1034"
"-Microsoft.Design#CA1004"
"-Microsoft.Design#CA1006"
"-Microsoft.Design#CA1011"
"-Microsoft.Design#CA1062"
"-Microsoft.Maintainability#CA1506"
"-Microsoft.Naming#CA1704"
"-Microsoft.Naming#CA1707"
"-Microsoft.Naming#CA1709"
"-Microsoft.Naming#CA1715" ])
([
"_Binaries/AltCover.Visualizer/Debug+AnyCPU/AltCover.Visualizer.exe"
], [
"AltCover.Augment"
"AltCover.Visualizer.Transformer"
"AltCover.Visualizer.CoverageFile"
"AltCover.Visualizer.Extensions"
"AltCover.Visualizer.Gui"
], [ "-Microsoft.Usage#CA2208"
"-Microsoft.Usage#CA2235"
"-Microsoft.Maintainability#CA1506"
"-Microsoft.Design#CA1004"
"-Microsoft.Design#CA1006"
"-Microsoft.Naming#CA1707"
"-Microsoft.Naming#CA1715"
"-Microsoft.Naming#CA1704"
"-Microsoft.Naming#CA1709" ])
([
"_Binaries/AltCover.Fake.DotNet.Testing.AltCover/Debug+AnyCPU/AltCover.Fake.DotNet.Testing.AltCover.dll"
], [
"AltCover_Fake.DotNet.Testing.AltCover.CollectParams"
"AltCover_Fake.DotNet.Testing.AltCover.PrepareParams"
"AltCover_Fake.DotNet.Testing.AltCover.Args"
"AltCover_Fake.DotNet.Testing.AltCover.ArgType"
"AltCover_Fake.DotNet.Testing.AltCover.ToolType"
"AltCover_Fake.DotNet.Testing.AltCover.Params"
"AltCover_Fake.DotNet.Testing.AltCover.PrepareParams"
"AltCover_Fake.DotNet.Testing.AltCover"
"AltCover.Internals.DotNet"
"AltCover_Fake.DotNet.DotNet"
], [ "-Microsoft.Design#CA1006"
"-Microsoft.Design#CA1011"
"-Microsoft.Design#CA1020"
"-Microsoft.Design#CA1062"
"-Microsoft.Naming#CA1704"
"-Microsoft.Naming#CA1707"
"-Microsoft.Naming#CA1709"
"-Microsoft.Naming#CA1724"
"-Microsoft.Usage#CA2208" ])
]
|> Seq.iter (fun (files, types, ruleset) -> files
|> FxCop.run { FxCop.Params.Create() with WorkingDirectory = "."
UseGAC = true
Verbose = false
ReportFileName = "_Reports/FxCopReport.xml"
Types = types
Rules = ruleset
FailOnError = FxCop.ErrorLevel.Warning
IgnoreGeneratedCode = true })
[ "_Binaries/AltCover.PowerShell/Debug+AnyCPU/AltCover.PowerShell.dll" ]
|> FxCop.run { FxCop.Params.Create() with WorkingDirectory = "."
UseGAC = true
Verbose = false
ReportFileName = "_Reports/FxCopReport.xml"
RuleLibraries =
[ Path.getFullName
"ThirdParty/Microsoft.PowerShell.CodeAnalysis.15.dll" ]
FailOnError = FxCop.ErrorLevel.Warning
IgnoreGeneratedCode = true })
// Unit Test
_Target "UnitTest" ignore
_Target "JustUnitTest" (fun _ ->
Directory.ensure "./_Reports"
try
let here = Path.getFullName "."
!!(@"_Binaries/*Tests/Debug+AnyCPU/*XTest*.dll")
|> Fake.DotNet.Testing.XUnit2.run (fun p ->
{ p with ToolPath = Tools.findToolInSubPath "xunit.console.exe" "."
NUnitXmlOutputPath = Some "./_Reports/JustXUnitTestReport.xml"
WorkingDir = Some here
ShadowCopy = false })
!!(@"_Binaries/*Tests*/Debug+AnyCPU/*Test*.dll")
|> Seq.filter
(fun f ->
Path.GetFileName(f) <> "AltCover.XTests.dll"
&& Path.GetFileName(f) <> "NUnit3.TestAdapter.dll"
&& Path.GetFileName(f) <> "xunit.runner.visualstudio.testadapter.dll")
|> NUnit3.run (fun p ->
{ p with ToolPath = Tools.findToolInSubPath "nunit3-console.exe" "."
WorkingDir = "."
ResultSpecs = [ "./_Reports/JustUnitTestReport.xml" ] })
with x ->
printfn "%A" x
reraise())
_Target "BuildForUnitTestDotNet" (fun _ ->
!!(@"./*Tests/*.tests.core.fsproj")
|> Seq.iter
(DotNet.build
(fun p ->
{ p.WithCommon dotnetOptions with Configuration =
DotNet.BuildConfiguration.Debug }
|> withMSBuildParams)))
_Target "UnitTestDotNet" (fun _ ->
Directory.ensure "./_Reports"
try
!!(@"./*Tests/*.tests.core.fsproj")
|> Seq.iter (DotNet.test (fun p ->
{ p.WithCommon dotnetOptions with Configuration =
DotNet.BuildConfiguration.Debug
NoBuild = true }
|> withCLIArgs))
with x ->
printfn "%A" x
reraise())
_Target "BuildForCoverlet" (fun _ ->
!!(@"./*Tests/*.tests.core.fsproj")
|> Seq.iter
(DotNet.build
(fun p ->
{ p.WithCommon dotnetOptions with Configuration =
DotNet.BuildConfiguration.Debug }
|> withMSBuildParams)))
_Target "UnitTestDotNetWithCoverlet" (fun _ ->
Directory.ensure "./_Reports"
try
let xml =
!!(@"./*Tests/*.tests.core.fsproj")
|> Seq.zip
[ """/p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="\"[*.Tests]*,[*.XTests]*,[xunit*]*,[Sample*]*,[AltCover.Record*]*,[NUnit*]*,[AltCover.Shadow.Adapter]*\"" """
"""/p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="\"[*.Tests]*,[*.XTests]*,[xunit*]*,[Sample*]*,[AltCover.Record*]*,[NUnit*]*,[AltCover.Shadow.Adapter]*\"" """
"""/p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="\"[*.Tests]*,[*.XTests]*,[xunit*]*,[Sample*]*,[AltCover.Record*]*\"" """ ]
|> Seq.fold (fun l (p, f) ->
try
f
|> DotNet.test (fun o ->
{ o.WithCommon(fun c -> { dotnetOptions c with CustomParams = Some p }) with Configuration =
DotNet.BuildConfiguration.Debug
NoBuild =
true
Framework =
Some
"netcoreapp2.1" }
|> withCLIArgs)
with x -> eprintf "%A" x
let here = Path.GetDirectoryName f
(here @@ "coverage.opencover.xml") :: l) []
ReportGenerator.generateReports (fun p ->
{ p with ExePath = Tools.findToolInSubPath "ReportGenerator.exe" "."
ReportTypes =
[ ReportGenerator.ReportType.Html; ReportGenerator.ReportType.XmlSummary ]
TargetDir = "_Reports/_UnitTestWithCoverlet" }) xml
with x ->
printfn "%A" x
reraise())
_Target "UnitTestWithOpenCover" (fun _ ->
Directory.ensure "./_Reports/_UnitTestWithOpenCover"
let testFiles =
!!(@"_Binaries/*Tests/Debug+AnyCPU/*Test*.dll")
|> Seq.filter
(fun f ->
Path.GetFileName(f) <> "AltCover.XTests.dll"
&& Path.GetFileName(f) <> "NUnit3.TestAdapter.dll"
&& Path.GetFileName(f) <> "xunit.runner.visualstudio.testadapter.dll")
let xtestFiles = !!(@"_Binaries/*Tests/Debug+AnyCPU/*XTest*.dll")
let coverage = Path.getFullName "_Reports/UnitTestWithOpenCover.xml"
let xcoverage = Path.getFullName "_Reports/XUnitTestWithOpenCover.xml"
try
OpenCover.run (fun p ->
{ p with WorkingDir = "."
ExePath = Tools.findToolInSubPath "OpenCover.Console.exe" "."
TestRunnerExePath = Tools.findToolInSubPath "xunit.console.exe" "."
Filter =
"+[AltCover]* +[AltCover.Shadow]* +[AltCover.Runner]* +[AltCover.WeakNameTests]Alt* -[*]Microsoft.* -[*]System.* -[Sample*]*"
MergeByHash = true
OptionalArguments =
"-excludebyattribute:*ExcludeFromCodeCoverageAttribute;*ProgIdAttribute"
Register = OpenCover.RegisterType.RegisterUser
Output = xcoverage })
(String.Join(" ", xtestFiles)
+ " -parallel none -noshadow -nunit _Reports/XUnitTestWithOpenCoverReport.xml")
OpenCover.run (fun p ->
{ p with WorkingDir = "."
ExePath = Tools.findToolInSubPath "OpenCover.Console.exe" "."
TestRunnerExePath = Tools.findToolInSubPath "nunit3-console.exe" "."
Filter =
"+[AltCover]* +[AltCover.Shadow]* +[AltCover.Runner]* +[AltCover.WeakNameTests]Alt* -[*]Microsoft.* -[*]System.* -[Sample*]*"
MergeByHash = true
OptionalArguments =
"-excludebyattribute:*ExcludeFromCodeCoverageAttribute;*ProgIdAttribute"
Register = OpenCover.RegisterType.RegisterUser
Output = coverage })
(String.Join(" ", testFiles)
+ " --result=./_Reports/UnitTestWithOpenCoverReport.xml")
with x ->
printfn "%A" x
reraise()
ReportGenerator.generateReports (fun p ->
{ p with ExePath = Tools.findToolInSubPath "ReportGenerator.exe" "."
ReportTypes =
[ ReportGenerator.ReportType.Html; ReportGenerator.ReportType.XmlSummary ]
TargetDir = "_Reports/_UnitTestWithOpenCover" }) [ coverage; xcoverage ])
// Hybrid (Self) Tests
_Target "UnitTestWithAltCover" (fun _ ->
Directory.ensure "./_Reports/_UnitTestWithAltCover"
let keyfile = Path.getFullName "Build/SelfTest.snk"
let shadowkeyfile = Path.getFullName "Build/Infrastructure.snk"
let reports = Path.getFullName "./_Reports"
let altcover = Tools.findToolInSubPath "AltCover.exe" "./_Binaries"
let here = Path.getFullName "."
let testDirectory = Path.getFullName "_Binaries/AltCover.Tests/Debug+AnyCPU"
let xtestDirectory = Path.getFullName "_Binaries/AltCover.XTests/Debug+AnyCPU"
if !!(testDirectory @@ "AltCov*.pdb")
|> Seq.length > 0 then
let xaltReport = reports @@ "XUnitTestWithAltCover.xml"
printfn "Instrumented the code"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = xaltReport
OutputDirectories = [| "./__UnitTestWithAltCover" |]
StrongNameKey = keyfile
OpenCover = false
InPlace = false
Save = false }
|> AltCoverFilter)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = xtestDirectory }
|> AltCover.run
printfn "Unit test the instrumented code"
!!(@"_Binaries/*Tests/Debug+AnyCPU/__UnitTestWithAltCover/*XTest*.dll")
|> Fake.DotNet.Testing.XUnit2.run (fun p ->
{ p with ToolPath = Tools.findToolInSubPath "xunit.console.exe" "."
NUnitXmlOutputPath = Some "./_Reports/XUnitTestWithAltCoverReport.xml"
WorkingDir = Some here
ShadowCopy = false })
let altReport = reports @@ "UnitTestWithAltCover.xml"
let weakDir = Path.getFullName "_Binaries/AltCover.WeakNameTests/Debug+AnyCPU"
printfn "Instrumented the code"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = altReport
InputDirectories = [| "."; weakDir|]
OutputDirectories = [| "./__UnitTestWithAltCover"; weakDir @@ "__WeakNameTestWithAltCover" |]
StrongNameKey = keyfile
OpenCover = false
InPlace = false
Save = false }
|> AltCoverFilterX)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = testDirectory }
|> AltCover.run
let sn = "sn" |> Fake.Core.ProcessUtils.tryFindFileOnPath
if sn |> Option.isSome then
Actions.Run
(sn |> Option.get, testDirectory,
[ "-vf"; "./__UnitTestWithAltCover/AltCover.Recorder.g.dll" ])
"Recorder assembly strong-name verified OK"
printfn "Unit test the instrumented code"
try
[ !!"_Binaries/AltCover.Tests/Debug+AnyCPU/__UnitTestWithAltCover/*.Tests.dll"
!!"_Binaries/AltCover.WeakNameTests/Debug+AnyCPU/__WeakNameTestWithAltCover/Alt*Test*.dll"
!!"_Binaries/AltCover.Tests/Debug+AnyCPU/__UnitTestWithAltCover/*ple2.dll" ]
|> Seq.concat
|> Seq.distinct
|> NUnit3.run (fun p ->
{ p with ToolPath = Tools.findToolInSubPath "nunit3-console.exe" "."
WorkingDir = "."
ResultSpecs = [ "./_Reports/UnitTestWithAltCoverReport.xml" ] })
with x ->
printfn "%A" x
reraise()
printfn "Instrument the shadow tests"
let shadowDir = Path.getFullName "_Binaries/AltCover.Shadow.Tests/Debug+AnyCPU"
let shadowReport = reports @@ "ShadowTestWithAltCover.xml"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = shadowReport
OutputDirectories =
[| "./__ShadowTestWithAltCover" |]
StrongNameKey = shadowkeyfile
InPlace = false
Save = false }
|> AltCoverFilter)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = shadowDir }
|> AltCover.run
printfn "Execute the shadow tests"
!!("_Binaries/AltCover.Shadow.Tests/Debug+AnyCPU/__ShadowTestWithAltCover/Alt*.Test*.dll")
|> NUnit3.run (fun p ->
{ p with ToolPath = Tools.findToolInSubPath "nunit3-console.exe" "."
WorkingDir = "."
ResultSpecs = [ "./_Reports/ShadowTestWithAltCoverReport.xml" ] })
ReportGenerator.generateReports (fun p ->
{ p with ExePath = Tools.findToolInSubPath "ReportGenerator.exe" "."
ReportTypes =
[ ReportGenerator.ReportType.Html; ReportGenerator.ReportType.XmlSummary ]
TargetDir = "_Reports/_UnitTestWithAltCover" })
[ xaltReport; altReport; shadowReport ]
else printfn "Symbols not present; skipping")
_Target "UnitTestWithAltCoverRunner" (fun _ ->
Directory.ensure "./_Reports/_UnitTestWithAltCover"
let keyfile = Path.getFullName "Build/SelfTest.snk"
let shadowkeyfile = Path.getFullName "Build/Infrastructure.snk"
let reports = Path.getFullName "./_Reports"
let altcover =
Tools.findToolInSubPath "AltCover.exe" "./_Binaries/AltCover/Debug+AnyCPU"
let nunit = Tools.findToolInSubPath "nunit3-console.exe" "."
let here = Path.getFullName "."
let testDirectory = Path.getFullName "_Binaries/AltCover.Tests/Debug+AnyCPU"
let xtestDirectory = Path.getFullName "_Binaries/AltCover.XTests/Debug+AnyCPU"
if !!(testDirectory @@ "AltCov*.pdb")
|> Seq.length > 0 then
let xaltReport = reports @@ "XUnitTestWithAltCoverRunner.xml"
printfn "Instrumented the code"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = xaltReport
OutputDirectories =
[| "./__UnitTestWithAltCoverRunner" |]
StrongNameKey = keyfile
Single = true
InPlace = false
Save = false }
|> AltCoverFilter)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = xtestDirectory }
|> AltCover.run
printfn "Unit test the instrumented code"
try
let collect =
AltCover.CollectParams.Primitive
{ Primitive.CollectParams.Create() with Executable = Tools.findToolInSubPath "xunit.console.exe" "."
RecorderDirectory = xtestDirectory @@ "__UnitTestWithAltCoverRunner"
CommandLine =
[ Path.getFullName
"_Binaries/AltCover.XTests/Debug+AnyCPU/__UnitTestWithAltCoverRunner/AltCover.XTests.dll"
"-parallel"
"none"
"-noshadow"
"-nunit"
"./_Reports/XUnitTestWithAltCoverRunnerReport.xml" ] }
|> AltCover.Collect
{ AltCover.Params.Create collect with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = here }
|> AltCover.run
with x ->
printfn "%A" x
reraise()
let altReport = reports @@ "UnitTestWithAltCoverRunner.xml"
printfn "Instrumented the code"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = altReport
OutputDirectories =
[| "./__UnitTestWithAltCoverRunner" |]
StrongNameKey = keyfile
Single = true
InPlace = false
Save = false }
|> AltCoverFilter)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = testDirectory }
|> AltCover.run
printfn "Unit test the instrumented code"
try
let collect =
AltCover.CollectParams.Primitive
{ Primitive.CollectParams.Create() with Executable = nunit
RecorderDirectory = testDirectory @@ "__UnitTestWithAltCoverRunner"
CommandLine =
[ "--noheader";
"--work=.";
"--result=./_Reports/UnitTestWithAltCoverRunnerReport.xml";
Path.getFullName
"_Binaries/AltCover.Tests/Debug+AnyCPU/__UnitTestWithAltCoverRunner/AltCover.Tests.dll";
Path.getFullName
"_Binaries/AltCover.Tests/Debug+AnyCPU/__UnitTestWithAltCoverRunner/Sample2.dll" ]}
|> AltCover.Collect
{ AltCover.Params.Create collect with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = "." }
|> AltCover.run
with x ->
printfn "%A" x
reraise()
printfn "Instrument the weakname tests"
let weakDir = Path.getFullName "_Binaries/AltCover.WeakNameTests/Debug+AnyCPU"
let weakReport = reports @@ "WeakNameTestWithAltCoverRunner.xml"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = weakReport
OutputDirectories =
[| "./__WeakNameTestWithAltCoverRunner" |]
TypeFilter = [ "WeakNameTest" ]
StrongNameKey = keyfile
Single = true
InPlace = false
Save = false }
|> AltCoverFilterX)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = weakDir }
|> AltCover.run
printfn "Execute the weakname tests"
let collect =
AltCover.CollectParams.Primitive
{ Primitive.CollectParams.Create() with Executable = nunit
RecorderDirectory = weakDir @@ "__WeakNameTestWithAltCoverRunner"
CommandLine =
[ "--noheader"
"--work=."
"--result=./_Reports/ShadowTestWithAltCoverRunnerReport.xml"
Path.getFullName
"_Binaries/AltCover.WeakNameTests/Debug+AnyCPU/__WeakNameTestWithAltCoverRunner/AltCover.WeakNameTests.dll" ] }
|> AltCover.Collect
{ AltCover.Params.Create collect with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = "." }
|> AltCover.run
printfn "Instrument the shadow tests"
let shadowDir = Path.getFullName "_Binaries/AltCover.Shadow.Tests/Debug+AnyCPU"
let shadowReport = reports @@ "ShadowTestWithAltCoverRunner.xml"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = shadowReport
OutputDirectories =
[| "./__ShadowTestWithAltCoverRunner" |]
StrongNameKey = shadowkeyfile
InPlace = false
Save = false }
|> AltCoverFilter)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = shadowDir }
|> AltCover.run
let collect =
AltCover.CollectParams.Primitive
{ Primitive.CollectParams.Create() with Executable = nunit
RecorderDirectory = shadowDir @@ "__ShadowTestWithAltCoverRunner"
CommandLine =
[ "--noheader";
"--work=.";
"--result=./_Reports/ShadowTestWithAltCoverRunnerReport.xml";
Path.getFullName
"_Binaries/AltCover.Shadow.Tests/Debug+AnyCPU/__ShadowTestWithAltCoverRunner/AltCover.Shadow.Tests.dll";
Path.getFullName
"_Binaries/AltCover.Shadow.Tests/Debug+AnyCPU/__ShadowTestWithAltCoverRunner/AltCover.Shadow.Tests2.dll" ]}
|> AltCover.Collect
{ AltCover.Params.Create collect with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = "." }
|> AltCover.run
printfn "Instrument the GTK# visualizer tests"
let gtkDir = Path.getFullName "_Binaries/AltCover.Tests.Visualizer/Debug+AnyCPU"
let gtkReport = reports @@ "GTKVTestWithAltCoverRunner.xml"
let prep =
AltCover.PrepareParams.Primitive
({ Primitive.PrepareParams.Create() with XmlReport = gtkReport
OutputDirectories =
[| "./__GTKVTestWithAltCoverRunner" |]
TypeFilter = [ "Gui" ]
AssemblyFilter = [ "\\-sharp" ]
StrongNameKey = keyfile
InPlace = false
Save = false }
|> AltCoverFilter)
|> AltCover.Prepare
{ AltCover.Params.Create prep with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = gtkDir }
|> AltCover.run
printfn "Execute the the GTK# visualizer tests"
let collect =
AltCover.CollectParams.Primitive
{ Primitive.CollectParams.Create() with Executable = nunit
RecorderDirectory = gtkDir @@ "__GTKVTestWithAltCoverRunner"
CommandLine =
[ "--noheader"
"--work=."
"--result=./_Reports/GTKVTestWithAltCoverRunnerReport.xml"
Path.getFullName
"_Binaries/AltCover.Tests.Visualizer/Debug+AnyCPU/__GTKVTestWithAltCoverRunner/AltCover.Tests.Visualizer.dll" ]}
|> AltCover.Collect
{ AltCover.Params.Create collect with ToolPath = altcover
ToolType = AltCover.ToolType.Framework
WorkingDirectory = "." }
|> AltCover.run
let pester = Path.getFullName "_Reports/Pester.xml"
ReportGenerator.generateReports (fun p ->
{ p with ExePath = Tools.findToolInSubPath "ReportGenerator.exe" "."
ReportTypes =
[ ReportGenerator.ReportType.Html; ReportGenerator.ReportType.XmlSummary ]
TargetDir = "_Reports/_UnitTestWithAltCoverRunner" })
[ xaltReport; altReport; shadowReport; weakReport; pester ]
let cover1 =
altReport
|> File.ReadAllLines
|> Seq.takeWhile (fun l -> l <> " </Modules>")
let cover2 =
shadowReport
|> File.ReadAllLines
|> Seq.skipWhile (fun l -> l.StartsWith(" <Module") |> not)
|> Seq.takeWhile (fun l -> l <> " </Modules>")
let cover3 =
weakReport