forked from Gitlink/gitlink-cli
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package interactive
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gitlink-org/gitlink-cli/shortcuts"
|
|
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
|
|
)
|
|
|
|
// TestE2E_ExecutingRealCommandProducesOutput is an end-to-end regression for
|
|
// "selecting a command shows no output". It drives the real shortcut registry
|
|
// (repo +list) through the executor and asserts that Execute returns either
|
|
// captured stdout OR a non-nil error — never both empty, which is what left
|
|
// the REPL silent before the RuntimeContext fix.
|
|
func TestE2E_ExecutingRealCommandProducesOutput(t *testing.T) {
|
|
all := shortcuts.GetAllShortcuts()
|
|
s, ok := findShortcut(all, "repo", "list")
|
|
if !ok {
|
|
t.Fatal("repo +list not found in registry")
|
|
}
|
|
if s.Run == nil {
|
|
t.Fatal("repo +list has no Run function")
|
|
}
|
|
|
|
exec := &Executor{}
|
|
// repo +list needs an owner; without --owner it tries git remote detection.
|
|
// Either way the executor must return something (output or error), not hang.
|
|
out, err := exec.Execute(s, map[string]string{})
|
|
|
|
// The contract: Execute never returns (empty, nil) for a real command —
|
|
// either it produced output, or it returned an error explaining the failure.
|
|
if out == "" && err == nil {
|
|
t.Fatal("Execute returned empty output AND nil error — REPL would show nothing (regression)")
|
|
}
|
|
|
|
// A non-empty result (output or error message) proves the command actually
|
|
// ran through a properly-initialized RuntimeContext instead of panicking.
|
|
t.Logf("output=%q err=%v", out, err)
|
|
_ = common.RuntimeContext{} // keep import
|
|
_ = strings.TrimSpace
|
|
}
|