Files
wangdefa f782b612ec build: 内置 norma 模块,构建不再依赖上游仓库
把 github.com/Autumn-27/norma v0.4.3(commit 320ae32)的源码复制到
third_party/norma,并用 go.mod 的 replace 指向本地副本。上游删除仓库或
改写 tag 都不再影响本仓库构建。

- 已验证 GOPROXY=off 下可完整编译并打出发行包
- go.sum 中该模块的两条校验记录随之删除(本地 replace 不需要哈希)
- 升级方法与授权注意事项见 third_party/README.md
2026-10-20 21:10:41 -07:00

35 lines
1014 B
Go

package tool
import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
func TestRipgrepPathDisabled(t *testing.T) {
t.Setenv("NORMA_DISABLE_RIPGREP", "1")
if RipgrepPath() != "" {
t.Fatal("NORMA_DISABLE_RIPGREP should force the Go implementation")
}
}
func TestGrepViaRipgrepIfAvailable(t *testing.T) {
if _, err := exec.LookPath("rg"); err != nil {
t.Skip("rg not installed — skipping the ripgrep-backed path")
}
// Use the existing rg; never auto-install during tests.
t.Setenv("NORMA_RIPGREP_NO_INSTALL", "1")
os.Unsetenv("NORMA_DISABLE_RIPGREP")
dir := t.TempDir()
os.WriteFile(filepath.Join(dir, "x.go"), []byte("package main\nfunc Zed(){}\n"), 0o644)
os.WriteFile(filepath.Join(dir, "y.txt"), []byte("nothing here\n"), 0o644)
res := run(t, NewGrep(), dir, map[string]any{"pattern": "Zed", "output_mode": "files_with_matches"})
if !strings.Contains(res.Flatten(), "x.go") || strings.Contains(res.Flatten(), "y.txt") {
t.Fatalf("ripgrep-backed grep: %q", res.Flatten())
}
}