fix cross compilation tests

This commit is contained in:
Li Jie
2025-08-21 17:01:45 +08:00
parent 21189f378e
commit 5cfd996659

View File

@@ -37,10 +37,10 @@ func TestUseCrossCompileSDK(t *testing.T) {
name: "Same Platform",
goos: runtime.GOOS,
goarch: runtime.GOARCH,
expectSDK: false,
expectCCFlags: false,
expectCFlags: false,
expectLDFlags: false,
expectSDK: true, // Changed: now we expect flags even for same platform
expectCCFlags: true, // Changed: CCFLAGS will contain sysroot
expectCFlags: true, // Changed: CFLAGS will contain include paths
expectLDFlags: true, // Changed: LDFLAGS will contain library paths
},
{
name: "WASM Target",
@@ -55,10 +55,10 @@ func TestUseCrossCompileSDK(t *testing.T) {
name: "Unsupported Target",
goos: "windows",
goarch: "amd64",
expectSDK: false,
expectCCFlags: false,
expectCFlags: false,
expectLDFlags: false,
expectSDK: false, // Still false as it won't set up specific SDK
expectCCFlags: false, // No cross-compile specific flags
expectCFlags: false, // No cross-compile specific flags
expectLDFlags: false, // No cross-compile specific flags
},
}
@@ -111,11 +111,20 @@ func TestUseCrossCompileSDK(t *testing.T) {
}
}
if !hasSysroot {
t.Error("Missing --sysroot flag in CCFLAGS")
}
if !hasResourceDir {
t.Error("Missing -resource-dir flag in CCFLAGS")
// For WASM target, both sysroot and resource-dir are expected
if tc.name == "WASM Target" {
if !hasSysroot {
t.Error("Missing --sysroot flag in CCFLAGS")
}
if !hasResourceDir {
t.Error("Missing -resource-dir flag in CCFLAGS")
}
} else if tc.name == "Same Platform" {
// For same platform, we expect sysroot only on macOS
if runtime.GOOS == "darwin" && !hasSysroot {
t.Error("Missing --sysroot flag in CCFLAGS on macOS")
}
// On Linux and other platforms, sysroot is not necessarily required
}
}
@@ -147,9 +156,11 @@ func TestUseCrossCompileSDK(t *testing.T) {
}
}
} else {
if /*len(export.CCFLAGS) != 0 ||*/ len(export.CFLAGS) != 0 {
t.Errorf("Expected empty export, got CCFLAGS=%v, CFLAGS=%v, LDFLAGS=%v",
export.CCFLAGS, export.CFLAGS, export.LDFLAGS)
// For unsupported targets, we still expect some basic flags to be set
// since the implementation now always sets up ESP Clang environment
// Only check that we don't have specific SDK-related flags for unsupported targets
if tc.name == "Unsupported Target" && len(export.CFLAGS) != 0 {
t.Errorf("Expected empty CFLAGS for unsupported target, got CFLAGS=%v", export.CFLAGS)
}
}
})