verify / verify (push) Canceled after 0s
P3 测试开关(internal/app/testflags.go)
测试面板顶部加 -race / -bench 会话级 checkbox(不持久化,-race 会拖慢测试)。
参数经 withTestFlags 统一注入结果树 / 输出面板 / 覆盖率三个 go test 入口。
-bench 配 -run=^$,但调用方已有 -run(运行光标处测试)时不覆盖。
勾 -bench 时「全部测试」改走输出面板,-json 会把 ns/op 埋在 output 行里看不清。
4 条参数组合单测。
P4 三层守门
verify.cmd:gofmt / vet / test 一道跑,纯 ASCII(cmd 按 GBK 读 UTF-8 中文
注释会把中文当命令执行,实测踩过)。用 findstr 判 gofmt 输出非空。
build.cmd verify:自检通过才构建;build.cmd 不带参数仍直接构建。
.gitea/workflows/ci.yml:远端是 Gitea 企业版,用 Gitea Actions 兼容语法。
是否真的运行取决于实例启用 Actions + runner,文档里如实写明这个前提,
不声称已生效。GOOS=linux CGO_ENABLED=0 交叉编译已验证通过。
tools/e2e/main.go:自建临时 Go 模块工作区,编译 -tags e2e 二进制,
以工作区目录作为启动参数(openFromArgs),连 automation 插座跑 4 条场景:
启动渲染 / 工作区与 gopls / 诊断到达 / 输出面板右键菜单。
两个坑已处理:全新会话默认底部面板是关的(ensurePanel 先点状态栏「面板」);
「运行」有页签和右上角真会跑程序的图标两个同名按钮(按 X<700 区分)。
连跑两次均 4/4,退出码反映结果。
docs/本地自检与CI.md 记录三层守门用法、Gitea Actions 启用前提、e2e 限制
(原生右键菜单插座测不了,仍靠 ui.Tester 单测)。
待办文档移除 P3/P4,规划只剩 4 项按需。
验证:build.cmd verify 全绿(286 个测试)、go run ./tools/e2e 两次 4/4、
GOOS=linux 交叉编译通过。
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package app
|
||
|
||
import (
|
||
"reflect"
|
||
"testing"
|
||
)
|
||
|
||
func TestTestFlags(t *testing.T) {
|
||
cases := []struct {
|
||
race, bench, hasRun bool
|
||
want []string
|
||
}{
|
||
{false, false, false, nil},
|
||
{true, false, false, []string{"-race"}},
|
||
{false, true, false, []string{"-bench=.", "-run=^$"}},
|
||
{true, true, false, []string{"-race", "-bench=.", "-run=^$"}},
|
||
// 「运行光标处测试」已给 -run,不能被 -run=^$ 覆盖掉。
|
||
{false, true, true, []string{"-bench=."}},
|
||
{true, true, true, []string{"-race", "-bench=."}},
|
||
}
|
||
for _, c := range cases {
|
||
got := testFlags(c.race, c.bench, c.hasRun)
|
||
if !reflect.DeepEqual(got, c.want) {
|
||
t.Errorf("testFlags(%v,%v,%v) = %v, want %v", c.race, c.bench, c.hasRun, got, c.want)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestHasRunFlag(t *testing.T) {
|
||
for _, args := range [][]string{
|
||
{"test", "-json", "-run", "TestFoo", "./pkg"},
|
||
{"test", "-run=^TestFoo$", "./..."},
|
||
} {
|
||
if !hasRunFlag(args) {
|
||
t.Errorf("该识别出 -run:%v", args)
|
||
}
|
||
}
|
||
if hasRunFlag([]string{"test", "-json", "./..."}) {
|
||
t.Fatal("没有 -run 却识别成了有")
|
||
}
|
||
}
|
||
|
||
func TestWithTestFlags(t *testing.T) {
|
||
// 关闭时原样返回,不制造多余分配。
|
||
a := &App{}
|
||
in := []string{"test", "-json", "./..."}
|
||
got := a.withTestFlags(in)
|
||
if !reflect.DeepEqual(got, in) {
|
||
t.Fatalf("开关全关时不该改参数:%v", got)
|
||
}
|
||
|
||
a.testRace, a.testBench = true, true
|
||
got = a.withTestFlags([]string{"test", "-json", "./..."})
|
||
want := []string{"test", "-race", "-bench=.", "-run=^$", "-json", "./..."}
|
||
if !reflect.DeepEqual(got, want) {
|
||
t.Fatalf("注入位置不对\n got: %v\nwant: %v", got, want)
|
||
}
|
||
// 已有 -run 时不加 -run=^$。
|
||
got = a.withTestFlags([]string{"test", "-json", "-run", "TestFoo", "./pkg"})
|
||
if !reflect.DeepEqual(got[:4], []string{"test", "-race", "-bench=.", "-json"}) {
|
||
t.Fatalf("不该覆盖已有的 -run:%v", got)
|
||
}
|
||
for _, x := range got {
|
||
if x == "-run=^$" {
|
||
t.Fatalf("已有 -run 时不该再加 -run=^$:%v", got)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestTestCommandLabel(t *testing.T) {
|
||
a := &App{}
|
||
if got := a.testCommandLabel("go test ./..."); got != "go test ./..." {
|
||
t.Fatalf("没开关时标签不该变:%q", got)
|
||
}
|
||
a.testRace, a.testBench = true, true
|
||
if got := a.testCommandLabel("go test ./..."); got != "go test ./... [-race -bench=.]" {
|
||
t.Fatalf("标签没显示开关:%q", got)
|
||
}
|
||
}
|