package main import ( "os" "path/filepath" "testing" ) func TestCheckBuildmodePlugin_FlagsMakefileAndScript(t *testing.T) { root := t.TempDir() if err := os.WriteFile(filepath.Join(root, "Makefile"), []byte("build-so:\n\tgo build -buildmode=plugin -o plugin.so .\n"), 0o644); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(root, "build.sh"), []byte("#!/bin/sh\ngo build -buildmode=plugin -o x.so .\n"), 0o644); err != nil { t.Fatal(err) } // A non-build file mentioning the string must NOT be flagged. if err := os.WriteFile(filepath.Join(root, "README.md"), []byte("we used to run go build -buildmode=plugin here\n"), 0o644); err != nil { t.Fatal(err) } v := checkBuildmodePlugin([]pluginScanTarget{{root: root, display: "demo"}}) if len(v) != 2 { t.Fatalf("got %d violations, want 2: %+v", len(v), v) } } func TestCheckBuildmodePlugin_CleanRepo(t *testing.T) { root := t.TempDir() if err := os.WriteFile(filepath.Join(root, "Makefile"), []byte("build-wasm:\n\tninja plugin build\n"), 0o644); err != nil { t.Fatal(err) } if v := checkBuildmodePlugin([]pluginScanTarget{{root: root, display: "demo"}}); len(v) != 0 { t.Fatalf("clean repo flagged: %+v", v) } }