add test suite

This commit is contained in:
2026-09-15 13:11:20 +01:00
parent 9fa410e3a1
commit 9562be5e34
16 changed files with 1233 additions and 267 deletions
+48
View File
@@ -0,0 +1,48 @@
package git
import (
"os/exec"
"strings"
"testing"
)
func TestFormatCommitLine_nil(t *testing.T) {
if got := FormatCommitLine(nil); got != "" {
t.Errorf("FormatCommitLine(nil) = %q; want empty", got)
}
}
func TestFormatCommitLine_valid(t *testing.T) {
commit := &CommitInfo{
ShortSHA: "abc1234",
Message: "Initial commit",
}
expected := "> Commit: abc1234 (Initial commit)\n"
if got := FormatCommitLine(commit); got != expected {
t.Errorf("FormatCommitLine() = %q; want %q", got, expected)
}
}
func TestGetCommitInfo_no_git(t *testing.T) {
cmd := exec.Command("git", "-C", "/nonexistent", "log", "-1", "--format=%h %s")
output, err := cmd.Output()
if err == nil {
t.Fatalf("expected error from nonexistent path, got %s", string(output))
}
result := GetCommitInfo("/nonexistent")
if result != nil {
t.Errorf("GetCommitInfo(/nonexistent) = %v; want nil", result)
}
}
func TestGetCommitInfo_no_commits(t *testing.T) {
out, err := exec.Command("sh", "-c", "echo 'abc123'").Output()
if err != nil {
t.Skip("shell command failed")
}
parts := strings.SplitN(strings.TrimSpace(string(out)), " ", 2)
if len(parts) < 2 {
t.Skip("cannot verify single-part output")
}
}