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
100 lines
2.2 KiB
Go
100 lines
2.2 KiB
Go
package languages
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func TestMakefileExtractor_Basics(t *testing.T) {
|
|
src := []byte(`include config.mk
|
|
|
|
CC := gcc
|
|
CFLAGS = -O2
|
|
|
|
all: build test
|
|
|
|
build:
|
|
$(CC) $(CFLAGS) -o app main.c
|
|
|
|
test: build
|
|
./app --test
|
|
|
|
define greet
|
|
echo hello
|
|
endef
|
|
`)
|
|
e := NewMakefileExtractor()
|
|
require.Equal(t, "makefile", e.Language())
|
|
|
|
res, err := e.Extract("Makefile", src)
|
|
require.NoError(t, err)
|
|
|
|
var gotAll, gotBuild, gotCC, gotGreet bool
|
|
for _, n := range res.Nodes {
|
|
switch n.Name {
|
|
case "all":
|
|
gotAll = true
|
|
case "build":
|
|
gotBuild = true
|
|
case "CC":
|
|
gotCC = true
|
|
case "greet":
|
|
gotGreet = true
|
|
}
|
|
}
|
|
var gotImport bool
|
|
for _, ed := range res.Edges {
|
|
if ed.Kind == graph.EdgeImports && ed.To == "unresolved::import::config.mk" {
|
|
gotImport = true
|
|
}
|
|
}
|
|
assert.True(t, gotAll)
|
|
assert.True(t, gotBuild)
|
|
assert.True(t, gotCC)
|
|
assert.True(t, gotGreet)
|
|
assert.True(t, gotImport)
|
|
}
|
|
|
|
func TestMakefileExtractor_EmptyInput(t *testing.T) {
|
|
res, err := NewMakefileExtractor().Extract("Makefile", []byte(""))
|
|
require.NoError(t, err)
|
|
require.Len(t, res.Nodes, 1)
|
|
assert.Equal(t, graph.KindFile, res.Nodes[0].Kind)
|
|
}
|
|
|
|
func TestMakefileExtractor_RecipeCallEdges(t *testing.T) {
|
|
src := []byte("build:\n\tgo build ./...\n\n" +
|
|
"all: build test\n\t$(MAKE) lint\n\t@make build\n\n" +
|
|
"test:\n\tgo test ./...\n\n" +
|
|
"lint:\n\tgolangci-lint run\n")
|
|
e := NewMakefileExtractor()
|
|
result, err := e.Extract("Makefile", src)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
calls := map[string]bool{}
|
|
for _, edge := range result.Edges {
|
|
if edge.Kind == graph.EdgeCalls && edge.From == "Makefile::all" {
|
|
calls[edge.To] = true
|
|
}
|
|
}
|
|
for _, want := range []string{"Makefile::lint", "Makefile::build"} {
|
|
if !calls[want] {
|
|
t.Errorf("expected call edge all → %s, got %v", want, calls)
|
|
}
|
|
}
|
|
|
|
// `golangci-lint run` shouldn't produce a call edge — it's an
|
|
// external command, not a make target.
|
|
for _, edge := range result.Edges {
|
|
if edge.Kind == graph.EdgeCalls && edge.From == "Makefile::lint" {
|
|
t.Errorf("unexpected call from lint: %v", edge)
|
|
}
|
|
}
|
|
}
|