oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package testci
2
3import (
4 "bufio"
5 "os"
6 "strings"
7 "testing"
8)
9
10// Budget records stay one short line each. Merges used to join both
11// sides' reasons, and a record grew past the budget tool's 64 KB line
12// limit (2026-11-12). A reason is the measured value and a short why,
13// never a history: that lives in the commits.
14const (
15 maxBudgetRecord = 500
16 maxBudgetReason = 200
17)
18
19func TestBudgetRecordsAreShort(t *testing.T) {
20 f, err := os.Open("../../.rastrillo/budgets.txt")
21 if err != nil {
22 t.Fatal(err)
23 }
24 defer f.Close()
25 sc := bufio.NewScanner(f)
26 sc.Buffer(make([]byte, 0, 64<<10), 1<<20)
27 for n := 1; sc.Scan(); n++ {
28 line := sc.Text()
29 if line == "" || strings.HasPrefix(line, "#") {
30 continue
31 }
32 if len(line) > maxBudgetRecord {
33 t.Errorf(".rastrillo/budgets.txt:%d: record is %d bytes, over %d: keep the reason to the measured value and a short why", n, len(line), maxBudgetRecord)
34 continue
35 }
36 if r := budgetReason(line); len(r) > maxBudgetReason {
37 t.Errorf(".rastrillo/budgets.txt:%d: reason is %d bytes, over %d", n, len(r), maxBudgetReason)
38 }
39 }
40 if err := sc.Err(); err != nil {
41 t.Fatal(err)
42 }
43}
44
45// budgetReason is a record's reason: what follows its fixed fields
46// (size: dir, source, test; time: dir, duration; perf: method, path,
47// duration; boot: duration).
48func budgetReason(line string) string {
49 f := strings.Fields(line)
50 fixed := map[string]int{"size": 4, "time": 3, "perf": 4, "boot": 2}[f[0]]
51 if fixed == 0 || len(f) <= fixed {
52 return ""
53 }
54 return strings.Join(f[fixed:], " ")
55}
56