@@ -375,8 +375,10 @@ func TestOverlayAugmentation(t *testing.T) {
375
375
desc : `remove unsafe and embed if not needed` ,
376
376
src : `import "unsafe"
377
377
import "embed"
378
+
378
379
//gopherjs:purge
379
380
var eFile embed.FS
381
+
380
382
//gopherjs:purge
381
383
func SwapPointer(addr *unsafe.Pointer, new unsafe.Pointer) (old unsafe.Pointer)` ,
382
384
want : `` ,
@@ -388,8 +390,10 @@ func TestOverlayAugmentation(t *testing.T) {
388
390
desc : `keep unsafe and embed for directives` ,
389
391
src : `import "unsafe"
390
392
import "embed"
393
+
391
394
//go:embed hello.txt
392
395
var eFile embed.FS
396
+
393
397
//go:linkname runtimeNano runtime.nanotime
394
398
func runtimeNano() int64` ,
395
399
noCodeChange : true ,
@@ -565,14 +569,18 @@ func TestOriginalAugmentation(t *testing.T) {
565
569
`Equal` : {},
566
570
},
567
571
src : `import "cmp"
572
+
573
+ // keeps the isOnlyImports from skipping what is being tested.
574
+ func foo() {}
568
575
569
576
type Pointer[T any] struct {}
570
577
571
578
func Sort[S ~[]E, E cmp.Ordered](x S) {}
572
579
573
580
// overlay had stub "func Equal() {}"
574
581
func Equal[S ~[]E, E any](s1, s2 S) bool {}` ,
575
- want : `` ,
582
+ want : `// keeps the isOnlyImports from skipping what is being tested.
583
+ func foo() {}` ,
576
584
}, {
577
585
desc : `purge generics` ,
578
586
info : map [string ]overrideInfo {
@@ -582,6 +590,9 @@ func TestOriginalAugmentation(t *testing.T) {
582
590
},
583
591
src : `import "cmp"
584
592
593
+ // keeps the isOnlyImports from skipping what is being tested.
594
+ func foo() {}
595
+
585
596
type Pointer[T any] struct {}
586
597
func (x *Pointer[T]) Load() *T {}
587
598
func (x *Pointer[T]) Store(val *T) {}
@@ -590,12 +601,17 @@ func TestOriginalAugmentation(t *testing.T) {
590
601
591
602
// overlay had stub "func Equal() {}"
592
603
func Equal[S ~[]E, E any](s1, s2 S) bool {}` ,
593
- want : `` ,
604
+ want : `// keeps the isOnlyImports from skipping what is being tested.
605
+ func foo() {}` ,
594
606
}, {
595
607
desc : `prune an unused import` ,
596
608
info : map [string ]overrideInfo {},
597
- src : `import foo "some/other/bar"` ,
598
- want : `` ,
609
+ src : `import foo "some/other/bar"
610
+
611
+ // keeps the isOnlyImports from skipping what is being tested.
612
+ func foo() {}` ,
613
+ want : `// keeps the isOnlyImports from skipping what is being tested.
614
+ func foo() {}` ,
599
615
}, {
600
616
desc : `override signature of function` ,
601
617
info : map [string ]overrideInfo {
@@ -638,6 +654,25 @@ func TestOriginalAugmentation(t *testing.T) {
638
654
}
639
655
return b, false
640
656
}` ,
657
+ }, {
658
+ desc : `empty file removes all imports` ,
659
+ info : map [string ]overrideInfo {
660
+ `foo` : {},
661
+ },
662
+ src : `import . "math/rand"
663
+ func foo() int {
664
+ return Int()
665
+ }` ,
666
+ want : `` ,
667
+ }, {
668
+ desc : `empty file with directive` ,
669
+ info : map [string ]overrideInfo {
670
+ `foo` : {},
671
+ },
672
+ src : `//go:linkname foo bar
673
+ import _ "unsafe"` ,
674
+ want : `//go:linkname foo bar
675
+ import _ "unsafe"` ,
641
676
},
642
677
}
643
678
0 commit comments