feat: 增强桌面启动失败提示与测试覆盖
This commit is contained in:
@@ -47,9 +47,15 @@ func TestMessageBoxW_WindowsOnly_FailureUsesReturnValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShowError_WindowsBranch(t *testing.T) {
|
||||
withMessageBoxW(t, func(_, _, _, _ uintptr) (uintptr, error) {
|
||||
return 0, syscall.Errno(5)
|
||||
})
|
||||
old := buildPromptChannels
|
||||
buildPromptChannels = func(commandRunner) []promptChannel {
|
||||
return []promptChannel{{
|
||||
name: "fake-failed-channel",
|
||||
available: func() error { return nil },
|
||||
run: func(promptRequest) error { return syscall.Errno(5) },
|
||||
}}
|
||||
}
|
||||
t.Cleanup(func() { buildPromptChannels = old })
|
||||
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
@@ -59,3 +65,42 @@ func TestShowError_WindowsBranch(t *testing.T) {
|
||||
|
||||
showError("测试错误", "这是一条测试错误消息")
|
||||
}
|
||||
|
||||
func TestMessageBoxW_WindowsOnly_StartupFlags(t *testing.T) {
|
||||
var gotFlags uintptr
|
||||
withMessageBoxW(t, func(_, _, _, flags uintptr) (uintptr, error) {
|
||||
gotFlags = flags
|
||||
return 1, syscall.Errno(0)
|
||||
})
|
||||
|
||||
if err := messageBox("测试标题", "测试消息", messageBoxStartupFlags()); err != nil {
|
||||
t.Fatalf("MessageBoxW 应成功: %v", err)
|
||||
}
|
||||
|
||||
for _, flag := range []uint{mbIconError, mbTaskModal, mbSetForeground, mbTopMost} {
|
||||
if gotFlags&uintptr(flag) == 0 {
|
||||
t.Fatalf("startup flags 缺少 0x%x,实际: 0x%x", flag, gotFlags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWindowsStartupChannelsUseToastBeforeMessageBox(t *testing.T) {
|
||||
runner := &fakeCommandRunner{paths: map[string]bool{"powershell.exe": true}}
|
||||
channels := platformStartupChannels(runner)
|
||||
if len(channels) != 2 {
|
||||
t.Fatalf("Windows 应有 Toast 和 MessageBox 两级通道,实际: %d", len(channels))
|
||||
}
|
||||
|
||||
if channels[0].name != "windows-toast" || channels[1].name != "windows-messagebox" {
|
||||
t.Fatalf("Windows 通道顺序错误: %s, %s", channels[0].name, channels[1].name)
|
||||
}
|
||||
if err := channels[0].available(); err != nil {
|
||||
t.Fatalf("PowerShell 存在时 Toast 通道应可用: %v", err)
|
||||
}
|
||||
if err := channels[0].run(promptRequest{title: "Nex 启动失败", message: "端口被占用"}); err != nil {
|
||||
t.Fatalf("Toast fake runner 应执行成功: %v", err)
|
||||
}
|
||||
if len(runner.calls) != 1 || runner.calls[0].name != "powershell.exe" {
|
||||
t.Fatalf("Toast 应调用 powershell.exe,实际: %#v", runner.calls)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user