mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
internal/ui has no package state: ui.UI holds the streams, terminal flags, run log, status line, cleanup stack and interrupt flag, and its functions are methods. ui.Main makes the run's UI on devvm's own streams, owns signals, recovers Die and runs the cleanups; ui.New makes one on other streams. cmd/devvm passes it to cli.Execute, and every cli command gets it through its constructor. Only cmd/devvm and internal/cli import internal/ui (a depguard rule). Each other package defines the small UI interface it needs, which its constructor takes, filling fields tests set: - gitprotect.New, secrets.NewStore, from.NewLookup: a warn func - ubuntu.New: LoggedCmd, Note - netpolicy.NewProxy: Note, Warn, Ask, Confirm, StdinIsTerminal; its log lines drop control characters themselves (oneLine) - sshagent.New: Info, Note, Warn, LogWriter - tools.New: Info, Warn, LogNote, Status, LoggedCmd, AddCleanup - lima.New, smolvm.New: Info, Warn, LoggedCmd (their Runner's Run), WithSteps, AddCleanup, Interrupted; lima LogNote and ubuntu's too - backends.Registry: lima's and smolvm's - vm.NewEnv: all of the above, Say, Stdout, Stderr; Env has Stdout, LogNote, LogWriter, LoggedCmd, AddCleanup, Interrupted fields - build.Builder: Terminal and LogNote fields - sshconfig.New: its caller sets what it prints and asks ui's tests build their own UI over buffers and run in parallel; other packages' tests use small fakes; cli's unit tests a UI over buffers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
27 lines
720 B
Go
27 lines
720 B
Go
package cli
|
|
|
|
import "testing"
|
|
|
|
// A release build's version is the one it was given, as it is; root's
|
|
// --version prints devvm's.
|
|
func TestVersionFromRelease(t *testing.T) {
|
|
t.Parallel()
|
|
if got := versionOf("1.2.3"); got != "1.2.3" {
|
|
t.Errorf("versionOf(1.2.3) = %q, want 1.2.3", got)
|
|
}
|
|
u, _, _ := testUI()
|
|
if got, want := NewRoot(u).Version, devvmVersion(); got != want {
|
|
t.Errorf("root's Version = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
// --version has no -v: Cobra would add one.
|
|
func TestVersionFlagHasNoShorthand(t *testing.T) {
|
|
t.Parallel()
|
|
u, _, _ := testUI()
|
|
f := NewRoot(u).Flags().Lookup("version")
|
|
if f == nil || f.Shorthand != "" {
|
|
t.Errorf("--version = %+v, want a flag with no shorthand", f)
|
|
}
|
|
}
|