Some checks are pending
Security Scan / security (push) Waiting to run
- Remove banned imports (fmt, log, errors, os, strings, path/filepath, encoding/json) from all cmd/ packages; replace with core.* primitives and cli.* wrappers - Rename abbreviated variables (cfg→configuration, reg→registry, cmd→proc, c→toolCheck/checkBuilder, sb→builder, out→output, r→repo/reason, b→branchName) across config, doctor, pkgcmd, help - Add usage-example comments to all exported functions in pkg/cli (strings.go, log.go, i18n.go) - Add complete Good/Bad/Ugly test triads to all pkg/cli test files: new files for command, errors, frame_components, i18n, log, render, runtime, strings, utils; updated existing check, daemon, glyph, layout, output, ansi, commands, frame, prompt, stream, styles, tracker, tree Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package cli
|
|
|
|
import "testing"
|
|
|
|
func TestRuntime_Good(t *testing.T) {
|
|
// Init with valid options should succeed.
|
|
err := Init(Options{
|
|
AppName: "test-cli",
|
|
Version: "0.0.1",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Init: unexpected error: %v", err)
|
|
}
|
|
defer Shutdown()
|
|
|
|
// Core() returns non-nil after Init.
|
|
coreInstance := Core()
|
|
if coreInstance == nil {
|
|
t.Error("Core(): returned nil after Init")
|
|
}
|
|
|
|
// RootCmd() returns non-nil after Init.
|
|
rootCommand := RootCmd()
|
|
if rootCommand == nil {
|
|
t.Error("RootCmd(): returned nil after Init")
|
|
}
|
|
|
|
// Context() returns non-nil after Init.
|
|
ctx := Context()
|
|
if ctx == nil {
|
|
t.Error("Context(): returned nil after Init")
|
|
}
|
|
}
|
|
|
|
func TestRuntime_Bad(t *testing.T) {
|
|
// Shutdown when not initialised should not panic.
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("Shutdown() panicked when not initialised: %v", r)
|
|
}
|
|
}()
|
|
// Reset singleton so this test can run standalone.
|
|
// We use a fresh Shutdown here — it should be a no-op.
|
|
Shutdown()
|
|
}
|
|
|
|
func TestRuntime_Ugly(t *testing.T) {
|
|
// Once is idempotent: calling Init twice should succeed.
|
|
err := Init(Options{AppName: "test-ugly"})
|
|
if err != nil {
|
|
t.Fatalf("Init (second call): unexpected error: %v", err)
|
|
}
|
|
defer Shutdown()
|
|
}
|