Add unit tests and test tasks

- Add main_test.go with tests for formatContextInfo, stripANSI,
  StatusInput parsing, getGitInfo, and getGiteaStatus
- Add test, test:cover, test:fixture tasks to Taskfile
- 45% code coverage
This commit is contained in:
2025-12-18 06:07:13 +01:00
parent db80a7da81
commit f1de3c2050
2 changed files with 229 additions and 14 deletions

View File

@ -15,34 +15,44 @@ tasks:
build:
desc: Build with stripped symbols
cmds:
- go build -ldflags="{{.LDFLAGS}}" -o {{.BINARY}} .
- go build -ldflags="{{.LDFLAGS}}" -o bin/{{.BINARY}} .
sources:
- "*.go"
- go.mod
- go.sum
generates:
- "{{.BINARY}}"
- "bin/{{.BINARY}}"
build:debug:
desc: Build with debug symbols
cmds:
- go build -o {{.BINARY}} .
- go build -o bin/{{.BINARY}} .
run:
desc: Run with test fixture
deps: [build]
cmds:
- cat test/fixture.json | ./{{.BINARY}}
- cat test/fixture.json | ./bin/{{.BINARY}}
test:
desc: Run Go unit tests
cmds:
- go test -v ./...
test:cover:
desc: Run tests with coverage
cmds:
- go test -cover ./...
test:fixture:
desc: Run with test fixture and show output
deps: [build]
cmds:
- echo "=== Output ==="
- cat test/fixture.json | ./{{.BINARY}}
- cat test/fixture.json | ./bin/{{.BINARY}}
- echo ""
- echo "=== Timing (single run) ==="
- time sh -c 'cat test/fixture.json | ./{{.BINARY}} > /dev/null'
- time sh -c 'cat test/fixture.json | ./bin/{{.BINARY}} > /dev/null'
bench:
desc: Benchmark Go vs Shell (100 runs)
@ -50,10 +60,10 @@ tasks:
cmds:
- |
echo "=== Pure Go (100 runs) ==="
time for i in $(seq 1 100); do cat test/fixture.json | ./{{.BINARY}} >/dev/null; done
echo ""
echo "=== Shell (100 runs) ==="
time for i in $(seq 1 100); do cat test/fixture.json | ./statusline.sh >/dev/null; done
time for i in $(seq 1 100); do cat test/fixture.json | ./bin/{{.BINARY}} >/dev/null; done
# echo ""
# echo "=== Shell (100 runs) ==="
# time for i in $(seq 1 100); do cat test/fixture.json | ./statusline.sh >/dev/null; done
silent: false
bench:go:
@ -62,7 +72,7 @@ tasks:
cmds:
- |
echo "=== Pure Go (100 runs) ==="
time for i in $(seq 1 100); do cat test/fixture.json | ./{{.BINARY}} >/dev/null; done
time for i in $(seq 1 100); do cat test/fixture.json | ./bin/{{.BINARY}} >/dev/null; done
tidy:
desc: Run go mod tidy
@ -92,18 +102,18 @@ tasks:
clean:
desc: Remove built binary
cmds:
- rm -f {{.BINARY}}
- rm -rf bin/
size:
desc: Show binary size
deps: [build]
cmds:
- ls -lh {{.BINARY}}
- ls -lh bin/{{.BINARY}}
install:
desc: Install to ~/.claude/
deps: [build]
cmds:
- mkdir -p ~/.claude
- cp {{.BINARY}} ~/.claude/{{.BINARY}}
- cp bin/{{.BINARY}} ~/.claude/{{.BINARY}}
- echo "Installed to ~/.claude/{{.BINARY}}"