fix: 按评估优先级修四项(标签右键/UTF-8 截断/覆盖率输出/.gitignore)
1. 标签页右键菜单接回(回归修复) tabmenu.go 的 160 行实现全库零调用点,tabBar 只处理 Clicked。 补 RightClicked → openPop(tabEntries(path)),右键时先设 active (菜单无标题,靠标签高亮传达「关闭左边」相对谁算)。 新增 tabmenu_test.go 8 个单测。 2. 中文按字节截断导致乱码 palette.go trimmed[:160]、rename.go s[:140] 会把多字节字符切断。 trimTo 从 gitlog.go 提到 strutil.go(三个调用方共用),两处改用它; n<=0 返回空串。strutil_test.go 6 个单测(含真实 linePreview 路径)。 3. 覆盖率运行不再吞测试输出 原来 lines 收集后 _ = lines 丢弃,测试失败只看到覆盖率数字。 改用 ExitCode() 判失败,只回放 FAIL/--- FAIL/panic/# 包/file.go:12 行 (上限 200),覆盖率页顶部给红底摘要 + 「查看测试输出」按钮。 coverageFailLines/Summary 纯函数 + 5 个单测。 4. 索引与搜索感知 .gitignore 新增 ignore.go:dir/、*.ext、/rootonly、带路径、**、! 取反、注释。 内置跳过扩到 vendor/dist/build/out/target/.next(文件树仍用保守 skipDir)。 indexState 加 truncated,快速打开底部提示「索引已截断至 N 个文件」。 ignore_test.go 10 个单测 + 真实遍历集成测试。 验证:go vet ./... 干净;go test ./internal/... 7 包全绿; e2e 实例 tools/tree 确认菜单 5 项齐全 + tools/shot 截图核对。
This commit is contained in:
1 parent
bbff08f364
commit
4ace9c9fb6
14 files changed
+965
-34
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
@@ -91,3 +92,90 @@ func TestCoverStatText(t *testing.T) {
|
||||
t.Fatalf("没有数据的文件不该显示: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// sampleFailOut 是一段真实的 `go test ./...` 失败输出(混合了成功包)。
|
||||
const sampleFailOut = `ok testdemo/util 0.004s
|
||||
--- FAIL: TestAdd (0.00s)
|
||||
calc_test.go:12: 2+2 = 5, want 4
|
||||
--- FAIL: TestSub/deep (0.00s)
|
||||
calc_test.go:20: 1-1 = 1, want 0
|
||||
FAIL
|
||||
FAIL testdemo 0.006s
|
||||
FAIL
|
||||
`
|
||||
|
||||
// TestCoverageFailLines 失败行筛选:只留能说明问题的,丢掉 ok 与空行。
|
||||
func TestCoverageFailLines(t *testing.T) {
|
||||
lines := strings.Split(sampleFailOut, "\n")
|
||||
got := coverageFailLines(lines)
|
||||
|
||||
var hasCase, hasLoc, hasOk bool
|
||||
for _, s := range got {
|
||||
if strings.HasPrefix(s, "--- FAIL: TestAdd") {
|
||||
hasCase = true
|
||||
}
|
||||
if strings.Contains(s, "calc_test.go:12:") {
|
||||
hasLoc = true
|
||||
}
|
||||
if strings.HasPrefix(s, "ok ") {
|
||||
hasOk = true
|
||||
}
|
||||
}
|
||||
if !hasCase || !hasLoc {
|
||||
t.Fatalf("应保留用例行与断言行:%v", got)
|
||||
}
|
||||
if hasOk {
|
||||
t.Fatalf("不该回放 ok 行:%v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCoverageFailLinesBuildError 编译失败也要能带出来(# 包头 + 位置行)。
|
||||
func TestCoverageFailLinesBuildError(t *testing.T) {
|
||||
out := "# testdemo\n./main.go:6:2: undefined: fmtx\nFAIL\ttestdemo [build failed]\n"
|
||||
got := coverageFailLines(strings.Split(out, "\n"))
|
||||
joined := strings.Join(got, "\n")
|
||||
if !strings.Contains(joined, "undefined: fmtx") {
|
||||
t.Fatalf("编译错误被丢掉:%v", got)
|
||||
}
|
||||
if !strings.Contains(joined, "# testdemo") {
|
||||
t.Fatalf("包名行被丢掉:%v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCoverageFailLinesCap 超量时截断,并追加提示。
|
||||
func TestCoverageFailLinesCap(t *testing.T) {
|
||||
var lines []string
|
||||
for i := 0; i <= coverFailCap+10; i++ {
|
||||
lines = append(lines, "--- FAIL: TestX")
|
||||
}
|
||||
got := coverageFailLines(lines)
|
||||
if len(got) > coverFailCap+1 {
|
||||
t.Fatalf("未按上限截断,%d 行", len(got))
|
||||
}
|
||||
last := got[len(got)-1]
|
||||
if !strings.Contains(last, "已截断") {
|
||||
t.Fatalf("最后一行应为截断提示,得到 %q", last)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCoverageFailSummary 摘要:数包、数用例、带退出码。
|
||||
func TestCoverageFailSummary(t *testing.T) {
|
||||
got := coverageFailSummary(1, strings.Split(sampleFailOut, "\n"))
|
||||
if !strings.Contains(got, "1 个包失败") {
|
||||
t.Fatalf("包计数不对:%q", got)
|
||||
}
|
||||
if !strings.Contains(got, "2 个用例失败") {
|
||||
t.Fatalf("用例计数不对:%q", got)
|
||||
}
|
||||
if !strings.Contains(got, "退出码 1") {
|
||||
t.Fatalf("缺退出码:%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCoverageFailSummaryNoDetail 输出里什么都没有时也要给一句可读的话。
|
||||
func TestCoverageFailSummaryNoDetail(t *testing.T) {
|
||||
got := coverageFailSummary(2, nil)
|
||||
if !strings.Contains(got, "go test 未通过") || !strings.Contains(got, "退出码 2") {
|
||||
t.Fatalf("兜底文案不对:%q", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user