-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathTerminalLogger_Tests.cs
More file actions
1165 lines (952 loc) · 58 KB
/
TerminalLogger_Tests.cs
File metadata and controls
1165 lines (952 loc) · 58 KB
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.CommandLine.UnitTests;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using Microsoft.Build.UnitTests.Shared;
using Shouldly;
using VerifyTests;
using VerifyXunit;
using Xunit;
using Xunit.Abstractions;
using Xunit.NetCore.Extensions;
using static VerifyXunit.Verifier;
namespace Microsoft.Build.UnitTests
{
internal sealed class MockBuildEventSink(int nodeNumber) : IBuildEventSink, IEventSource
{
public string Name { get; set; } = $"MockBuildEventSink{nodeNumber}";
public bool HaveLoggedBuildStartedEvent { get; set; }
public bool HaveLoggedBuildFinishedEvent { get; set; }
void IBuildEventSink.Consume(BuildEventArgs buildEvent, int sinkId) => (this as IBuildEventSink).Consume(buildEvent);
void IBuildEventSink.Consume(BuildEventArgs buildEvent)
{
// map the incoming build event to the appropriate event handler
switch (buildEvent)
{
case BuildStartedEventArgs e:
HaveLoggedBuildStartedEvent = true;
BuildStarted?.Invoke(this, e);
break;
case BuildFinishedEventArgs e:
BuildFinished?.Invoke(this, e);
break;
case ProjectStartedEventArgs e:
ProjectStarted?.Invoke(this, e);
break;
case ProjectFinishedEventArgs e:
ProjectFinished?.Invoke(this, e);
break;
case TargetStartedEventArgs e:
TargetStarted?.Invoke(this, e);
break;
case TargetFinishedEventArgs e:
TargetFinished?.Invoke(this, e);
break;
case TaskStartedEventArgs e:
TaskStarted?.Invoke(this, e);
break;
case TaskFinishedEventArgs e:
TaskFinished?.Invoke(this, e);
break;
case BuildMessageEventArgs e:
MessageRaised?.Invoke(this, e);
break;
case BuildWarningEventArgs e:
WarningRaised?.Invoke(this, e);
break;
case BuildErrorEventArgs e:
ErrorRaised?.Invoke(this, e);
break;
case BuildStatusEventArgs e:
StatusEventRaised?.Invoke(this, e);
break;
case CustomBuildEventArgs c:
CustomEventRaised?.Invoke(this, c);
break;
}
}
void IBuildEventSink.ShutDown()
{
}
private const string _eventSender = "Test";
public event BuildMessageEventHandler? MessageRaised;
public event BuildErrorEventHandler? ErrorRaised;
public event BuildWarningEventHandler? WarningRaised;
public event BuildStartedEventHandler? BuildStarted;
public event BuildFinishedEventHandler? BuildFinished;
public event ProjectStartedEventHandler? ProjectStarted;
public event ProjectFinishedEventHandler? ProjectFinished;
public event TargetStartedEventHandler? TargetStarted;
public event TargetFinishedEventHandler? TargetFinished;
public event TaskStartedEventHandler? TaskStarted;
public event TaskFinishedEventHandler? TaskFinished;
public event CustomBuildEventHandler? CustomEventRaised;
public event BuildStatusEventHandler? StatusEventRaised;
#pragma warning disable CS0067 // The event is never used
public event AnyEventHandler? AnyEventRaised;
#pragma warning restore CS0067 // The event is never used
// wrappers to invoke the events on this class
public void InvokeBuildStarted(BuildStartedEventArgs args) => BuildStarted?.Invoke(_eventSender, args);
public void InvokeBuildFinished(BuildFinishedEventArgs args) => BuildFinished?.Invoke(_eventSender, args);
public void InvokeProjectStarted(ProjectStartedEventArgs args) => ProjectStarted?.Invoke(_eventSender, args);
public void InvokeProjectFinished(ProjectFinishedEventArgs args) => ProjectFinished?.Invoke(_eventSender, args);
public void InvokeTargetStarted(TargetStartedEventArgs args) => TargetStarted?.Invoke(_eventSender, args);
public void InvokeTargetFinished(TargetFinishedEventArgs args) => TargetFinished?.Invoke(_eventSender, args);
public void InvokeTaskStarted(TaskStartedEventArgs args) => TaskStarted?.Invoke(_eventSender, args);
public void InvokeTaskFinished(TaskFinishedEventArgs args) => TaskFinished?.Invoke(_eventSender, args);
public void InvokeMessageRaised(BuildMessageEventArgs args) => MessageRaised?.Invoke(_eventSender, args);
public void InvokeWarningRaised(BuildWarningEventArgs args) => WarningRaised?.Invoke(_eventSender, args);
public void InvokeErrorRaised(BuildErrorEventArgs args) => ErrorRaised?.Invoke(_eventSender, args);
public void InvokeStatusEventRaised(BuildStatusEventArgs args) => StatusEventRaised?.Invoke(_eventSender, args);
public void InvokeCustomEventRaised(CustomBuildEventArgs args) => CustomEventRaised?.Invoke(_eventSender, args);
}
[UsesVerify]
[UseInvariantCulture]
public class TerminalLogger_Tests
{
private const int _nodeCount = 8;
private const string _immediateMessageString =
"The plugin credential provider could not acquire credentials." +
"Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, " +
"/p:NuGetInteractive=\"true\" for MSBuild or removing the -NonInteractive switch for `NuGet`";
private readonly string _projectFile = NativeMethods.IsUnixLike ? "/src/project.proj" : @"C:\src\project.proj";
private readonly string _projectFile2 = NativeMethods.IsUnixLike ? "/src/project2.proj" : @"C:\src\project2.proj";
private readonly string _projectFileWithNonAnsiSymbols = NativeMethods.IsUnixLike ? "/src/проектТерминал/㐇𠁠𪨰𫠊𫦠𮚮⿕.proj" : @"C:\src\проектТерминал\㐇𠁠𪨰𫠊𫦠𮚮⿕.proj";
private readonly MockBuildEventSink _centralNodeEventSource = new MockBuildEventSink(0);
private readonly MockBuildEventSink _remoteNodeEventSource = new MockBuildEventSink(1);
private StringWriter _outputWriter = new();
private readonly Terminal _mockTerminal;
private readonly TerminalLogger _terminallogger;
private readonly ForwardingTerminalLogger _remoteTerminalLogger;
private readonly DateTime _buildStartTime = new DateTime(2023, 3, 30, 16, 30, 0);
private readonly DateTime _targetStartTime = new DateTime(2023, 3, 30, 16, 30, 1);
private readonly DateTime _messageTime = new DateTime(2023, 3, 30, 16, 30, 2);
private readonly DateTime _buildFinishTime = new DateTime(2023, 3, 30, 16, 30, 5);
private VerifySettings _settings = new();
private readonly ITestOutputHelper _outputHelper;
public TerminalLogger_Tests(ITestOutputHelper outputHelper)
{
_outputHelper = outputHelper;
_mockTerminal = new Terminal(_outputWriter);
_terminallogger = new TerminalLogger(_mockTerminal);
_terminallogger.Initialize(_centralNodeEventSource, _nodeCount);
_terminallogger._createStopwatch = () => new MockStopwatch();
_remoteTerminalLogger = new ForwardingTerminalLogger();
_remoteTerminalLogger.BuildEventRedirector = new EventRedirectorToSink(0, _centralNodeEventSource);
_remoteTerminalLogger.Initialize(_remoteNodeEventSource, 1);
UseProjectRelativeDirectory("Snapshots");
}
[Theory]
[InlineData(null, false, false, "", typeof(ConsoleLogger))]
[InlineData(null, true, false, "", typeof(ConsoleLogger))]
[InlineData(null, false, true, "", typeof(ConsoleLogger))]
[InlineData(null, true, true, "off", typeof(ConsoleLogger))]
[InlineData(null, true, true, "false", typeof(ConsoleLogger))]
[InlineData("--tl:off", true, true, "", typeof(ConsoleLogger))]
[InlineData("--tl:false", true, true, "", typeof(ConsoleLogger))]
[InlineData(null, true, true, "", typeof(TerminalLogger))]
[InlineData("-tl:on", true, true, "off", typeof(TerminalLogger))] // arg overrides env
[InlineData("-tl:true", true, true, "off", typeof(TerminalLogger))] // arg overrides env
[InlineData("-tl:off", true, true, "on", typeof(ConsoleLogger))] // arg overrides env (disable)
[InlineData("-tl:false", true, true, "true", typeof(ConsoleLogger))] // arg overrides env (disable)
[InlineData("-tl:on", false, false, "", typeof(TerminalLogger))] // Force when explicitly set to "on"
[InlineData("-tl:true", false, false, "", typeof(TerminalLogger))] // Force when explicitly set to "true"
[InlineData("-tl:on", true, false, "", typeof(TerminalLogger))] // Force when explicitly set to "on"
[InlineData("-tl:true", false, true, "", typeof(TerminalLogger))] // Force when explicitly set to "true"
[InlineData(null, false, false, "on", typeof(TerminalLogger))] // Force when env var set to "on"
[InlineData(null, false, false, "true", typeof(TerminalLogger))] // Force when env var set to "true"
[InlineData(null, true, false, "on", typeof(TerminalLogger))] // Force when env var set to "on"
[InlineData(null, false, true, "true", typeof(TerminalLogger))] // Force when env var set to "true"
[InlineData("-tl:auto", false, false, "", typeof(ConsoleLogger))] // Auto respects system capabilities (no ANSI, no screen)
[InlineData("-tl:auto", true, false, "", typeof(ConsoleLogger))] // Auto respects system capabilities (ANSI but no screen)
[InlineData("-tl:auto", false, true, "", typeof(ConsoleLogger))] // Auto respects system capabilities (screen but no ANSI)
[InlineData("-tl:auto", true, true, "", typeof(TerminalLogger))] // Auto respects system capabilities (both ANSI and screen)
[InlineData("-tl:auto", true, true, "off", typeof(TerminalLogger))] // Auto ignores env var when explicitly set
[InlineData("-tl:auto", false, false, "on", typeof(ConsoleLogger))] // Auto ignores env var and respects system capabilities
[InlineData(null, false, false, "auto", typeof(ConsoleLogger))] // Auto via env var respects system capabilities
[InlineData(null, true, true, "auto", typeof(TerminalLogger))] // Auto via env var respects system capabilities
public void CreateTerminalOrConsoleLogger_CreatesCorrectLoggerInstance(string? argsString, bool supportsAnsi, bool outputIsScreen, string evnVariableValue, Type expectedType)
{
using TestEnvironment testEnvironment = TestEnvironment.Create();
testEnvironment.SetEnvironmentVariable("MSBUILDTERMINALLOGGER", evnVariableValue);
string[]? args = argsString?.Split(' ');
(ILogger logger, _) = TerminalLogger.CreateTerminalOrConsoleLoggerWithForwarding(args, supportsAnsi, outputIsScreen, default);
logger.ShouldNotBeNull();
logger.GetType().ShouldBe(expectedType);
}
[Theory]
[InlineData("-v:q", LoggerVerbosity.Quiet)]
[InlineData("-verbosity:minimal", LoggerVerbosity.Minimal)]
[InlineData("--v:d", LoggerVerbosity.Detailed)]
[InlineData("/verbosity:diag", LoggerVerbosity.Diagnostic)]
[InlineData(null, LoggerVerbosity.Normal)]
public void CreateTerminalOrConsoleLogger_ParsesVerbosity(string? argsString, LoggerVerbosity expectedVerbosity)
{
string[]? args = argsString?.Split(' ');
(ILogger logger, _) = TerminalLogger.CreateTerminalOrConsoleLoggerWithForwarding(args, true, true, default);
logger.ShouldNotBeNull();
logger.Verbosity.ShouldBe(expectedVerbosity);
}
#region Helper methods to create BuildEventArgs with BuildEventContext
/// <summary>
/// Helper function to create a BuildEventContext keyed to specific scenarios.
/// When you want to refer to the same eval properties, use the same evalId.
/// When you want to refer to the same project, use the same projectContextId.
/// When you want to refer to the same node, use the same nodeId.
/// By default, nodeId, evalId, projectContextId, and targetId are all set to 1.
/// </summary>
private BuildEventContext MakeBuildEventContext(int evalId = 1, int projectContextId = 1, int nodeId = 1)
{
return new BuildEventContext(
submissionId: -1,
nodeId: nodeId,
evaluationId: evalId,
projectInstanceId: -1,
projectContextId: projectContextId,
targetId: 1,
taskId: 1);
}
private BuildStartedEventArgs MakeBuildStartedEventArgs(BuildEventContext? buildEventContext = null)
{
return new BuildStartedEventArgs(null, null, _buildStartTime)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private BuildFinishedEventArgs MakeBuildFinishedEventArgs(bool succeeded, BuildEventContext? buildEventContext = null)
{
return new BuildFinishedEventArgs(null, null, succeeded, _buildFinishTime)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private ProjectStartedEventArgs MakeProjectStartedEventArgs(string projectFile, string targetNames = "Build", BuildEventContext? buildEventContext = null)
{
return new ProjectStartedEventArgs("", "", projectFile, targetNames, new Dictionary<string, string>(), new List<DictionaryEntry>())
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private ProjectFinishedEventArgs MakeProjectFinishedEventArgs(string projectFile, bool succeeded, BuildEventContext? buildEventContext = null)
{
return new ProjectFinishedEventArgs(null, null, projectFile, succeeded)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private TargetStartedEventArgs MakeTargetStartedEventArgs(string projectFile, string targetName, BuildEventContext? buildEventContext = null)
{
return new TargetStartedEventArgs("", "", targetName, projectFile, targetFile: projectFile, String.Empty, TargetBuiltReason.None, _targetStartTime)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private TargetFinishedEventArgs MakeTargetFinishedEventArgs(string projectFile, string targetName, bool succeeded, BuildEventContext? buildEventContext = null)
{
return new TargetFinishedEventArgs("", "", targetName, projectFile, targetFile: projectFile, succeeded)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private TaskStartedEventArgs MakeTaskStartedEventArgs(string projectFile, string taskName, BuildEventContext? buildEventContext = null)
{
return new TaskStartedEventArgs("", "", projectFile, taskFile: projectFile, taskName)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private TaskFinishedEventArgs MakeTaskFinishedEventArgs(string projectFile, string taskName, bool succeeded, BuildEventContext? buildEventContext = null)
{
return new TaskFinishedEventArgs("", "", projectFile, taskFile: projectFile, taskName, succeeded)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private BuildWarningEventArgs MakeCopyRetryWarning(int retryCount, BuildEventContext? buildEventContext = null)
{
return new BuildWarningEventArgs("", "MSB3026", "directory/file", 1, 2, 3, 4,
$"MSB3026: Could not copy \"sourcePath\" to \"destinationPath\". Beginning retry {retryCount} in x ms.",
null, null)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private BuildMessageEventArgs MakeMessageEventArgs(string message, MessageImportance importance, string? code = null, string? keyword = "keyword", BuildEventContext? buildEventContext = null)
{
return new BuildMessageEventArgs(message: message, helpKeyword: keyword, senderName: null, importance: importance, eventTimestamp: DateTime.UtcNow, lineNumber: 0, columnNumber: 0, endLineNumber: 0, endColumnNumber: 0, code: code, subcategory: null, file: null)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private BuildMessageEventArgs MakeBuildOutputEventArgs(string projectFilePath, BuildEventContext? buildEventContext = null)
{
var projectName = Path.GetFileNameWithoutExtension(projectFilePath);
var outputPath = Path.ChangeExtension(projectFilePath, "dll");
var messageString = $"{projectName} -> {outputPath}";
var args = MakeMessageEventArgs(messageString, MessageImportance.High, buildEventContext: buildEventContext);
args.ProjectFile = projectFilePath;
return args;
}
private BuildMessageEventArgs MakeTaskCommandLineEventArgs(string message, MessageImportance importance, BuildEventContext? buildEventContext = null)
{
return new TaskCommandLineEventArgs(message, "Task", importance)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private BuildMessageEventArgs MakeExtendedMessageEventArgs(string message, MessageImportance importance, string extendedType, Dictionary<string, string?>? extendedMetadata, BuildEventContext? buildEventContext = null)
{
return new ExtendedBuildMessageEventArgs(extendedType, message, "keyword", null, importance, _messageTime)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
ExtendedMetadata = extendedMetadata
};
}
private BuildErrorEventArgs MakeErrorEventArgs(string error, string? link = null, string? keyword = null, BuildEventContext? buildEventContext = null)
{
return new BuildErrorEventArgs(subcategory: null, code: "AA0000", file: "directory/file", lineNumber: 1, columnNumber: 2, endLineNumber: 3, endColumnNumber: 4, message: error, helpKeyword: keyword, helpLink: link, senderName: null, eventTimestamp: DateTime.UtcNow)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private BuildWarningEventArgs MakeWarningEventArgs(string warning, string? link = null, string? keyword = null, BuildEventContext? buildEventContext = null)
{
return new BuildWarningEventArgs(subcategory: null, code: "AA0000", file: "directory/file", lineNumber: 1, columnNumber: 2, endLineNumber: 3, endColumnNumber: 4, message: warning, helpKeyword: keyword, helpLink: link, senderName: null, eventTimestamp: DateTime.UtcNow)
{
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
#endregion
#region Build summary tests
private void InvokeLoggerCallbacksForSimpleProject(bool succeeded, Action? additionalCallbacks = null, string? projectFile = null, List<(string, string)>? properties = null)
{
projectFile ??= _projectFile;
_centralNodeEventSource.InvokeBuildStarted(MakeBuildStartedEventArgs());
_centralNodeEventSource.InvokeStatusEventRaised(MakeProjectEvalFinishedArgs(projectFile, properties: properties));
_centralNodeEventSource.InvokeProjectStarted(MakeProjectStartedEventArgs(projectFile));
_centralNodeEventSource.InvokeTargetStarted(MakeTargetStartedEventArgs(projectFile, "Build"));
_centralNodeEventSource.InvokeTaskStarted(MakeTaskStartedEventArgs(projectFile, "Task"));
additionalCallbacks?.Invoke();
_centralNodeEventSource.InvokeTaskFinished(MakeTaskFinishedEventArgs(projectFile, "Task", succeeded));
_centralNodeEventSource.InvokeTargetFinished(MakeTargetFinishedEventArgs(projectFile, "Build", succeeded));
_centralNodeEventSource.InvokeProjectFinished(MakeProjectFinishedEventArgs(projectFile, succeeded));
_centralNodeEventSource.InvokeBuildFinished(MakeBuildFinishedEventArgs(succeeded));
}
private ProjectEvaluationFinishedEventArgs MakeProjectEvalFinishedArgs(string projectFile, List<(string, string)>? properties = null, List<(string, string)>? items = null, BuildEventContext? buildEventContext = null)
{
return new ProjectEvaluationFinishedEventArgs
{
ProjectFile = projectFile,
Properties = properties?.ToDictionary(k => k.Item1, v => v.Item2) ?? new Dictionary<string, string>(),
Items = items?.Select(kvp => new DictionaryEntry(kvp.Item1, kvp.Item2)).ToList() ?? new List<DictionaryEntry>(),
BuildEventContext = buildEventContext ?? MakeBuildEventContext(),
};
}
private void InvokeLoggerCallbacksForTestProject(bool succeeded, Action additionalCallbacks)
{
_centralNodeEventSource.InvokeBuildStarted(MakeBuildStartedEventArgs());
_centralNodeEventSource.InvokeStatusEventRaised(MakeProjectEvalFinishedArgs(_projectFile));
_centralNodeEventSource.InvokeProjectStarted(MakeProjectStartedEventArgs(_projectFile));
_centralNodeEventSource.InvokeTargetStarted(MakeTargetStartedEventArgs(_projectFile, "_TestRunStart"));
_centralNodeEventSource.InvokeTaskStarted(MakeTaskStartedEventArgs(_projectFile, "Task"));
additionalCallbacks();
_centralNodeEventSource.InvokeTaskFinished(MakeTaskFinishedEventArgs(_projectFile, "Task", succeeded));
_centralNodeEventSource.InvokeTargetFinished(MakeTargetFinishedEventArgs(_projectFile, "_TestRunStart", succeeded));
_centralNodeEventSource.InvokeProjectFinished(MakeProjectFinishedEventArgs(_projectFile, succeeded));
_centralNodeEventSource.InvokeBuildFinished(MakeBuildFinishedEventArgs(succeeded));
}
private void InvokeLoggerCallbacksForTwoProjects(bool succeeded, Action additionalCallbacks, Action additionalCallbacks2)
{
_centralNodeEventSource.InvokeBuildStarted(MakeBuildStartedEventArgs());
var p1BuildContext = MakeBuildEventContext(evalId: 1, projectContextId: 1);
_centralNodeEventSource.InvokeStatusEventRaised(MakeProjectEvalFinishedArgs(_projectFile, buildEventContext: p1BuildContext));
_centralNodeEventSource.InvokeProjectStarted(MakeProjectStartedEventArgs(_projectFile, buildEventContext: p1BuildContext));
_centralNodeEventSource.InvokeTargetStarted(MakeTargetStartedEventArgs(_projectFile, "Build1", buildEventContext: p1BuildContext));
_centralNodeEventSource.InvokeTaskStarted(MakeTaskStartedEventArgs(_projectFile, "Task1", buildEventContext: p1BuildContext));
additionalCallbacks();
_centralNodeEventSource.InvokeTaskFinished(MakeTaskFinishedEventArgs(_projectFile, "Task1", succeeded, buildEventContext: p1BuildContext));
_centralNodeEventSource.InvokeTargetFinished(MakeTargetFinishedEventArgs(_projectFile, "Build1", succeeded, buildEventContext: p1BuildContext));
_centralNodeEventSource.InvokeProjectFinished(MakeProjectFinishedEventArgs(_projectFile, succeeded, buildEventContext: p1BuildContext));
var p2BuildContext = MakeBuildEventContext(evalId: 2, projectContextId: 2);
_centralNodeEventSource.InvokeStatusEventRaised(MakeProjectEvalFinishedArgs(_projectFile2, buildEventContext: p2BuildContext));
_centralNodeEventSource.InvokeProjectStarted(MakeProjectStartedEventArgs(_projectFile2, buildEventContext: p2BuildContext));
_centralNodeEventSource.InvokeTargetStarted(MakeTargetStartedEventArgs(_projectFile2, "Build2", buildEventContext: p2BuildContext));
_centralNodeEventSource.InvokeTaskStarted(MakeTaskStartedEventArgs(_projectFile2, "Task2", buildEventContext: p2BuildContext));
additionalCallbacks2();
_centralNodeEventSource.InvokeTaskFinished(MakeTaskFinishedEventArgs(_projectFile2, "Task2", succeeded, buildEventContext: p2BuildContext));
_centralNodeEventSource.InvokeTargetFinished(MakeTargetFinishedEventArgs(_projectFile2, "Build2", succeeded, buildEventContext: p2BuildContext));
_centralNodeEventSource.InvokeProjectFinished(MakeProjectFinishedEventArgs(_projectFile2, succeeded, buildEventContext: p2BuildContext));
_centralNodeEventSource.InvokeBuildFinished(MakeBuildFinishedEventArgs(succeeded));
}
[Fact]
public Task PrintsBuildSummary_Succeeded()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () => { });
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummary_SucceededWithWarnings()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("A\nMulti\r\nLine\nWarning!"));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintImmediateWarningMessage_Succeeded()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("[CredentialProvider]DeviceFlow: https://testfeed/index.json"));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs(
"[CredentialProvider]ATTENTION: User interaction required." +
"**********************************************************************" +
"To sign in, use a web browser to open the page https://devicelogin and enter the code XXXXXX to authenticate." +
"**********************************************************************"));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintCopyTaskRetryWarningAsImmediateMessage_Failed()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: false, () =>
{
_centralNodeEventSource.InvokeWarningRaised(MakeCopyRetryWarning(1));
_centralNodeEventSource.InvokeWarningRaised(MakeCopyRetryWarning(2));
_centralNodeEventSource.InvokeWarningRaised(MakeCopyRetryWarning(3));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintImmediateMessage_Success()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs(_immediateMessageString, MessageImportance.High));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintImmediateMessage_Skipped()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs("--anycustomarg", MessageImportance.High));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintRestore_Failed()
{
_centralNodeEventSource.InvokeBuildStarted(MakeBuildStartedEventArgs());
bool succeeded = false;
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Restore Failed"));
_centralNodeEventSource.InvokeProjectFinished(MakeProjectFinishedEventArgs(_projectFile, succeeded));
_centralNodeEventSource.InvokeBuildFinished(MakeBuildFinishedEventArgs(succeeded));
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintRestore_SuccessWithWarnings()
{
_centralNodeEventSource.InvokeBuildStarted(MakeBuildStartedEventArgs());
bool succeeded = true;
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Restore with Warning"));
_centralNodeEventSource.InvokeProjectFinished(MakeProjectFinishedEventArgs(_projectFile, succeeded));
_centralNodeEventSource.InvokeBuildFinished(MakeBuildFinishedEventArgs(succeeded));
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummary_Failed()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: false, () => { });
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummary_FailedWithErrors()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: false, () =>
{
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error!"));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintDetailedBuildSummary_FailedWithErrorAndWarning()
{
string? originalParameters = _terminallogger.Parameters;
_terminallogger.Parameters = "SUMMARY";
_terminallogger.ParseParameters();
InvokeLoggerCallbacksForSimpleProject(succeeded: false, () =>
{
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning!"));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error!"));
});
// Restore original parameters
_terminallogger.Parameters = originalParameters;
_terminallogger.ParseParameters();
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummary_FailedWithErrorsAndWarnings()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: false, () =>
{
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning1!"));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning2!"));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error1!"));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error2!"));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummary_2Projects_FailedWithErrorsAndWarnings()
{
InvokeLoggerCallbacksForTwoProjects(
succeeded: false,
() =>
{
var p1Context = MakeBuildEventContext(evalId: 1, projectContextId: 1);
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning1!", buildEventContext: p1Context));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning2!", buildEventContext: p1Context));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error1!", buildEventContext: p1Context));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error2!", buildEventContext: p1Context));
},
() =>
{
var p2Context = MakeBuildEventContext(evalId: 2, projectContextId: 2);
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning3!", buildEventContext: p2Context));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning4!", buildEventContext: p2Context));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error3!", buildEventContext: p2Context));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error4!", buildEventContext: p2Context));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintProjectOutputDirectoryLink()
{
// Send message in order to set project output path
BuildMessageEventArgs e = MakeBuildOutputEventArgs(_projectFileWithNonAnsiSymbols);
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeMessageRaised(e);
}, _projectFileWithNonAnsiSymbols);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
#endregion
#region Helper methods to call specific orders of messages
private void CallAllTypesOfMessagesWarningAndError()
{
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs(_immediateMessageString, MessageImportance.High));
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs("High importance message!", MessageImportance.High));
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs("Normal importance message!", MessageImportance.Normal));
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs("Low importance message!", MessageImportance.Low));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("Warning!"));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("A\nMulti\r\nLine\nWarning!"));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("Error!"));
}
private void CallAllTypesOfTestMessages()
{
_centralNodeEventSource.InvokeMessageRaised(MakeExtendedMessageEventArgs(
"Test passed.",
MessageImportance.High,
"TLTESTPASSED",
new Dictionary<string, string?>() { { "displayName", "testName1" }, { "localizedResult", "passed" } }));
_centralNodeEventSource.InvokeMessageRaised(MakeExtendedMessageEventArgs(
"Test skipped.",
MessageImportance.High,
"TLTESTSKIPPED",
new Dictionary<string, string?>() { { "displayName", "testName2" }, { "localizedResult", "skipped" } }));
_centralNodeEventSource.InvokeMessageRaised(MakeExtendedMessageEventArgs(
"Test results.",
MessageImportance.High,
"TLTESTFINISH",
new Dictionary<string, string?>() { { "total", "10" }, { "passed", "7" }, { "skipped", "2" }, { "failed", "1" } }));
}
#endregion
[Fact]
public Task PrintBuildSummaryQuietVerbosity_FailedWithErrors()
{
_terminallogger.Verbosity = LoggerVerbosity.Quiet;
InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummaryMinimalVerbosity_FailedWithErrors()
{
_terminallogger.Verbosity = LoggerVerbosity.Minimal;
InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task LogEvaluationErrorFromEngine()
{
_terminallogger.Verbosity = LoggerVerbosity.Normal;
InvokeLoggerCallbacksForSimpleProject(succeeded: false, () =>
{
_centralNodeEventSource.InvokeErrorRaised(new BuildErrorEventArgs(
"MSB0001", "EvaluationError", "MSBUILD", 0, 0, 0, 0,
"An error occurred during evaluation.", null, null)
{
BuildEventContext = new BuildEventContext(1, -1, -1, -1) // context that belongs to no project
});
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummaryNormalVerbosity_FailedWithErrors()
{
_terminallogger.Verbosity = LoggerVerbosity.Normal;
InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummaryDetailedVerbosity_FailedWithErrors()
{
_terminallogger.Verbosity = LoggerVerbosity.Detailed;
InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintBuildSummaryDiagnosticVerbosity_FailedWithErrors()
{
_terminallogger.Verbosity = LoggerVerbosity.Diagnostic;
InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintTestSummaryNormalVerbosity_Succeeded()
{
_terminallogger.Verbosity = LoggerVerbosity.Normal;
InvokeLoggerCallbacksForTestProject(succeeded: true, CallAllTypesOfTestMessages);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintTestSummaryQuietVerbosity_Succeeded()
{
_terminallogger.Verbosity = LoggerVerbosity.Quiet;
InvokeLoggerCallbacksForTestProject(succeeded: true, CallAllTypesOfTestMessages);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintSummaryWithOverwrittenVerbosity_FailedWithErrors()
{
_terminallogger.Verbosity = LoggerVerbosity.Minimal;
_terminallogger.Parameters = "v=diag";
_terminallogger.ParseParameters();
InvokeLoggerCallbacksForSimpleProject(succeeded: false, CallAllTypesOfMessagesWarningAndError);
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintSummaryWithTaskCommandLineEventArgs_Succeeded()
{
_terminallogger.Verbosity = LoggerVerbosity.Detailed;
_terminallogger.Parameters = "SHOWCOMMANDLINE=on";
_terminallogger.ParseParameters();
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeMessageRaised(MakeTaskCommandLineEventArgs("Task Command Line.", MessageImportance.High));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public Task PrintSummaryWithoutTaskCommandLineEventArgs_Succeeded()
{
_terminallogger.Verbosity = LoggerVerbosity.Detailed;
_terminallogger.Parameters = "SHOWCOMMANDLINE=off";
_terminallogger.ParseParameters();
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeMessageRaised(MakeTaskCommandLineEventArgs("Task Command Line.", MessageImportance.High));
});
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public void DisplayNodesShowsCurrent()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: false, async () =>
{
_terminallogger.DisplayNodes();
await Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
});
}
[Fact]
public void DisplayNodesOverwritesTime()
{
List<MockStopwatch> stopwatches = new();
Func<StopwatchAbstraction>? createStopwatch = _terminallogger._createStopwatch;
try
{
_terminallogger._createStopwatch = () =>
{
MockStopwatch stopwatch = new();
stopwatches.Add(stopwatch);
return stopwatch;
};
InvokeLoggerCallbacksForSimpleProject(succeeded: false, async () =>
{
foreach (var stopwatch in stopwatches)
{
// Tick time forward by at least 10 seconds,
// as a regression test for https://github.com/dotnet/msbuild/issues/9562
stopwatch.Tick(111.0);
}
_terminallogger.DisplayNodes();
await Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
});
}
finally
{
_terminallogger._createStopwatch = createStopwatch;
}
}
[Fact]
public async Task DisplayNodesOverwritesWithNewTargetFramework()
{
_centralNodeEventSource.InvokeBuildStarted(MakeBuildStartedEventArgs());
_centralNodeEventSource.InvokeStatusEventRaised(MakeProjectEvalFinishedArgs(_projectFile, properties: [("TargetFramework", "tfName")]));
_centralNodeEventSource.InvokeProjectStarted(MakeProjectStartedEventArgs(_projectFile, "Build"));
_centralNodeEventSource.InvokeTargetStarted(MakeTargetStartedEventArgs(_projectFile, "Build"));
_centralNodeEventSource.InvokeTaskStarted(MakeTaskStartedEventArgs(_projectFile, "Task"));
_terminallogger.DisplayNodes();
// force the current node to stop building and 'yield'
_centralNodeEventSource.InvokeTaskStarted(MakeTaskStartedEventArgs(_projectFile, "MSBuild"));
// now create a new project with a different target framework that runs on the same node
var buildContext2 = MakeBuildEventContext(evalId: 2, projectContextId: 2);
_centralNodeEventSource.InvokeStatusEventRaised(MakeProjectEvalFinishedArgs(_projectFile, properties: [("TargetFramework", "tf2")], buildEventContext: buildContext2));
_centralNodeEventSource.InvokeProjectStarted(MakeProjectStartedEventArgs(_projectFile, "Build", buildEventContext: buildContext2));
_centralNodeEventSource.InvokeTargetStarted(MakeTargetStartedEventArgs(_projectFile, "Build", buildEventContext: buildContext2));
_terminallogger.DisplayNodes();
await Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public void TestTerminalLoggerTogetherWithOtherLoggers()
{
using (TestEnvironment env = TestEnvironment.Create())
{
string contents = @"
<Project>
<ItemGroup>
<Compile Include=""MyItem1.cs"" />
<Compile Include=""MyItem2.cs"" />
</ItemGroup>
<PropertyGroup>
<MyProp1>MyProperty1</MyProp1>
</PropertyGroup>
<Target Name = ""Build"">
<Message Text = ""Build target is executing."" Importance = ""High"" />
</Target>
</Project>";
TransientTestFolder logFolder = env.CreateFolder(createFolder: true);
TransientTestFile projectFile = env.CreateFile(logFolder, "myProj.proj", contents);
string logFileWithTL = env.ExpectFile(".binlog").Path;
string logFileWithoutTL = env.ExpectFile(".binlog").Path;
// Execute MSBuild with binary, file and terminal loggers
RunnerUtilities.ExecMSBuild($"{projectFile.Path} /bl:{logFileWithTL} -flp:logfile={Path.Combine(logFolder.Path, "logFileWithTL.log")};verbosity=diagnostic -tl:on", out bool success, outputHelper: _outputHelper);
success.ShouldBeTrue();
// Execute MSBuild with binary and file loggers
RunnerUtilities.ExecMSBuild($"{projectFile.Path} /bl:{logFileWithoutTL} -flp:logfile={Path.Combine(logFolder.Path, "logFileWithoutTL.log")};verbosity=diagnostic", out success, outputHelper: _outputHelper);
success.ShouldBeTrue();
// Read the binary log and replay into mockLogger
var mockLogFromPlaybackWithTL = new MockLogger();
var binaryLogReaderWithTL = new BinaryLogReplayEventSource();
mockLogFromPlaybackWithTL.Initialize(binaryLogReaderWithTL);
var mockLogFromPlaybackWithoutTL = new MockLogger();
var binaryLogReaderWithoutTL = new BinaryLogReplayEventSource();
mockLogFromPlaybackWithoutTL.Initialize(binaryLogReaderWithoutTL);
binaryLogReaderWithTL.Replay(logFileWithTL);
binaryLogReaderWithoutTL.Replay(logFileWithoutTL);
// Check that amount of warnings and errors is equal in both cases. Presence of other loggers should not change behavior
mockLogFromPlaybackWithoutTL.Errors.Count.ShouldBe(mockLogFromPlaybackWithTL.Errors.Count);
mockLogFromPlaybackWithoutTL.Warnings.Count.ShouldBe(mockLogFromPlaybackWithTL.Warnings.Count);
// Note: We don't compare AllBuildEvents.Count because internal events can vary between runs and with different logger configurations
// Check presence of some items and properties and that they have at least 1 item and property
mockLogFromPlaybackWithoutTL.EvaluationFinishedEvents.ShouldContain(x => (x.Items != null) && x.Items.GetEnumerator().MoveNext());
mockLogFromPlaybackWithTL.EvaluationFinishedEvents.ShouldContain(x => (x.Items != null) && x.Items.GetEnumerator().MoveNext());
mockLogFromPlaybackWithoutTL.EvaluationFinishedEvents.ShouldContain(x => (x.Properties != null) && x.Properties.GetEnumerator().MoveNext());
mockLogFromPlaybackWithTL.EvaluationFinishedEvents.ShouldContain(x => (x.Properties != null) && x.Properties.GetEnumerator().MoveNext());
}
}
[Fact]
public async Task PrintMessageLinks()
{
_terminallogger.Verbosity = LoggerVerbosity.Detailed;
_terminallogger.ParseParameters();
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs("this message has a link because it has a code and a keyword", MessageImportance.High, code: "1234", keyword: "keyword"));
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs("this message has no link because it only has a code", MessageImportance.High, code: "1234", keyword: null));
_centralNodeEventSource.InvokeMessageRaised(MakeMessageEventArgs("this message has no link because it only has a keyword", MessageImportance.High, keyword: "keyword"));
});
await Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public async Task PrintWarningLinks()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("this warning has a link because it has an explicit link", link: "https://example.com"));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("this warning has a link because it has a keyword", keyword: "keyword"));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("this warning has a link to example.com because links take precedence over keywords", link: "https://example.com", keyword: "keyword"));
_centralNodeEventSource.InvokeWarningRaised(MakeWarningEventArgs("this warning has no link because it has no link or keyword"));
});
await Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public async Task PrintErrorLinks()
{
InvokeLoggerCallbacksForSimpleProject(succeeded: true, () =>
{
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("this error has a link because it has an explicit link", link: "https://example.com"));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("this error has a link because it has a keyword", keyword: "keyword"));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("this error has a link to example.com because links take precedence over keywords", link: "https://example.com", keyword: "keyword"));
_centralNodeEventSource.InvokeErrorRaised(MakeErrorEventArgs("this error has no link because it has no link or keyword"));
});
await Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}
[Fact]
public async Task ProjectFinishedReportsRuntimeIdentifier()
{
// this project will report a RID and so will show a RID in the build output