Repository navigation
Expand file tree
/
Copy pathCrashDumpTests.cs
More file actions
1068 lines (939 loc) · 49.8 KB
/
Copy pathCrashDumpTests.cs
File metadata and controls
1068 lines (939 loc) · 49.8 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Testing.Extensions.Diagnostics;
using Microsoft.Testing.Extensions.Diagnostics.Resources;
using Microsoft.Testing.Extensions.UnitTests.Helpers;
using Microsoft.Testing.Platform.Configurations;
using Microsoft.Testing.Platform.Extensions.CommandLine;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.OutputDevice;
using Microsoft.Testing.Platform.Extensions.TestHostControllers;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.Messages;
using Microsoft.Testing.Platform.OutputDevice;
using Moq;
namespace Microsoft.Testing.Extensions.UnitTests;
[TestClass]
public sealed class CrashDumpTests
{
// AppDomain.CurrentDomain.GetData/SetData("ProcessKilledByHangDump") is a process-wide data slot
// (see CrashDumpProcessLifetimeHandler.OnTestHostProcessExitedAsync and
// HangDumpProcessLifetimeHandler.DumpTaking). Only the single test method below reads or writes it,
// so a method-level lock on that one test is enough to serialize it against itself without forcing
// the whole class to run sequentially.
private const string ProcessKilledByHangDumpAppDomainDataResource = "Microsoft.Testing.Extensions.CrashDump.ProcessKilledByHangDumpAppDomainData";
[TestMethod]
[DataRow("Mini")]
[DataRow("Heap")]
[DataRow("Triage")]
[DataRow("Full")]
public async Task IsValid_If_CrashDumpType_Has_CorrectValue(string crashDumpType)
{
var provider = new CrashDumpCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == CrashDumpCommandLineOptions.CrashDumpTypeOptionName);
ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [crashDumpType]).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
[DataRow("invalid")]
[DataRow("None")]
public async Task IsInvalid_If_CrashDumpType_Has_IncorrectValue(string crashDumpType)
{
var provider = new CrashDumpCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == CrashDumpCommandLineOptions.CrashDumpTypeOptionName);
ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [crashDumpType]).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, CrashDumpResources.CrashDumpTypeOptionInvalidType, crashDumpType, "'Mini', 'Heap', 'Triage', 'Full'"), validateOptionsResult.ErrorMessage);
}
[TestMethod]
public async Task CrashDump_CommandLineOptions_Are_Valid_ByDefault()
{
var provider = new CrashDumpCommandLineProvider();
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions([])).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
[DataRow(CrashDumpCommandLineOptions.CrashDumpFileNameOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashDumpTypeOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashSequenceOptionName)]
public async Task Missing_CrashDumpMainOption_ShouldReturn_IsInvalid(string crashDumpArgument)
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ crashDumpArgument, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.AreEqual(CrashDumpResources.MissingCrashDumpMainOption, validateOptionsResult.ErrorMessage);
}
[TestMethod]
[DataRow(CrashDumpCommandLineOptions.CrashDumpFileNameOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashDumpTypeOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashSequenceOptionName)]
public async Task If_CrashDumpMainOption_IsSpecified_ShouldReturn_IsValid(string crashDumpArgument)
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ crashDumpArgument, [] },
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
[DataRow("on")]
[DataRow("off")]
[DataRow("true")]
[DataRow("false")]
[DataRow("enable")]
[DataRow("disable")]
[DataRow("1")]
[DataRow("0")]
[DataRow("TrUe")]
public async Task IsValid_If_CrashSequence_Has_CorrectValue(string value)
{
var provider = new CrashDumpCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == CrashDumpCommandLineOptions.CrashSequenceOptionName);
ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [value]).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid, validateOptionsResult.ErrorMessage);
Assert.IsNull(validateOptionsResult.ErrorMessage);
}
[TestMethod]
[DataRow("maybe")]
[DataRow("auto")]
[DataRow("")]
public async Task IsInvalid_If_CrashSequence_Has_IncorrectValue(string value)
{
var provider = new CrashDumpCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == CrashDumpCommandLineOptions.CrashSequenceOptionName);
ValidationResult validateOptionsResult = await provider.ValidateOptionArgumentsAsync(option, [value]).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.AreEqual(CrashDumpResources.CrashSequenceOptionInvalidArgument, validateOptionsResult.ErrorMessage);
}
[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Crash report is not supported on Windows (dotnet/runtime#80191)")]
[DataRow(CrashDumpCommandLineOptions.CrashDumpFileNameOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashDumpTypeOptionName)]
public async Task If_CrashReportMainOption_IsSpecified_ShouldReturn_IsValid(string crashDumpArgument)
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ crashDumpArgument, [] },
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Crash report is not supported on Windows (dotnet/runtime#80191)")]
public async Task CrashReport_Without_CrashDump_Is_Valid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Crash report is not supported on Windows (dotnet/runtime#80191)")]
public async Task CrashReport_Alongside_CrashDump_Is_Valid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
[OSCondition(ConditionMode.Include, OperatingSystems.Windows, IgnoreMessage = "Validates Windows-specific rejection of --crash-report")]
public async Task CrashReport_OnWindows_IsInvalid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.AreEqual(CrashDumpResources.CrashReportNotSupportedOnWindowsErrorMessage, validateOptionsResult.ErrorMessage);
}
[TestMethod]
[OSCondition(ConditionMode.Include, OperatingSystems.Windows, IgnoreMessage = "Validates Windows-specific rejection of --crash-report")]
public async Task CrashReport_WithCrashDump_OnWindows_IsInvalid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.AreEqual(CrashDumpResources.CrashReportNotSupportedOnWindowsErrorMessage, validateOptionsResult.ErrorMessage);
}
[TestMethod]
public async Task CrashReportIfSupported_Without_CrashDump_Is_Valid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
public async Task CrashReportIfSupported_Alongside_CrashDump_Is_Valid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
{ CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
public async Task CrashReportIfSupported_OnAnyPlatform_IsValid()
{
// Unlike '--crash-report', the '-if-supported' variant must never be rejected by
// platform validation: that is the whole point of the option. Cover all OSes in a
// single test to make a future regression obvious.
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
public async Task CrashReport_And_CrashReportIfSupported_Together_IsInvalid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
{ CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.AreEqual(CrashDumpResources.CrashReportAndIfSupportedAreMutuallyExclusiveErrorMessage, validateOptionsResult.ErrorMessage);
}
[TestMethod]
[DataRow(CrashDumpCommandLineOptions.CrashDumpFileNameOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashDumpTypeOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashSequenceOptionName)]
public async Task CrashReportIfSupported_SatisfiesMainOptionRequirement(string subOption)
{
// '--crash-report-if-supported' should count as a "main" CrashDump option so that
// sub-options like '--crashdump-type' do not produce a "missing main option" error.
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName, [] },
{ subOption, ["value"] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}
[TestMethod]
[OSCondition(ConditionMode.Include, OperatingSystems.Windows, IgnoreMessage = "Validates Windows-specific fallback wording in '--crash-report' error.")]
public async Task CrashReport_OnWindows_ErrorPointsToIfSupportedAlternative()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
};
ValidationResult validateOptionsResult = await provider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)).ConfigureAwait(false);
Assert.IsFalse(validateOptionsResult.IsValid);
Assert.Contains("--crash-report-if-supported", validateOptionsResult.ErrorMessage);
}
[TestMethod]
[DataRow(CrashDumpCommandLineOptions.CrashReportOptionName)]
[DataRow(CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName)]
public async Task ProviderRegistersBothCrashReportVariantsAsZeroArityOptions(string optionName)
{
var provider = new CrashDumpCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions().First(x => x.Name == optionName);
Assert.AreEqual(ArgumentArity.Zero, option.Arity);
}
[TestMethod]
public void IsCrashReportEffective_ReturnsTrue_When_StrictCrashReport_IsSet()
{
// The strict '--crash-report' always opts the user in: any "is this effective?" check
// should follow suit regardless of the runtime / OS.
var options = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
});
Assert.IsTrue(CrashDumpEnvironmentVariableProvider.IsCrashReportEffective(options));
}
[TestMethod]
public void IsCrashReportEffective_ReturnsFalse_When_NoCrashReportOption_IsSet()
{
var options = new TestCommandLineOptions([]);
Assert.IsFalse(CrashDumpEnvironmentVariableProvider.IsCrashReportEffective(options));
}
[TestMethod]
public void IsCrashReportEffective_With_IfSupported_MatchesCurrentRuntimeAndPlatform()
{
// The "-if-supported" variant is effective only when the underlying runtime can honor
// the request. This test mirrors the production check so that any divergence between
// the helper and what the env-var provider / lifetime handler rely on is caught.
var options = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName, [] },
});
#if !NETCOREAPP
// .NET Framework: the env-var-based createdump/crashreport mechanism is unavailable,
// so the option is a no-op regardless of the OS.
Assert.IsFalse(CrashDumpEnvironmentVariableProvider.IsCrashReportEffective(options));
#else
bool expected = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
Assert.AreEqual(expected, CrashDumpEnvironmentVariableProvider.IsCrashReportEffective(options));
#endif
}
[TestMethod]
[DataRow(false, false, false, true, false)]
[DataRow(true, false, false, true, true)]
[DataRow(false, true, false, true, true)]
[DataRow(false, false, true, true, true)]
[DataRow(true, true, true, false, false)]
public async Task IsEnabledAsync_OptionsAndConfiguration_ReturnsExpectedResult(
bool crashDump,
bool crashReport,
bool crashReportIfSupported,
bool configurationEnabled,
bool expected)
{
var options = new Dictionary<string, string[]>();
if (crashDump)
{
options.Add(CrashDumpCommandLineOptions.CrashDumpOptionName, []);
}
if (crashReport)
{
options.Add(CrashDumpCommandLineOptions.CrashReportOptionName, []);
}
if (crashReportIfSupported)
{
options.Add(CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName, []);
}
var handler = new CrashDumpProcessLifetimeHandler(
new TestCommandLineOptions(options),
new RecordingMessageBus(),
new NullOutputDevice(),
new CrashDumpConfiguration { Enable = configurationEnabled });
Assert.AreEqual(expected, await handler.IsEnabledAsync().ConfigureAwait(false));
}
[TestMethod]
public async Task BeforeTestHostProcessStartAsync_CrashReportIfSupported_DisplaysUnsupportedMessageOnce()
{
var outputDevice = new CapturingOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(
new TestCommandLineOptions(new Dictionary<string, string[]>
{
[CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName] = [],
}),
new RecordingMessageBus(),
outputDevice,
new CrashDumpConfiguration());
await handler.BeforeTestHostProcessStartAsync(CancellationToken.None).ConfigureAwait(false);
await handler.BeforeTestHostProcessStartAsync(CancellationToken.None).ConfigureAwait(false);
#if NETCOREAPP
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.AreSequenceEqual([CrashDumpResources.CrashReportIfSupportedIgnoredOnWindowsInfoMessage], outputDevice.Displayed);
}
else
{
Assert.IsEmpty(outputDevice.Displayed);
}
#else
Assert.AreSequenceEqual([CrashDumpResources.CrashReportIfSupportedIgnoredOnNetFrameworkInfoMessage], outputDevice.Displayed);
#endif
}
[TestMethod]
public async Task BeforeTestHostProcessStartAsync_StrictCrashReportIsSet_DoesNotDisplayUnsupportedMessage()
{
var outputDevice = new CapturingOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(
new TestCommandLineOptions(new Dictionary<string, string[]>
{
[CrashDumpCommandLineOptions.CrashReportOptionName] = [],
[CrashDumpCommandLineOptions.CrashReportIfSupportedOptionName] = [],
}),
new RecordingMessageBus(),
outputDevice,
new CrashDumpConfiguration());
await handler.BeforeTestHostProcessStartAsync(CancellationToken.None).ConfigureAwait(false);
Assert.IsEmpty(outputDevice.Displayed);
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_CrashHandlingDisabled_DoesNotDeleteSequenceFileOrPublishArtifacts()
{
string sequenceFile = Path.GetTempFileName();
try
{
var messageBus = new RecordingMessageBus();
var handler = new CrashDumpProcessLifetimeHandler(
new TestCommandLineOptions([]),
messageBus,
new NullOutputDevice(),
new CrashDumpConfiguration { SequenceFileName = sequenceFile });
await handler.OnTestHostProcessExitedAsync(
new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false),
CancellationToken.None).ConfigureAwait(false);
Assert.IsTrue(File.Exists(sequenceFile));
Assert.IsEmpty(messageBus.Published);
}
finally
{
File.Delete(sequenceFile);
}
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_GracefulExit_DeletesSequenceFileAndDoesNotPublishArtifacts()
{
string sequenceFile = Path.GetTempFileName();
try
{
var messageBus = new RecordingMessageBus();
var handler = new CrashDumpProcessLifetimeHandler(
new TestCommandLineOptions(new Dictionary<string, string[]>
{
[CrashDumpCommandLineOptions.CrashDumpOptionName] = [],
}),
messageBus,
new NullOutputDevice(),
new CrashDumpConfiguration { SequenceFileName = sequenceFile });
await handler.OnTestHostProcessExitedAsync(
new TestHostProcessInformation(pid: 123, exitCode: 0, hasExitedGracefully: true),
CancellationToken.None).ConfigureAwait(false);
Assert.IsFalse(File.Exists(sequenceFile));
Assert.IsEmpty(messageBus.Published);
}
finally
{
File.Delete(sequenceFile);
}
}
[TestMethod]
[ResourceLock(ProcessKilledByHangDumpAppDomainDataResource)]
public async Task OnTestHostProcessExitedAsync_ProcessKilledByHangDump_DeletesSequenceFileAndDoesNotPublishArtifacts()
{
string sequenceFile = Path.GetTempFileName();
object? processKilledByHangDump = AppDomain.CurrentDomain.GetData("ProcessKilledByHangDump");
try
{
AppDomain.CurrentDomain.SetData("ProcessKilledByHangDump", "true");
var messageBus = new RecordingMessageBus();
var handler = new CrashDumpProcessLifetimeHandler(
new TestCommandLineOptions(new Dictionary<string, string[]>
{
[CrashDumpCommandLineOptions.CrashDumpOptionName] = [],
}),
messageBus,
new NullOutputDevice(),
new CrashDumpConfiguration { SequenceFileName = sequenceFile });
await handler.OnTestHostProcessExitedAsync(
new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false),
CancellationToken.None).ConfigureAwait(false);
Assert.IsFalse(File.Exists(sequenceFile));
Assert.IsEmpty(messageBus.Published);
}
finally
{
AppDomain.CurrentDomain.SetData("ProcessKilledByHangDump", processKilledByHangDump);
File.Delete(sequenceFile);
}
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_PreCancelledToken_ThrowsBeforeHandlingExit()
{
string sequenceFile = Path.GetTempFileName();
try
{
var messageBus = new RecordingMessageBus();
var handler = new CrashDumpProcessLifetimeHandler(
new TestCommandLineOptions(new Dictionary<string, string[]>
{
[CrashDumpCommandLineOptions.CrashDumpOptionName] = [],
}),
messageBus,
new NullOutputDevice(),
new CrashDumpConfiguration { SequenceFileName = sequenceFile });
using var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.Cancel();
await Assert.ThrowsExactlyAsync<OperationCanceledException>(() => handler.OnTestHostProcessExitedAsync(
new TestHostProcessInformation(pid: 123, exitCode: 0, hasExitedGracefully: true),
cancellationTokenSource.Token));
Assert.IsTrue(File.Exists(sequenceFile));
Assert.IsEmpty(messageBus.Published);
}
finally
{
File.Delete(sequenceFile);
}
}
[TestMethod]
[DataRow("trailing%", "^trailing%$")]
// Glob metacharacters that may appear literally in a user-supplied filename must be escaped so they are
// matched literally, not treated as wildcards. This guards against picking up unrelated dump files on
// file systems that allow these characters in file names (e.g. Linux/macOS).
[DataRow("my*dump_%p.dmp", @"^my\*dump_.*\.dmp$")]
[DataRow("dump?_%p.dmp", @"^dump\?_.*\.dmp$")]
// The .NET runtime's createdump tool treats "%%" as an escape for a literal '%'. The regex builder
// must preserve that: "%%" stays a literal percent rather than collapsing into a ".*" wildcard
// (which would otherwise over-match unrelated files).
[DataRow("My%%App_%p.dmp", @"^My%App_.*\.dmp$")]
[DataRow("%%%p.dmp", @"^%.*\.dmp$")]
[DataRow("%p%%.dmp", @"^.*%\.dmp$")]
public void BuildDumpFileNameRegexPattern_ConvertsPlaceholdersToRegex(string fileName, string expected)
{
string actual = CrashDumpProcessLifetimeHandler.BuildDumpFileNameRegexPattern(fileName);
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void BuildDumpFileNameRegex_LiteralGlobMetacharactersInName_DoesNotOverMatch()
{
Regex regex = CrashDumpProcessLifetimeHandler.BuildDumpFileNameRegex("my*dump_%p.dmp");
Assert.IsTrue(regex.IsMatch("my*dump_123.dmp"), "Literal '*' must be matched literally.");
Assert.IsFalse(regex.IsMatch("myXYZdump_123.dmp"), "Literal '*' must not act as a wildcard.");
Assert.IsFalse(regex.IsMatch("mydump_123.dmp"), "Literal '*' must require at least the '*' character to be present.");
}
[TestMethod]
public void BuildDumpFileNameRegex_LiteralPercentInName_DoesNotOverMatch()
{
Regex regex = CrashDumpProcessLifetimeHandler.BuildDumpFileNameRegex("My%%App_%p.dmp");
Assert.IsTrue(regex.IsMatch("My%App_123.dmp"), "Literal '%' must be matched literally.");
Assert.IsFalse(regex.IsMatch("MyApp_123.dmp"), "Literal '%' must require the '%' character to be present.");
Assert.IsFalse(regex.IsMatch("MyXApp_123.dmp"), "Literal '%' must not be treated as a wildcard.");
}
[TestMethod]
[DataRow("dump_%p.dmp")]
[DataRow("")]
[DataRow("customdumpname.dmp")]
public void GetDumpDirectory_WhenPatternHasNoDirectoryComponent_ReturnsCurrentDirectory(string pattern)
{
// The CrashDump runtime writes dumps to the current working directory when the configured pattern
// contains no directory prefix. Previously the extension's enumeration was silently skipped in that
// case because Path.GetDirectoryName returns "" (not null), and Directory.Exists("") is false.
string actual = CrashDumpProcessLifetimeHandler.GetDumpDirectory(pattern);
Assert.AreEqual(".", actual);
}
[TestMethod]
public void GetDumpDirectory_WhenPatternHasDirectoryComponent_ReturnsDirectory()
{
string directory = Path.Combine(Path.GetTempPath(), "dumps");
string pattern = Path.Combine(directory, "dump_%p.dmp");
string actual = CrashDumpProcessLifetimeHandler.GetDumpDirectory(pattern);
Assert.AreEqual(directory, actual);
}
[TestMethod]
[DataRow("{pname}_{pid}_crash.dmp", "%e_%p_crash.dmp")]
[DataRow("{asm}_{pid}.dmp", null)]
[DataRow("literal.dmp", "literal.dmp")]
public async Task UpdateAsync_UserFilenameTemplate_SetsCorrectDumpFileNamePattern(string userTemplate, string? expectedSuffix)
{
var commandLineOptions = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
{ CrashDumpCommandLineOptions.CrashDumpFileNameOptionName, [userTemplate] },
});
string resultsDirectory = Path.Combine(Path.GetTempPath(), "crashdump-tests-" + Guid.NewGuid().ToString("N"));
var configuration = new Mock<IConfiguration>();
configuration.Setup(x => x[PlatformConfigurationConstants.PlatformResultDirectory]).Returns(resultsDirectory);
var crashDumpConfiguration = new CrashDumpConfiguration();
var loggerFactory = new Mock<ILoggerFactory>();
loggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(Mock.Of<ILogger>());
var clock = new Mock<IClock>();
clock.Setup(x => x.UtcNow).Returns(new DateTimeOffset(2026, 6, 11, 7, 0, 0, TimeSpan.Zero));
var environmentVariables = new Mock<IEnvironmentVariables>();
var provider = new CrashDumpEnvironmentVariableProvider(
configuration.Object,
commandLineOptions,
crashDumpConfiguration,
loggerFactory.Object,
clock.Object);
await provider.UpdateAsync(environmentVariables.Object);
Assert.IsNotNull(crashDumpConfiguration.DumpFileNamePattern);
if (expectedSuffix is not null)
{
Assert.IsTrue(crashDumpConfiguration.DumpFileNamePattern.EndsWith(expectedSuffix, StringComparison.Ordinal), $"Expected pattern ending '{expectedSuffix}', got '{crashDumpConfiguration.DumpFileNamePattern}'.");
}
else
{
Assert.DoesNotContain("{", crashDumpConfiguration.DumpFileNamePattern, "Unresolved placeholder left in pattern.");
Assert.IsTrue(crashDumpConfiguration.DumpFileNamePattern.EndsWith("_%p.dmp", StringComparison.Ordinal), $"Expected pattern ending '_%p.dmp', got '{crashDumpConfiguration.DumpFileNamePattern}'.");
}
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_OnlyPublishesDumpsThatAppearedDuringTheRun()
{
// Create an isolated dump directory so we can pre-populate it with stale files that simulate
// dumps left over from a previous run (the snapshot must filter them out) and then write a
// fresh dump that should be published as an artifact.
string dumpDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "crashdump-tests-" + Guid.NewGuid().ToString("N"))).FullName;
try
{
string stale1 = Path.Combine(dumpDirectory, "CrashDump_999_crash.dmp");
string stale2 = Path.Combine(dumpDirectory, "CrashDump_888_crash.dmp");
File.WriteAllText(stale1, "stale");
File.WriteAllText(stale2, "stale");
string dumpPattern = Path.Combine(dumpDirectory, "CrashDump_%p_crash.dmp");
var configuration = new CrashDumpConfiguration { DumpFileNamePattern = dumpPattern };
var commandLineOptions = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
});
var messageBus = new RecordingMessageBus();
var outputDevice = new NullOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(commandLineOptions, messageBus, outputDevice, configuration);
// Snapshot the directory; both stale dumps must be considered pre-existing.
await handler.OnTestHostProcessStartedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
// Simulate the runtime writing two new dumps during the run: one for the testhost and one
// for a child process that crashed too. The expected testhost dump is also created on disk
// (so the "missing expected dump" warning is not triggered).
string fresh1 = Path.Combine(dumpDirectory, "CrashDump_123_crash.dmp");
string fresh2 = Path.Combine(dumpDirectory, "CrashDump_456_crash.dmp");
File.WriteAllText(fresh1, "fresh");
File.WriteAllText(fresh2, "fresh");
await handler.OnTestHostProcessExitedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
string[] publishedDumps = messageBus.Published
.OfType<FileArtifact>()
.Select(static a => a.FileInfo.FullName)
.OrderBy(static p => p, StringComparer.Ordinal)
.ToArray();
string[] expected = new[] { fresh1, fresh2 }.OrderBy(static p => p, StringComparer.Ordinal).ToArray();
Assert.AreSequenceEqual(expected, publishedDumps);
}
finally
{
try
{
Directory.Delete(dumpDirectory, recursive: true);
}
catch
{
// Best effort cleanup.
}
}
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_PatternWithMultiplePlaceholders_DoesNotEmitFalseMissingDumpWarning()
{
// When the configured dump pattern relies on placeholders other than `%p` (here `%e`),
// the literal-`%p`-substituted path never exists on disk. The handler must therefore
// recognize the testhost dump from the regex match (PID-baked into the testhost-specific
// regex) and avoid emitting CannotFindExpectedCrashDumpFile, which would otherwise
// contradict the success banner above it.
string dumpDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "crashdump-tests-" + Guid.NewGuid().ToString("N"))).FullName;
try
{
string dumpPattern = Path.Combine(dumpDirectory, "Dump_%e_%p.dmp");
var configuration = new CrashDumpConfiguration { DumpFileNamePattern = dumpPattern };
var commandLineOptions = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
});
var messageBus = new RecordingMessageBus();
var outputDevice = new CapturingOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(commandLineOptions, messageBus, outputDevice, configuration);
await handler.OnTestHostProcessStartedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
// Runtime expands %e to "testhost" and %p to the actual PID. The resulting filename is
// matched by the testhost-specific regex even though the literal-%p substitution would
// produce `Dump_%e_123.dmp` (which does not exist on disk).
string testhostDump = Path.Combine(dumpDirectory, "Dump_testhost_123.dmp");
File.WriteAllText(testhostDump, "fresh");
await handler.OnTestHostProcessExitedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
string[] publishedDumps = messageBus.Published
.OfType<FileArtifact>()
.Select(static a => a.FileInfo.FullName)
.ToArray();
Assert.AreSequenceEqual([testhostDump], publishedDumps);
// The "expected dump not found" warning must NOT be emitted: the testhost dump was
// recognized via the regex even though `expectedDumpFile` (literal `%p` substitution)
// would be `Dump_%e_123.dmp`, which does not exist on disk.
string captured = string.Join(" | ", outputDevice.Displayed);
Assert.DoesNotContain("Dump_%e_123.dmp", captured, "CannotFindExpectedCrashDumpFile must not be displayed when the testhost dump was recognized via the regex.");
}
finally
{
try
{
Directory.Delete(dumpDirectory, recursive: true);
}
catch
{
// Best effort cleanup.
}
}
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_PatternWithRepeatedPidPlaceholder_RecognizesTesthostDump()
{
// A configured pattern can include `%p` more than once. Verify that the PID-substitution
// applies to every occurrence (string.Replace substitutes all matches) so the
// testhost-specific regex is anchored to the actual PID on both sides.
string dumpDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "crashdump-tests-" + Guid.NewGuid().ToString("N"))).FullName;
try
{
string dumpPattern = Path.Combine(dumpDirectory, "dump_%p_backup_%p.dmp");
var configuration = new CrashDumpConfiguration { DumpFileNamePattern = dumpPattern };
var commandLineOptions = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
});
var messageBus = new RecordingMessageBus();
var outputDevice = new CapturingOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(commandLineOptions, messageBus, outputDevice, configuration);
await handler.OnTestHostProcessStartedAsync(new TestHostProcessInformation(pid: 555, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
string testhostDump = Path.Combine(dumpDirectory, "dump_555_backup_555.dmp");
File.WriteAllText(testhostDump, "fresh");
await handler.OnTestHostProcessExitedAsync(new TestHostProcessInformation(pid: 555, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
string[] publishedDumps = messageBus.Published
.OfType<FileArtifact>()
.Select(static a => a.FileInfo.FullName)
.ToArray();
Assert.AreSequenceEqual([testhostDump], publishedDumps);
string captured = string.Join(" | ", outputDevice.Displayed);
Assert.DoesNotContain("dump_555_backup_555.dmp", captured, "CannotFindExpectedCrashDumpFile must not be displayed when the testhost dump was recognized via the regex.");
}
finally
{
try
{
Directory.Delete(dumpDirectory, recursive: true);
}
catch
{
// Best effort cleanup.
}
}
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_TesthostAndChildBothCrashWithMultiPlaceholderPattern_PublishesBothAndSuppressesWarning()
{
// Regression coverage for the M1 vector: when both the testhost AND a child process write
// dumps using a pattern with non-`%p` placeholders, both dumps must be published, and the
// "expected dump not found" warning must NOT fire (because the testhost dump is identified
// via the testhost-specific regex, not via File.Exists on the literal-`%p`-substituted path).
string dumpDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "crashdump-tests-" + Guid.NewGuid().ToString("N"))).FullName;
try
{
string dumpPattern = Path.Combine(dumpDirectory, "Dump_%e_%p.dmp");
var configuration = new CrashDumpConfiguration { DumpFileNamePattern = dumpPattern };
var commandLineOptions = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
});
var messageBus = new RecordingMessageBus();
var outputDevice = new CapturingOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(commandLineOptions, messageBus, outputDevice, configuration);
await handler.OnTestHostProcessStartedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
string testhostDump = Path.Combine(dumpDirectory, "Dump_testhost_123.dmp");
string childDump = Path.Combine(dumpDirectory, "Dump_child_456.dmp");
File.WriteAllText(testhostDump, "fresh");
File.WriteAllText(childDump, "fresh");
await handler.OnTestHostProcessExitedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
string[] publishedDumps = messageBus.Published
.OfType<FileArtifact>()
.Select(static a => a.FileInfo.FullName)
.OrderBy(static p => p, StringComparer.Ordinal)
.ToArray();
string[] expected = new[] { testhostDump, childDump }.OrderBy(static p => p, StringComparer.Ordinal).ToArray();
Assert.AreSequenceEqual(expected, publishedDumps);
string captured = string.Join(" | ", outputDevice.Displayed);
Assert.DoesNotContain("Dump_%e_123.dmp", captured, "CannotFindExpectedCrashDumpFile must not be displayed when the testhost dump was recognized via the regex.");
}
finally
{
try
{
Directory.Delete(dumpDirectory, recursive: true);
}
catch
{
// Best effort cleanup.
}
}
}
[TestMethod]
public async Task OnTestHostProcessExitedAsync_CrashReport_PatternWithRuntimePlaceholders_PublishesMatchedReport()
{
// When the configured dump pattern relies on runtime placeholders other than `%p`
// (here `%e`, which the `{pname}` token maps to), the literal-`%p`-substituted crash
// report path never exists on disk. The handler must therefore identify the crash
// report via the testhost-dump regex applied to the report's "<dump file name>"
// prefix, and publish the actual file found on disk (not the unresolved path).
string dumpDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "crashdump-tests-" + Guid.NewGuid().ToString("N"))).FullName;
try
{
string dumpPattern = Path.Combine(dumpDirectory, "Dump_%e_%p.dmp");
var configuration = new CrashDumpConfiguration { DumpFileNamePattern = dumpPattern };
var commandLineOptions = new TestCommandLineOptions(new Dictionary<string, string[]>
{
{ CrashDumpCommandLineOptions.CrashDumpOptionName, [] },
{ CrashDumpCommandLineOptions.CrashReportOptionName, [] },
});
var messageBus = new RecordingMessageBus();
var outputDevice = new CapturingOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(commandLineOptions, messageBus, outputDevice, configuration);
await handler.OnTestHostProcessStartedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
// Simulate the runtime writing the testhost dump and its companion crash report with
// `%e` expanded to "testhost". A naive File.Exists check on the literal-%p-substituted
// crash report path (`Dump_%e_123.dmp.crashreport.json`) would miss the actual file.
string testhostDump = Path.Combine(dumpDirectory, "Dump_testhost_123.dmp");
string testhostCrashReport = testhostDump + ".crashreport.json";
string childDump = Path.Combine(dumpDirectory, "Dump_child_456.dmp");
string childCrashReport = childDump + ".crashreport.json";
File.WriteAllText(testhostDump, "fresh");
File.WriteAllText(testhostCrashReport, "{}");
File.WriteAllText(childDump, "fresh");
File.WriteAllText(childCrashReport, "{}");
await handler.OnTestHostProcessExitedAsync(new TestHostProcessInformation(pid: 123, exitCode: 1, hasExitedGracefully: false), CancellationToken.None);
string[] publishedFiles = messageBus.Published
.OfType<FileArtifact>()
.Select(static a => a.FileInfo.FullName)
.OrderBy(static p => p, StringComparer.Ordinal)
.ToArray();
string[] expected = new[] { testhostDump, testhostCrashReport, childDump, childCrashReport }.OrderBy(static p => p, StringComparer.Ordinal).ToArray();
Assert.AreSequenceEqual(expected, publishedFiles);
// The "expected crash report not found" warning must NOT be emitted: the report was
// matched by the regex even though `expectedCrashReportFile` (literal `%p` substitution)
// would be `Dump_%e_123.dmp.crashreport.json`, which does not exist on disk.
string captured = string.Join(" | ", outputDevice.Displayed);
Assert.DoesNotContain("Dump_%e_123.dmp.crashreport.json", captured, "CannotFindExpectedCrashReportFile must not be displayed when the report was recognized via the regex.");
}
finally
{
try
{
Directory.Delete(dumpDirectory, recursive: true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
// Best effort cleanup.
}
}
}
[TestMethod]
public async Task IsValid_If_CrashDumpFileName_Has_ArbitraryExtension()
{
var provider = new CrashDumpCommandLineProvider();
CommandLineOption option = provider.GetCommandLineOptions()
.Single(x => x.Name == CrashDumpCommandLineOptions.CrashDumpFileNameOptionName);
ValidationResult result = await provider
.ValidateOptionArgumentsAsync(option, ["dump.custom"])
.ConfigureAwait(false);
Assert.IsTrue(result.IsValid, result.ErrorMessage);
Assert.IsNull(result.ErrorMessage);
}
[TestMethod]
public async Task CrashDump_MainOptionOnly_IsValid()
{
var provider = new CrashDumpCommandLineProvider();
var options = new Dictionary<string, string[]>
{
[CrashDumpCommandLineOptions.CrashDumpOptionName] = [],
};
ValidationResult result = await provider
.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options))
.ConfigureAwait(false);
Assert.IsTrue(result.IsValid, result.ErrorMessage);
Assert.IsNull(result.ErrorMessage);
}
[TestMethod]
public async Task BeforeTestHostProcessStartAsync_WhenIfSupportedNotSet_EmitsNoMessage()
{
var commandLineOptions = new TestCommandLineOptions([]);
var outputDevice = new CapturingOutputDevice();
var handler = new CrashDumpProcessLifetimeHandler(
commandLineOptions,
new RecordingMessageBus(),
outputDevice,
new CrashDumpConfiguration());
await handler.BeforeTestHostProcessStartAsync(CancellationToken.None).ConfigureAwait(false);
Assert.IsEmpty(outputDevice.Displayed);
}
[TestMethod]