docs: add godoc and bilingual README

This commit is contained in:
2026-03-17 15:33:11 +03:00
parent 6112a707c7
commit badee2c598
10 changed files with 541 additions and 54 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"os"
"strings"
"testing"
)
@@ -153,6 +154,42 @@ func TestCreateJsonStdoutWriterDoesNotCloseStdout(t *testing.T) {
}
}
func TestGetFullTracebackSkipsRuntimeAndSlogFrames(t *testing.T) {
tracebacks := captureTracebackForTest()
if len(tracebacks) == 0 {
t.Fatal("expected at least one traceback frame")
}
first := tracebacks[0]
if first.Method != "captureTracebackForTest" {
t.Fatalf("first frame should be the nearest user frame, got %s", first.Method)
}
for _, tb := range tracebacks {
if strings.HasPrefix(tb.Signature, "runtime.") {
t.Fatalf("runtime frame should be filtered out, got %s", tb.Signature)
}
if _, ok := internalTracebackMethods[tb.Method]; ok {
t.Fatalf("internal slog frame should be filtered out, got %s", tb.Signature)
}
}
}
func TestGetTracebackReturnsNearestUserFrame(t *testing.T) {
tb := captureSingleTracebackForTest()
if tb == nil {
t.Fatal("expected traceback frame")
}
if tb.Method != "captureSingleTracebackForTest" {
t.Fatalf("expected nearest user frame, got %s", tb.Method)
}
if strings.HasPrefix(tb.Signature, "runtime.") {
t.Fatalf("runtime frame should be filtered out, got %s", tb.Signature)
}
if _, ok := internalTracebackMethods[tb.Method]; ok {
t.Fatalf("internal slog frame should be filtered out, got %s", tb.Signature)
}
}
func swapStdout(t *testing.T) *os.File {
t.Helper()
@@ -168,3 +205,11 @@ func swapStdout(t *testing.T) *os.File {
})
return stdoutFile
}
func captureTracebackForTest() []*MethodTraceback {
return getFullTraceback(0)
}
func captureSingleTracebackForTest() *MethodTraceback {
return getTraceback()
}