a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
48 lines
894 B
Go
48 lines
894 B
Go
package languages
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func TestGoCgo_StampsUsesCgoOnFileNode(t *testing.T) {
|
|
src := `package foo
|
|
|
|
/*
|
|
#include <stdio.h>
|
|
*/
|
|
import "C"
|
|
|
|
func Hello() {
|
|
C.printf(C.CString("hello\n"))
|
|
}
|
|
`
|
|
fix := runGoExtract(t, src)
|
|
|
|
files := fix.nodesByKind[graph.KindFile]
|
|
if len(files) != 1 {
|
|
t.Fatalf("expected 1 file node, got %d", len(files))
|
|
}
|
|
if v, _ := files[0].Meta["uses_cgo"].(bool); !v {
|
|
t.Errorf("expected meta.uses_cgo=true on file node with import \"C\"")
|
|
}
|
|
}
|
|
|
|
func TestGoCgo_NoFlagOnRegularImport(t *testing.T) {
|
|
src := `package foo
|
|
|
|
import "fmt"
|
|
|
|
func Hello() { fmt.Println("hi") }
|
|
`
|
|
fix := runGoExtract(t, src)
|
|
files := fix.nodesByKind[graph.KindFile]
|
|
if len(files) != 1 {
|
|
t.Fatalf("expected 1 file node")
|
|
}
|
|
if v, _ := files[0].Meta["uses_cgo"].(bool); v {
|
|
t.Errorf("regular import must not set uses_cgo")
|
|
}
|
|
}
|