Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33

Open
lilleman wants to merge 966 commits from worktree-todo-relative-dates-exact-counts into main
2 changed files with 24 additions and 2 deletions
Showing only changes of commit 3aa747de02 - Show all commits
+3 -2
View File
@@ -2,6 +2,7 @@ package fejkdata
import ( import (
"encoding/base64" "encoding/base64"
"fmt"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@@ -217,8 +218,8 @@ func TestArgGuardsPanic(t *testing.T) {
func mustPanic(t *testing.T, name string, call func()) { func mustPanic(t *testing.T, name string, call func()) {
t.Helper() t.Helper()
defer func() { defer func() {
if recover() == nil { if r := recover(); r == nil || !strings.HasPrefix(fmt.Sprint(r), "fejkdata: internal error: ") {
t.Errorf("%s: no panic, want the invariant reported", name) t.Errorf("%s: recovered %v, want the invariant reported as an internal error", name, r)
} }
}() }()
call() call()
+21
View File
@@ -24,6 +24,27 @@ func TestNoFunctionSpellsAMethod(t *testing.T) {
} }
} }
func TestEveryPanicIsAnInternalError(t *testing.T) {
fset, files := sourceFiles(t)
for _, f := range files {
ast.Inspect(f, func(n ast.Node) bool {
call, isCall := n.(*ast.CallExpr)
if !isCall || !isIdent(call.Fun, "panic") {
return true
}
if arg, isArgCall := call.Args[0].(*ast.CallExpr); !isArgCall || !isIdent(arg.Fun, "internalError") {
t.Errorf("%s: panic with internalError(…), so every invariant break greps to one phrase", fset.Position(call.Pos()))
}
return true
})
}
}
func isIdent(e ast.Expr, name string) bool {
id, isID := e.(*ast.Ident)
return isID && id.Name == name
}
func namespaceFiles(t *testing.T) []*ast.File { func namespaceFiles(t *testing.T) []*ast.File {
t.Helper() t.Helper()
pkg := packageDir(t) pkg := packageDir(t)