Skip to content

Commit

Permalink
feat: add json printing to TestExtractStackTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Jan 30, 2024
1 parent 6a4b95f commit c889419
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions error_template_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package errgoengine_test

import (
"encoding/json"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -275,6 +276,11 @@ func TestExtractVariables(t *testing.T) {
})
}

func printStackTraceJson(stackTrace lib.TraceStack) {
b, _ := json.MarshalIndent(stackTrace, "", " ")
fmt.Println(string(b))
}

func TestExtractStackTrace(t *testing.T) {
tmp, err := setupTemplate(lib.ErrorTemplate{
Name: "A",
Expand All @@ -289,13 +295,13 @@ func TestExtractStackTrace(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
cd := lib.NewContextData(lib.NewEmptyStore(), "/home/user")
cd.Variables = map[string]string{
"stacktrace": "\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1",
"stacktrace": "\nin funcA at /home/user/main.py:123\nin main at /home/user/main.py:1",
}

stackTrace := tmp.ExtractStackTrace(cd)
exp := lib.TraceStack{
lib.StackTraceEntry{
SymbolName: "main",
SymbolName: "funcA",
Location: lib.Location{
DocumentPath: "/home/user/main.py",
StartPos: lib.Position{
Expand Down Expand Up @@ -328,6 +334,8 @@ func TestExtractStackTrace(t *testing.T) {
},
}

printStackTraceJson(exp)
printStackTraceJson(stackTrace)
if !reflect.DeepEqual(stackTrace, exp) {
t.Fatalf("expected %v, got %v", exp, stackTrace)
}
Expand All @@ -342,6 +350,8 @@ func TestExtractStackTrace(t *testing.T) {
stackTrace := tmp.ExtractStackTrace(cd)
exp := lib.TraceStack{}

printStackTraceJson(exp)
printStackTraceJson(stackTrace)
if !reflect.DeepEqual(stackTrace, exp) {
t.Fatalf("expected %v, got %v", exp, stackTrace)
}
Expand All @@ -356,6 +366,8 @@ func TestExtractStackTrace(t *testing.T) {
stackTrace := tmp.ExtractStackTrace(cd)
exp := lib.TraceStack{}

printStackTraceJson(exp)
printStackTraceJson(stackTrace)
if !reflect.DeepEqual(stackTrace, exp) {
t.Fatalf("expected %v, got %v", exp, stackTrace)
}
Expand Down Expand Up @@ -403,6 +415,8 @@ func TestExtractStackTrace(t *testing.T) {
},
}

printStackTraceJson(exp)
printStackTraceJson(stackTrace)
if !reflect.DeepEqual(stackTrace, exp) {
t.Fatalf("expected %v, got %v", exp, stackTrace)
}
Expand Down

0 comments on commit c889419

Please sign in to comment.