fix: all issues by golangci-lint

This commit is contained in:
verse91
2026-05-09 23:49:33 +07:00
parent e587f02798
commit c76541258a
18 changed files with 118 additions and 79 deletions
+35
View File
@@ -0,0 +1,35 @@
version: 2
run:
timeout: 5m
tests: true
linters:
disable-all: true
enable:
- errcheck
- govet
- staticcheck
- errorlint
- errname
- bodyclose
- sqlclosecheck
- noctx
- ineffassign
- unconvert
- bidichk
linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
govet:
enable-all: true
disable:
- fieldalignment
issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
+1 -1
View File
@@ -10,7 +10,7 @@ var DebugWriter io.Writer
func debugLog(format string, a ...interface{}) { func debugLog(format string, a ...interface{}) {
if DebugWriter != nil { if DebugWriter != nil {
fmt.Fprintf(DebugWriter, format+"\n", a...) _, _ = fmt.Fprintf(DebugWriter, format+"\n", a...)
} }
} }
+2 -1
View File
@@ -1,6 +1,7 @@
package dev package dev
import ( import (
"context"
"os/exec" "os/exec"
"strings" "strings"
@@ -50,7 +51,7 @@ func GitPushPullGenerator(tokens []string, prefix string, partial string) []core
func getGitResults(prefix string, args ...string) []core.Suggestion { func getGitResults(prefix string, args ...string) []core.Suggestion {
cwd := core.GetCWD() cwd := core.GetCWD()
cmd := exec.Command("git", args...) cmd := exec.CommandContext(context.Background(), "git", args...)
cmd.Dir = cwd cmd.Dir = cwd
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
+3 -5
View File
@@ -6,6 +6,7 @@ package fs
import ( import (
"bytes" "bytes"
"context"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@@ -35,7 +36,7 @@ func ZoxideGenerator() core.GeneratorFunc {
localSuggestions := core.FileGenerator("/")(tokens, prefix, fullQuery) localSuggestions := core.FileGenerator("/")(tokens, prefix, fullQuery)
var zoxideSuggestions []core.Suggestion var zoxideSuggestions []core.Suggestion
cmd := exec.Command("zoxide", "query", "-l") cmd := exec.CommandContext(context.Background(), "zoxide", "query", "-l")
out, err := cmd.Output() out, err := cmd.Output()
if err == nil { if err == nil {
lines := strings.Split(string(bytes.TrimSpace(out)), "\n") lines := strings.Split(string(bytes.TrimSpace(out)), "\n")
@@ -79,10 +80,7 @@ func ZoxideGenerator() core.GeneratorFunc {
var finalResults []core.Suggestion var finalResults []core.Suggestion
seen := make(map[string]bool) seen := make(map[string]bool)
for _, s := range localSuggestions { finalResults = append(finalResults, localSuggestions...)
finalResults = append(finalResults, s)
}
for _, s := range zoxideSuggestions { for _, s := range zoxideSuggestions {
if !seen[s.Cmd] { if !seen[s.Cmd] {
+1 -1
View File
@@ -23,7 +23,7 @@ func init() {
return nil return nil
} }
} }
defer file.Close() defer func() { _ = file.Close() }()
var suggestions []core.Suggestion var suggestions []core.Suggestion
seen := make(map[string]bool) seen := make(map[string]bool)
+1 -1
View File
@@ -19,7 +19,7 @@ func init() {
// No Makefile, don't pretend we have one // No Makefile, don't pretend we have one
return nil return nil
} }
defer file.Close() defer func() { _ = file.Close() }()
var suggestions []core.Suggestion var suggestions []core.Suggestion
seen := make(map[string]bool) seen := make(map[string]bool)
+1 -1
View File
@@ -68,7 +68,7 @@ func SearchHistory(query string) ([]HistResult, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer file.Close() defer func() { _ = file.Close() }()
var allCmds []string var allCmds []string
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
+2 -3
View File
@@ -2,6 +2,7 @@ package shell
import ( import (
"fmt" "fmt"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -94,9 +95,7 @@ func ScanPosixAliases(files []string) map[string]string {
continue continue
} }
for k, v := range ParseAliases(string(data)) { maps.Copy(aliases, ParseAliases(string(data)))
aliases[k] = v
}
} }
return aliases return aliases
} }
+1 -1
View File
@@ -53,6 +53,6 @@ func (s *Server) Start() {
} }
func (s *Server) Close() { func (s *Server) Close() {
s.conn.Close() _ = s.conn.Close()
close(s.StateChan) close(s.StateChan)
} }
+5
View File
@@ -43,3 +43,8 @@ alias ana := analyze
[group('dev')] [group('dev')]
analyze: analyze:
@go run scripts/test_analyzer.go @go run scripts/test_analyzer.go
# run linter
[group('dev')]
lint:
@golangci-lint run ./...
+2 -2
View File
@@ -100,9 +100,9 @@ var setupCmd = &cobra.Command{
fmt.Printf("Failed to update %s: %v\n", configFile, err) fmt.Printf("Failed to update %s: %v\n", configFile, err)
return return
} }
defer f.Close() defer func() { _ = f.Close() }()
f.WriteString("\n# Iris Autocomplete\n" + evalCmd + "\n") _, _ = f.WriteString("\n# Iris Autocomplete\n" + evalCmd + "\n")
fmt.Printf("✓ Added iris integration to %s\n", configFile) fmt.Printf("✓ Added iris integration to %s\n", configFile)
} }
+3 -5
View File
@@ -34,7 +34,7 @@ It works exactly like coding editor suggestion menu drop down.`,
f, _ := os.OpenFile("iris.log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) f, _ := os.OpenFile("iris.log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
debugLogger = f debugLogger = f
core.DebugWriter = f core.DebugWriter = f
fmt.Fprintf(debugLogger, "--- IRIS DEBUG LOG ---\n") _, _ = fmt.Fprintf(debugLogger, "--- IRIS DEBUG LOG ---\n")
} }
runWrapper() runWrapper()
}, },
@@ -42,7 +42,6 @@ It works exactly like coding editor suggestion menu drop down.`,
shellFlag string shellFlag string
debugMode bool debugMode bool
debugLogger *os.File debugLogger *os.File
isReload bool
) )
func init() { func init() {
@@ -52,15 +51,14 @@ func init() {
func debugLog(format string, a ...interface{}) { func debugLog(format string, a ...interface{}) {
if debugLogger != nil { if debugLogger != nil {
fmt.Fprintf(debugLogger, format+"\n", a...) _, _ = fmt.Fprintf(debugLogger, format+"\n", a...)
} }
} }
func Execute() { func Execute() {
if os.Getenv("IRIS_RELOADED") == "true" { if os.Getenv("IRIS_RELOADED") == "true" {
isReload = true
fmt.Printf("\r\033[K\033[35m[IRIS] reloading...\033[0m\n") fmt.Printf("\r\033[K\033[35m[IRIS] reloading...\033[0m\n")
os.Unsetenv("IRIS_RELOADED") _ = os.Unsetenv("IRIS_RELOADED")
} }
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
+2 -1
View File
@@ -1,6 +1,7 @@
package root package root
import ( import (
"context"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@@ -55,7 +56,7 @@ func detectShell() string {
} }
func getActiveInnerShell(rootPid int, defaultShell string) string { func getActiveInnerShell(rootPid int, defaultShell string) string {
cmd := exec.Command("ps", "-e", "-o", "pid,ppid,comm") cmd := exec.CommandContext(context.Background(), "ps", "-e", "-o", "pid,ppid,comm")
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
return defaultShell return defaultShell
+1 -1
View File
@@ -10,5 +10,5 @@ var termMutex sync.Mutex
func TermWrite(data []byte) { func TermWrite(data []byte) {
termMutex.Lock() termMutex.Lock()
defer termMutex.Unlock() defer termMutex.Unlock()
os.Stdout.Write(data) _, _ = os.Stdout.Write(data)
} }
+39 -38
View File
@@ -3,6 +3,7 @@ package root
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@@ -34,7 +35,7 @@ func getStateFile() string {
return "" return ""
} }
dir := filepath.Join(home, ".iris") dir := filepath.Join(home, ".iris")
os.MkdirAll(dir, 0755) _ = os.MkdirAll(dir, 0755)
return filepath.Join(dir, "state.json") return filepath.Join(dir, "state.json")
} }
@@ -60,7 +61,7 @@ func saveMode(mode string) {
state := State{Mode: mode} state := State{Mode: mode}
data, err := json.MarshalIndent(state, "", " ") data, err := json.MarshalIndent(state, "", " ")
if err == nil { if err == nil {
os.WriteFile(file, data, 0644) _ = os.WriteFile(file, data, 0644)
} }
} }
} }
@@ -78,7 +79,7 @@ func runWrapper() {
var shellName string var shellName string
if active := os.Getenv("IRIS_ACTIVE_SHELL"); active != "" { if active := os.Getenv("IRIS_ACTIVE_SHELL"); active != "" {
shellName = active shellName = active
os.Unsetenv("IRIS_ACTIVE_SHELL") _ = os.Unsetenv("IRIS_ACTIVE_SHELL")
} else if shellFlag != "" { } else if shellFlag != "" {
shellName = shellFlag shellName = shellFlag
} else { } else {
@@ -88,7 +89,8 @@ func runWrapper() {
shell.Init(shellName) shell.Init(shellName)
adapter := shell.Current adapter := shell.Current
c := exec.Command(adapter.GetShellPath()) ctx := context.Background()
c := exec.CommandContext(ctx, adapter.GetShellPath())
c.ExtraFiles = make([]*os.File, 11) c.ExtraFiles = make([]*os.File, 11)
// pass write end of pipe to shell as fd 10 (I chose 10 just because it won't conflict with other file descriptors) // pass write end of pipe to shell as fd 10 (I chose 10 just because it won't conflict with other file descriptors)
c.ExtraFiles[10] = w c.ExtraFiles[10] = w
@@ -96,10 +98,10 @@ func runWrapper() {
ptmx, err := pty.Start(c) ptmx, err := pty.Start(c)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "[IRIS] failed to start PTY: %v\n", err) _, _ = fmt.Fprintf(os.Stderr, "[IRIS] failed to start PTY: %v\n", err)
return return
} }
defer ptmx.Close() defer func() { _ = ptmx.Close() }()
_ = pty.InheritSize(os.Stdin, ptmx) _ = pty.InheritSize(os.Stdin, ptmx)
core.ShellPID = c.Process.Pid core.ShellPID = c.Process.Pid
@@ -124,18 +126,17 @@ func runWrapper() {
case syscall.SIGUSR1: case syscall.SIGUSR1:
// trigger iris reload by executing itself again // trigger iris reload by executing itself again
exe, _ := os.Executable() exe, _ := os.Executable()
// this marks for the next iris process that it've just reloaded _ = os.Setenv("IRIS_RELOADED", "true")
os.Setenv("IRIS_RELOADED", "true")
innerShell := getActiveInnerShell(c.Process.Pid, shellName) innerShell := getActiveInnerShell(c.Process.Pid, shellName)
if innerShell != "" { if innerShell != "" {
// to detect which is last shell (bash, zsh, fish) // to detect which is last shell (bash, zsh, fish)
os.Setenv("IRIS_ACTIVE_SHELL", innerShell) _ = os.Setenv("IRIS_ACTIVE_SHELL", innerShell)
} }
if c.Process != nil { if c.Process != nil {
_ = syscall.Kill(c.Process.Pid, syscall.SIGKILL) _ = syscall.Kill(c.Process.Pid, syscall.SIGKILL)
ptmx.Close() _ = ptmx.Close()
} }
if oldState != nil { if oldState != nil {
@@ -160,7 +161,7 @@ func runWrapper() {
} }
continue continue
} }
os.Stdout.Write(buf[:n]) _, _ = os.Stdout.Write(buf[:n])
} }
}() }()
@@ -209,17 +210,17 @@ func runWrapper() {
results := MergeResults(query, "spec") results := MergeResults(query, "spec")
if len(results) == 0 { if len(results) == 0 {
os.Stdout.Write([]byte(overlay.ClearAndDisable())) _, _ = os.Stdout.Write([]byte(overlay.ClearAndDisable()))
continue continue
} }
os.Stdout.Write([]byte(overlay.Clear())) _, _ = os.Stdout.Write([]byte(overlay.Clear()))
overlay.UpdateItems(results) overlay.UpdateItems(results)
var rBuf strings.Builder var rBuf strings.Builder
if !disableGhostText.Load() { if !disableGhostText.Load() {
rBuf.WriteString(overlay.RenderGhostText(query, false)) rBuf.WriteString(overlay.RenderGhostText(query, false))
} }
rBuf.WriteString(overlay.Render()) rBuf.WriteString(overlay.Render())
os.Stdout.Write([]byte(rBuf.String())) _, _ = os.Stdout.Write([]byte(rBuf.String()))
} }
}() }()
@@ -248,7 +249,7 @@ func runWrapper() {
navCopy := userNavigated navCopy := userNavigated
if bufCopy == "" && !navCopy { if bufCopy == "" && !navCopy {
os.Stdout.Write([]byte(overlay.ClearAndDisable())) _, _ = os.Stdout.Write([]byte(overlay.ClearAndDisable()))
return return
} }
@@ -268,7 +269,7 @@ func runWrapper() {
if len(results) == 0 { if len(results) == 0 {
b.WriteString(overlay.ClearAndDisable()) b.WriteString(overlay.ClearAndDisable())
os.Stdout.Write([]byte(b.String())) _, _ = os.Stdout.Write([]byte(b.String()))
return return
} }
@@ -286,7 +287,7 @@ func runWrapper() {
b.WriteString(overlay.RenderGhostText(bufCopy, navCopy)) b.WriteString(overlay.RenderGhostText(bufCopy, navCopy))
} }
b.WriteString(overlay.Render()) b.WriteString(overlay.Render())
os.Stdout.Write([]byte(b.String())) _, _ = os.Stdout.Write([]byte(b.String()))
}) })
} }
@@ -306,7 +307,7 @@ func runWrapper() {
} }
b.WriteString(overlay.Render()) b.WriteString(overlay.Render())
} }
os.Stdout.Write([]byte(b.String())) _, _ = os.Stdout.Write([]byte(b.String()))
} }
// reads from stdin and decides what to forward or intercept // reads from stdin and decides what to forward or intercept
@@ -322,7 +323,7 @@ func runWrapper() {
if n > 0 { if n > 0 {
if isExecuting() { if isExecuting() {
ptmx.Write(inputSlice[:n]) _, _ = ptmx.Write(inputSlice[:n])
continue continue
} }
@@ -339,7 +340,7 @@ func runWrapper() {
intercepted = true intercepted = true
suggestionsEnabled = !suggestionsEnabled suggestionsEnabled = !suggestionsEnabled
if !suggestionsEnabled { if !suggestionsEnabled {
os.Stdout.Write([]byte(overlay.ClearAndDisable())) _, _ = os.Stdout.Write([]byte(overlay.ClearAndDisable()))
} else { } else {
shouldOverlayDraw = true shouldOverlayDraw = true
} }
@@ -351,7 +352,7 @@ func runWrapper() {
intercepted = true intercepted = true
userNavigated = true userNavigated = true
os.Stdout.Write([]byte(overlay.Clear())) // clear old menu _, _ = os.Stdout.Write([]byte(overlay.Clear())) // clear old menu
if inputSlice[i+2] == 'A' { // up arrow if inputSlice[i+2] == 'A' { // up arrow
overlay.Cursor-- overlay.Cursor--
@@ -366,8 +367,8 @@ func runWrapper() {
} }
selected := overlay.Items[overlay.Cursor].Cmd selected := overlay.Items[overlay.Cursor].Cmd
ptmx.Write([]byte{0x15}) // ctrl+u to clear line _, _ = ptmx.Write([]byte{0x15}) // ctrl+u to clear line
ptmx.Write([]byte(selected)) _, _ = ptmx.Write([]byte(selected))
naiveBuffer = selected naiveBuffer = selected
renderNow() renderNow()
@@ -407,8 +408,8 @@ func runWrapper() {
} }
selected := overlay.Items[overlay.Cursor].Cmd selected := overlay.Items[overlay.Cursor].Cmd
ptmx.Write([]byte{0x15}) // ctrl+u to clear line _, _ = ptmx.Write([]byte{0x15}) // ctrl+u to clear line
ptmx.Write([]byte(selected)) _, _ = ptmx.Write([]byte(selected))
naiveBuffer = selected naiveBuffer = selected
userNavigated = true userNavigated = true
@@ -423,7 +424,7 @@ func runWrapper() {
if len(ghostText) > 0 { if len(ghostText) > 0 {
intercepted = true intercepted = true
naiveBuffer += ghostText naiveBuffer += ghostText
ptmx.Write([]byte(ghostText)) _, _ = ptmx.Write([]byte(ghostText))
shouldOverlayDraw = true shouldOverlayDraw = true
i += 2 i += 2
continue continue
@@ -434,15 +435,15 @@ func runWrapper() {
// forward escape sequence to pty if not intercepted // forward escape sequence to pty if not intercepted
if !intercepted { if !intercepted {
os.Stdout.Write([]byte(overlay.ClearAndDisable())) _, _ = os.Stdout.Write([]byte(overlay.ClearAndDisable()))
disableGhostText.Store(true) disableGhostText.Store(true)
naiveBuffer = "" naiveBuffer = ""
ptmx.Write([]byte{b}) _, _ = ptmx.Write([]byte{b})
// skip remaining bytes of the escape sequence to avoid misinterpretation // skip remaining bytes of the escape sequence to avoid misinterpretation
for j := i + 1; j < n; j++ { for j := i + 1; j < n; j++ {
char := inputSlice[j] char := inputSlice[j]
ptmx.Write([]byte{char}) _, _ = ptmx.Write([]byte{char})
i = j i = j
if (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || char == '~' { if (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || char == '~' {
break break
@@ -467,9 +468,9 @@ func runWrapper() {
// enter is not used to select suggestions // enter is not used to select suggestions
} else if overlay.Visible && (b == 0x0d || b == 0x0a) { } else if overlay.Visible && (b == 0x0d || b == 0x0a) {
intercepted = true intercepted = true
os.Stdout.Write([]byte(overlay.ClearAndDisable())) _, _ = os.Stdout.Write([]byte(overlay.ClearAndDisable()))
ptmx.Write([]byte{0x0d}) _, _ = ptmx.Write([]byte{0x0d})
naiveBuffer = "" naiveBuffer = ""
disableGhostText.Store(false) disableGhostText.Store(false)
shouldOverlayDraw = false shouldOverlayDraw = false
@@ -481,7 +482,7 @@ func runWrapper() {
shouldOverlayDraw = true shouldOverlayDraw = true
} else { } else {
selected := overlay.Items[overlay.Cursor].Cmd selected := overlay.Items[overlay.Cursor].Cmd
os.Stdout.Write([]byte(overlay.ClearAndDisable())) _, _ = os.Stdout.Write([]byte(overlay.ClearAndDisable()))
if mode == "spec" { if mode == "spec" {
selected = strings.TrimSpace(selected) + " " selected = strings.TrimSpace(selected) + " "
@@ -489,8 +490,8 @@ func runWrapper() {
naiveBuffer = selected naiveBuffer = selected
ptmx.Write([]byte{0x15}) // ctrl+u to clear line _, _ = ptmx.Write([]byte{0x15}) // ctrl+u to clear line
ptmx.Write([]byte(selected)) _, _ = ptmx.Write([]byte(selected))
overlay.Cursor = 0 // this prevents when you tab, it switchs between suggestions non-stop overlay.Cursor = 0 // this prevents when you tab, it switchs between suggestions non-stop
@@ -503,7 +504,7 @@ func runWrapper() {
} }
if !intercepted { if !intercepted {
ptmx.Write([]byte{b}) _, _ = ptmx.Write([]byte{b})
// we handle line editing keys manually to keep naiveBuffer in sync // we handle line editing keys manually to keep naiveBuffer in sync
// since terminal is in raw mode, we must update our state for every change // since terminal is in raw mode, we must update our state for every change
switch b { switch b {
@@ -526,7 +527,7 @@ func runWrapper() {
case '\r', '\n', 0x03, 0x15, 0x0C: // enter, ctrl+c, ctrl+u, ctrl+l: clear buffer on line reset case '\r', '\n', 0x03, 0x15, 0x0C: // enter, ctrl+c, ctrl+u, ctrl+l: clear buffer on line reset
naiveBuffer = "" naiveBuffer = ""
disableGhostText.Store(false) disableGhostText.Store(false)
os.Stdout.Write([]byte(overlay.ClearAndDisable())) _, _ = os.Stdout.Write([]byte(overlay.ClearAndDisable()))
userNavigated = false userNavigated = false
default: default:
// track normal printable characters in the buffer for matching // track normal printable characters in the buffer for matching
@@ -535,8 +536,8 @@ func runWrapper() {
if b == ' ' && naiveBuffer != "" && !strings.Contains(naiveBuffer, " ") { if b == ' ' && naiveBuffer != "" && !strings.Contains(naiveBuffer, " ") {
if target, ok := core.GetAlias(naiveBuffer); ok { if target, ok := core.GetAlias(naiveBuffer); ok {
// clear the current alias and replace it with the full command // clear the current alias and replace it with the full command
ptmx.Write([]byte{0x15}) // ctrl+u to clear the current input line _, _ = ptmx.Write([]byte{0x15}) // ctrl+u to clear the current input line
ptmx.Write([]byte(target + " ")) _, _ = ptmx.Write([]byte(target + " "))
naiveBuffer = target + " " naiveBuffer = target + " "
shouldOverlayDraw = true shouldOverlayDraw = true
continue continue
+7 -7
View File
@@ -12,15 +12,15 @@ import (
func TestFileGenerator(t *testing.T) { func TestFileGenerator(t *testing.T) {
// Setup mock files // Setup mock files
tmp := t.TempDir() tmp := t.TempDir()
os.MkdirAll(filepath.Join(tmp, "src"), 0755) _ = os.MkdirAll(filepath.Join(tmp, "src"), 0755)
os.WriteFile(filepath.Join(tmp, "main.go"), []byte(""), 0644) _ = os.WriteFile(filepath.Join(tmp, "main.go"), []byte(""), 0644)
os.WriteFile(filepath.Join(tmp, "README.md"), []byte(""), 0644) _ = os.WriteFile(filepath.Join(tmp, "README.md"), []byte(""), 0644)
os.WriteFile(filepath.Join(tmp, ".hidden"), []byte(""), 0644) _ = os.WriteFile(filepath.Join(tmp, ".hidden"), []byte(""), 0644)
os.WriteFile(filepath.Join(tmp, "src/utils.go"), []byte(""), 0644) _ = os.WriteFile(filepath.Join(tmp, "src/utils.go"), []byte(""), 0644)
oldWd, _ := os.Getwd() oldWd, _ := os.Getwd()
os.Chdir(tmp) _ = os.Chdir(tmp)
defer os.Chdir(oldWd) defer func() { _ = os.Chdir(oldWd) }()
// REQUIREMENT: dirOnly shows only dirs // REQUIREMENT: dirOnly shows only dirs
t.Run("dirOnly shows only dirs", func(t *testing.T) { t.Run("dirOnly shows only dirs", func(t *testing.T) {
+3 -3
View File
@@ -16,12 +16,12 @@ func TestZoxideGenerator(t *testing.T) {
// Script that prints mock directories // Script that prints mock directories
script := "#!/bin/sh\necho \"/home/verse/project1\n/home/verse/docs\n/home/verse/dev/iris\"" script := "#!/bin/sh\necho \"/home/verse/project1\n/home/verse/docs\n/home/verse/dev/iris\""
os.WriteFile(mockZoxide, []byte(script), 0755) _ = os.WriteFile(mockZoxide, []byte(script), 0755)
// Add tmp to PATH // Add tmp to PATH
oldPath := os.Getenv("PATH") oldPath := os.Getenv("PATH")
os.Setenv("PATH", tmp+string(os.PathListSeparator)+oldPath) _ = os.Setenv("PATH", tmp+string(os.PathListSeparator)+oldPath)
defer os.Setenv("PATH", oldPath) defer func() { _ = os.Setenv("PATH", oldPath) }()
gen := fs.ZoxideGenerator() gen := fs.ZoxideGenerator()
+8 -7
View File
@@ -14,22 +14,23 @@ func TestIntegration_ZoxideMultiWord(t *testing.T) {
// Create mock directory with spaces // Create mock directory with spaces
tmp := t.TempDir() tmp := t.TempDir()
targetDir := filepath.Join(tmp, "My Awesome Project") targetDir := filepath.Join(tmp, "My Awesome Project")
os.MkdirAll(targetDir, 0755) _ = os.MkdirAll(targetDir, 0755)
// Mock shell environment // Mock shell environment
oldWd, _ := os.Getwd() oldWd, _ := os.Getwd()
os.Chdir(tmp) _ = os.Chdir(tmp)
defer os.Chdir(oldWd) defer func() { _ = os.Chdir(oldWd) }()
// Mock zoxide binary // Mock zoxide binary
mockBinDir := t.TempDir() mockBinDir := t.TempDir()
mockZoxide := filepath.Join(mockBinDir, "zoxide") mockZoxide := filepath.Join(mockBinDir, "zoxide")
// Create mock zoxide binary
script := "#!/bin/sh\necho \"" + targetDir + "\"" script := "#!/bin/sh\necho \"" + targetDir + "\""
os.WriteFile(mockZoxide, []byte(script), 0755) _ = os.WriteFile(mockZoxide, []byte(script), 0755)
// Add mock bin to PATH
oldPath := os.Getenv("PATH") oldPath := os.Getenv("PATH")
os.Setenv("PATH", mockBinDir+string(os.PathListSeparator)+oldPath) _ = os.Setenv("PATH", mockBinDir+string(os.PathListSeparator)+oldPath)
defer os.Setenv("PATH", oldPath) defer func() { _ = os.Setenv("PATH", oldPath) }()
t.Run("z matches multi-word folder without quotes", func(t *testing.T) { t.Run("z matches multi-word folder without quotes", func(t *testing.T) {
// Simulating user typing "z My Awe" // Simulating user typing "z My Awe"