(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestInstallAndUninstall_Bash(t *testing.T) { |
| 16 | if runtime.GOOS == "windows" { |
| 17 | t.Skip("bash is not supported on Windows") |
| 18 | } |
| 19 | |
| 20 | var fileExists = func(path string) bool { |
| 21 | _, err := os.Stat(path) |
| 22 | return err == nil |
| 23 | } |
| 24 | |
| 25 | home := t.TempDir() |
| 26 | |
| 27 | // Set dirs.TmpFilesDir to a temp location specific for the test |
| 28 | origTmp := dirs.TmpFilesDir |
| 29 | tmpRoot := filepath.Join(t.TempDir(), "tmpfiles") |
| 30 | dirs.TmpFilesDir = tmpRoot |
| 31 | defer func() { dirs.TmpFilesDir = origTmp }() |
| 32 | |
| 33 | rootCmd := &cobra.Command{ |
| 34 | Use: "celer", |
| 35 | } |
| 36 | b := NewBashCompletion(home, rootCmd) |
| 37 | |
| 38 | // Ensure clean tmp dir exists |
| 39 | if err := dirs.CleanTmpFilesDir(); err != nil { |
| 40 | t.Fatalf("CleanTmpFilesDir failed: %v", err) |
| 41 | } |
| 42 | |
| 43 | // Install completion (should generate file in tmp then move it to destination) |
| 44 | if err := b.installCompletion(); err != nil { |
| 45 | t.Fatalf("installCompletion failed: %v", err) |
| 46 | } |
| 47 | |
| 48 | dest := filepath.Join(home, ".local", "share", "bash-completion", "completions", "celer") |
| 49 | if !fileExists(dest) { |
| 50 | t.Fatalf("expected completion file at %s to exist", dest) |
| 51 | } |
| 52 | |
| 53 | // Uninstall completion (should remove file and attempt to remove empty parent) |
| 54 | if err := b.uninstallCompletion(); err != nil { |
| 55 | t.Fatalf("uninstallCompletion failed: %v", err) |
| 56 | } |
| 57 | if fileExists(dest) { |
| 58 | t.Fatalf("expected completion file to be removed at %s", dest) |
| 59 | } |
| 60 | |
| 61 | // parent dir might be removed; ensure it does not contain the file |
| 62 | parent := filepath.Dir(dest) |
| 63 | if fileExists(parent) { |
| 64 | // If parent still exists ensure it's not containing our file |
| 65 | if fileExists(filepath.Join(parent, "celer")) { |
| 66 | t.Fatalf("completion file still present after uninstall") |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | func TestRegisterAndUnregisterRunCommand_Bash(t *testing.T) { |
| 72 | home := t.TempDir() |
nothing calls this directly
no test coverage detected