Includes the current working directory changes. Historical commits and release binaries are excluded to limit Gitea storage. Source base: d7515973fbfd6dd2001fa156c483455b8081c7cb
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
//go:build windows
|
||
|
||
package cursor
|
||
|
||
import (
|
||
"os"
|
||
"path/filepath"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
// 验证:注册表 PATH 中的 fnm\bin(仅含 fnm.exe)能被扩展到实际 node 所在目录。
|
||
func TestMergeNodeSearchPathFindsNode(t *testing.T) {
|
||
merged, _ := mergeNodeSearchPath()
|
||
if _, err := execLookPathIn(merged, "node.exe"); err != nil {
|
||
t.Fatalf("node.exe not found in merged PATH: %v", err)
|
||
}
|
||
}
|
||
|
||
// execLookPathIn 在给定 PATH 字符串下查找可执行文件。
|
||
func execLookPathIn(pathEnv string, file string) (string, error) {
|
||
for _, dir := range filepath.SplitList(pathEnv) {
|
||
if dir == "" {
|
||
continue
|
||
}
|
||
candidate := filepath.Join(dir, file)
|
||
if info, err := os.Stat(candidate); err == nil && !info.IsDir() {
|
||
return candidate, nil
|
||
}
|
||
// .cmd/.bat 等 PATHEXT 场景只处理精确名与 .cmd。
|
||
if !strings.HasSuffix(strings.ToLower(file), ".exe") {
|
||
cmdCandidate := candidate + ".cmd"
|
||
if info, err := os.Stat(cmdCandidate); err == nil && !info.IsDir() {
|
||
return cmdCandidate, nil
|
||
}
|
||
}
|
||
}
|
||
return "", os.ErrNotExist
|
||
}
|