@@ -262,8 +262,8 @@ async function processSymbol(
262
262
seen : Set < string > ,
263
263
symbol : DocumentSymbol
264
264
) {
265
- // Skip TestMain(*testing.M)
266
- if ( symbol . name === 'TestMain' || / \* t e s t i n g .M \) / . test ( symbol . detail ) ) {
265
+ // Skip TestMain(*testing.M) - allow TestMain(*testing.T)
266
+ if ( symbol . name === 'TestMain' && / \* t e s t i n g .M \) / . test ( symbol . detail ) ) {
267
267
return ;
268
268
}
269
269
@@ -325,7 +325,7 @@ async function walk(
325
325
let dirs = [ uri ] ;
326
326
327
327
// While there are directories to be scanned
328
- while ( dirs . length ) {
328
+ while ( dirs . length > 0 ) {
329
329
const d = dirs ;
330
330
dirs = [ ] ;
331
331
@@ -561,6 +561,7 @@ function resolveTestName(ctrl: TestController, tests: Record<string, TestItem>,
561
561
return test ;
562
562
}
563
563
564
+ // Process benchmark test events (see test_events.md)
564
565
function consumeGoBenchmarkEvent < T > (
565
566
ctrl : TestController ,
566
567
run : TestRun < T > ,
@@ -569,18 +570,19 @@ function consumeGoBenchmarkEvent<T>(
569
570
e : GoTestOutput
570
571
) {
571
572
if ( e . Test ) {
573
+ // Find (or create) the (sub)benchmark
572
574
const test = resolveTestName ( ctrl , benchmarks , e . Test ) ;
573
575
if ( ! test ) {
574
576
return ;
575
577
}
576
578
577
579
switch ( e . Action ) {
578
- case 'fail' :
580
+ case 'fail' : // Failed
579
581
run . setState ( test , TestResultState . Failed ) ;
580
582
complete . add ( test ) ;
581
583
break ;
582
584
583
- case 'skip' :
585
+ case 'skip' : // Skipped
584
586
run . setState ( test , TestResultState . Skipped ) ;
585
587
complete . add ( test ) ;
586
588
break ;
@@ -589,22 +591,29 @@ function consumeGoBenchmarkEvent<T>(
589
591
return ;
590
592
}
591
593
594
+ // Ignore anything that's not an output event
592
595
if ( ! e . Output ) {
593
596
return ;
594
597
}
595
598
596
- // Started: "BenchmarkFooBar"
597
- // Completed: "BenchmarkFooBar-4 123456 123.4 ns/op 123 B/op 12 allocs/op"
599
+ // On start: "BenchmarkFooBar"
600
+ // On complete: "BenchmarkFooBar-4 123456 123.4 ns/op 123 B/op 12 allocs/op"
601
+
602
+ // Extract the benchmark name and status
598
603
const m = e . Output . match ( / ^ (?< name > B e n c h m a r k [ / \w ] + ) (?: - (?< procs > \d + ) \s + (?< result > .* ) ) ? (?: $ | \n ) / ) ;
599
604
if ( ! m ) {
605
+ // If the output doesn't start with `BenchmarkFooBar`, ignore it
600
606
return ;
601
607
}
602
608
609
+ // Find (or create) the (sub)benchmark
603
610
const test = resolveTestName ( ctrl , benchmarks , m . groups . name ) ;
604
611
if ( ! test ) {
605
612
return ;
606
613
}
607
614
615
+ // If output includes benchmark results, the benchmark passed. If output
616
+ // only includes the benchmark name, the benchmark is running.
608
617
if ( m . groups . result ) {
609
618
run . appendMessage ( test , {
610
619
message : m . groups . result ,
@@ -618,6 +627,7 @@ function consumeGoBenchmarkEvent<T>(
618
627
}
619
628
}
620
629
630
+ // Pass any incomplete benchmarks (see test_events.md)
621
631
function passBenchmarks < T > ( run : TestRun < T > , items : Record < string , TestItem > , complete : Set < TestItem > ) {
622
632
function pass ( item : TestItem ) {
623
633
if ( ! complete . has ( item ) ) {
@@ -746,7 +756,7 @@ async function runTest<T>(ctrl: TestController, request: TestRunRequest<T>) {
746
756
for ( const item of items ) {
747
757
run . setState ( item , TestResultState . Queued ) ;
748
758
749
- // Remove any subtests
759
+ // Clear any dynamic subtests generated by a previous run
750
760
item . canResolveChildren = false ;
751
761
Array . from ( item . children . values ( ) ) . forEach ( ( x ) => x . dispose ( ) ) ;
752
762
@@ -762,7 +772,8 @@ async function runTest<T>(ctrl: TestController, request: TestRunRequest<T>) {
762
772
const testFns = Object . keys ( tests ) ;
763
773
const benchmarkFns = Object . keys ( benchmarks ) ;
764
774
765
- if ( testFns . length ) {
775
+ if ( testFns . length > 0 ) {
776
+ // Run tests
766
777
await goTest ( {
767
778
goConfig,
768
779
flags,
@@ -774,7 +785,8 @@ async function runTest<T>(ctrl: TestController, request: TestRunRequest<T>) {
774
785
} ) ;
775
786
}
776
787
777
- if ( benchmarkFns . length ) {
788
+ if ( benchmarkFns . length > 0 ) {
789
+ // Run benchmarks
778
790
const complete = new Set < TestItem > ( ) ;
779
791
await goTest ( {
780
792
goConfig,
@@ -787,6 +799,7 @@ async function runTest<T>(ctrl: TestController, request: TestRunRequest<T>) {
787
799
goTestOutputConsumer : ( e ) => consumeGoBenchmarkEvent ( ctrl , run , benchmarks , complete , e )
788
800
} ) ;
789
801
802
+ // Explicitly pass any incomplete benchmarks (see test_events.md)
790
803
passBenchmarks ( run , benchmarks , complete ) ;
791
804
}
792
805
0 commit comments