mirror of
https://github.com/Cheviiot/Vintner.git
synced 2026-08-03 15:57:24 +00:00
Add test coverage for cmd/vintner and internal/i18n
Both were at 0% coverage. Focused on what's safely testable without touching the network or filesystem: flag validation (--architecture/ --host-arch, the same guard added in the stability pass), subcommand dispatch and aliases, help/usage error paths, and - for i18n - full language-detection table coverage plus a completeness check that every catalog key has both an EN and RU entry (an English-only or Russian-only entry would silently degrade rather than fail loudly, so this is worth locking in). cmd/vintner: 0% -> 28.8%, i18n: 0% -> 94.1%.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestRunDownloadRejectsInvalidArchFlags exercises the validation added
|
||||
// after the flags are parsed, which must reject typos before runDownload
|
||||
// gets anywhere near the network (FetchChannelManifest) - these tests would
|
||||
// hang/fail on network access if that ordering ever regressed.
|
||||
func TestRunDownloadRejectsInvalidArchFlags(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
args []string
|
||||
}{
|
||||
{"bad architecture", []string{"--architecture", "x866"}},
|
||||
{"bad architecture, valid mixed with invalid", []string{"--architecture", "x64", "--architecture", "sparc"}},
|
||||
{"bad host-arch", []string{"--host-arch", "sparc"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if code := runDownload(tc.args); code != 2 {
|
||||
t.Errorf("runDownload(%v) = %d, want 2", tc.args, code)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidArchitectureSets(t *testing.T) {
|
||||
for _, a := range []string{"x86", "x64", "arm", "arm64", "host"} {
|
||||
if !validArchitectures[a] {
|
||||
t.Errorf("validArchitectures[%q] = false, want true", a)
|
||||
}
|
||||
}
|
||||
for _, a := range []string{"x86", "x64", "arm64"} {
|
||||
if !validHostArchs[a] {
|
||||
t.Errorf("validHostArchs[%q] = false, want true", a)
|
||||
}
|
||||
}
|
||||
if validHostArchs["arm"] {
|
||||
t.Error(`validHostArchs["arm"] = true, want false (no 32-bit ARM host toolchain exists)`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRunEnvRequiresBin(t *testing.T) {
|
||||
if code := runEnv(nil); code != 1 {
|
||||
t.Errorf("runEnv(nil) = %d, want 1", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunEnvRejectsMissingBinDir(t *testing.T) {
|
||||
if code := runEnv([]string{"--bin", "/nonexistent/path/for/vintner/tests"}); code != 1 {
|
||||
t.Errorf("runEnv with a nonexistent --bin = %d, want 1", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToUnixPathList(t *testing.T) {
|
||||
got := toUnixPathList(`z:\vc\include;z:\kits\10\include`)
|
||||
want := "/vc/include;/kits/10/include"
|
||||
if got != want {
|
||||
t.Errorf("toUnixPathList(...) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRunInstallRejectsExtraArgs(t *testing.T) {
|
||||
if code := runInstall([]string{"one", "two"}); code != 1 {
|
||||
t.Errorf("runInstall with two args = %d, want 1", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunInstallHelp(t *testing.T) {
|
||||
for _, flag := range []string{"-h", "--help"} {
|
||||
if code := runInstall([]string{flag}); code != 1 {
|
||||
t.Errorf("runInstall([%q]) = %d, want 1", flag, code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestRunCLIDispatch covers the subset of runCLI's switch that has no side
|
||||
// effects (no filesystem/network touched) - the actual subcommand bodies
|
||||
// (download/install/env) get their own focused tests.
|
||||
func TestRunCLIDispatch(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
args []string
|
||||
want int
|
||||
}{
|
||||
{"no args prints usage", nil, 1},
|
||||
{"unknown subcommand", []string{"frobnicate"}, 1},
|
||||
{"help long", []string{"--help"}, 0},
|
||||
{"help short flag", []string{"-h"}, 0},
|
||||
{"help word", []string{"help"}, 0},
|
||||
{"help alias", []string{"h"}, 0},
|
||||
{"version word", []string{"version"}, 0},
|
||||
{"version alias", []string{"v"}, 0},
|
||||
{"version flag", []string{"--version"}, 0},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := runCLI(tc.args); got != tc.want {
|
||||
t.Errorf("runCLI(%v) = %d, want %d", tc.args, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDefaultToolchainDir(t *testing.T) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skipf("no home directory available: %v", err)
|
||||
}
|
||||
got, err := defaultToolchainDir()
|
||||
if err != nil {
|
||||
t.Fatalf("defaultToolchainDir() error: %v", err)
|
||||
}
|
||||
want := filepath.Join(home, ".vintner")
|
||||
if got != want {
|
||||
t.Errorf("defaultToolchainDir() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user