Skip to content

Commit 41fa6d3

Browse files
committed
test: isolate go1.26 source patch coverage
1 parent ca8e14a commit 41fa6d3

File tree

2 files changed

+57
-43
lines changed

2 files changed

+57
-43
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//go:build go1.26
2+
// +build go1.26
3+
4+
package build
5+
6+
import (
7+
"path/filepath"
8+
"runtime"
9+
"strings"
10+
"testing"
11+
12+
"github.com/goplus/llgo/internal/env"
13+
llruntime "github.com/goplus/llgo/runtime"
14+
)
15+
16+
func TestBuildSourcePatchOverlayForInternalSync(t *testing.T) {
17+
overlay, err := buildSourcePatchOverlayForGOROOT(nil, env.LLGoRuntimeDir(), runtime.GOROOT(), sourcePatchBuildContext{
18+
goos: runtime.GOOS,
19+
goarch: runtime.GOARCH,
20+
goversion: "go1.26.0",
21+
})
22+
if err != nil {
23+
t.Fatal(err)
24+
}
25+
26+
syncDir := filepath.Join(runtime.GOROOT(), "src", "internal", "sync")
27+
patchFile := filepath.Join(syncDir, "z_llgo_patch_hashtriemap.go")
28+
patchSrc, ok := overlay[patchFile]
29+
if !ok {
30+
t.Fatalf("missing source patch file %s", patchFile)
31+
}
32+
if !strings.Contains(string(patchSrc), "type HashTrieMap") {
33+
t.Fatalf("source patch file %s does not contain HashTrieMap replacement", patchFile)
34+
}
35+
36+
stdFile := filepath.Join(syncDir, "hashtriemap.go")
37+
stdSrc, ok := overlay[stdFile]
38+
if !ok {
39+
t.Fatalf("missing stub overlay for %s", stdFile)
40+
}
41+
got := string(stdSrc)
42+
if !strings.Contains(got, "package sync") {
43+
t.Fatalf("stub overlay for %s lost package clause", stdFile)
44+
}
45+
if strings.Contains(got, "type HashTrieMap") {
46+
t.Fatalf("stub overlay for %s still contains original declarations", stdFile)
47+
}
48+
}
49+
50+
func TestInternalSyncUsesSourcePatchInsteadOfAltPkg(t *testing.T) {
51+
if !llruntime.HasSourcePatchPkg("internal/sync") {
52+
t.Fatal("internal/sync should be registered as a source patch package")
53+
}
54+
if llruntime.HasAltPkg("internal/sync") {
55+
t.Fatal("internal/sync should not remain an alt package")
56+
}
57+
}

internal/build/source_patch_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,49 +56,6 @@ func TestIterUsesSourcePatchInsteadOfAltPkg(t *testing.T) {
5656
}
5757
}
5858

59-
func TestBuildSourcePatchOverlayForInternalSync(t *testing.T) {
60-
overlay, err := buildSourcePatchOverlayForGOROOT(nil, env.LLGoRuntimeDir(), runtime.GOROOT(), sourcePatchBuildContext{
61-
goos: runtime.GOOS,
62-
goarch: runtime.GOARCH,
63-
goversion: "go1.26.0",
64-
})
65-
if err != nil {
66-
t.Fatal(err)
67-
}
68-
69-
syncDir := filepath.Join(runtime.GOROOT(), "src", "internal", "sync")
70-
patchFile := filepath.Join(syncDir, "z_llgo_patch_hashtriemap.go")
71-
patchSrc, ok := overlay[patchFile]
72-
if !ok {
73-
t.Fatalf("missing source patch file %s", patchFile)
74-
}
75-
if !strings.Contains(string(patchSrc), "type HashTrieMap") {
76-
t.Fatalf("source patch file %s does not contain HashTrieMap replacement", patchFile)
77-
}
78-
79-
stdFile := filepath.Join(syncDir, "hashtriemap.go")
80-
stdSrc, ok := overlay[stdFile]
81-
if !ok {
82-
t.Fatalf("missing stub overlay for %s", stdFile)
83-
}
84-
got := string(stdSrc)
85-
if !strings.Contains(got, "package sync") {
86-
t.Fatalf("stub overlay for %s lost package clause", stdFile)
87-
}
88-
if strings.Contains(got, "type HashTrieMap") {
89-
t.Fatalf("stub overlay for %s still contains original declarations", stdFile)
90-
}
91-
}
92-
93-
func TestInternalSyncUsesSourcePatchInsteadOfAltPkg(t *testing.T) {
94-
if !llruntime.HasSourcePatchPkg("internal/sync") {
95-
t.Fatal("internal/sync should be registered as a source patch package")
96-
}
97-
if llruntime.HasAltPkg("internal/sync") {
98-
t.Fatal("internal/sync should not remain an alt package")
99-
}
100-
}
101-
10259
func TestSyncAtomicRemainsAltPkg(t *testing.T) {
10360
if llruntime.HasSourcePatchPkg("sync/atomic") {
10461
t.Fatal("sync/atomic should not be registered as a source patch package")

0 commit comments

Comments
 (0)