Approval-based snapshot testing library for Go (mirror)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add utter for pretty printing

+84 -55
+21
LICENSE
··· 1 + MIT License 2 + 3 + Copyright (c) 2025 Patrick Dewey 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy 6 + of this software and associated documentation files (the "Software"), to deal 7 + in the Software without restriction, including without limitation the rights 8 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + copies of the Software, and to permit persons to whom the Software is 10 + furnished to do so, subject to the following conditions: 11 + 12 + The above copyright notice and this permission notice shall be included in all 13 + copies or substantial portions of the Software. 14 + 15 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + SOFTWARE.
-5
__snapshots__/test_map.snap
··· 1 - --- 2 - version: 0.1.0 3 - test_name: TestMap 4 - --- 5 - map[string]interface {}{"foo":"bar"}
+7
__snapshots__/test_map.snap.new
··· 1 + --- 2 + version: 0.1.0 3 + test_name: TestMap 4 + --- 5 + map[string]interface{}{ 6 + string("foo"): string("bar"), 7 + }
-5
__snapshots__/test_snap_custom_type.snap
··· 1 - --- 2 - version: 0.1.0 3 - test_name: TestSnapCustomType 4 - --- 5 - CustomStruct{Name: Alice, Age: }
+8
__snapshots__/test_snap_custom_type.snap.new
··· 1 + --- 2 + version: 0.1.0 3 + test_name: TestSnapCustomType 4 + --- 5 + freeze_test.CustomStruct{ 6 + Name: string("Alice"), 7 + Age: int(30), 8 + }
-13
__snapshots__/test_snap_multiple.snap
··· 1 - --- 2 - version: 0.1.0 3 - test_name: TestSnapMultiple 4 - --- 5 - value1 6 - value2 7 - 42 8 - foo 9 - bar 10 - baz 11 - wibble 12 - wobble 13 - tock
+21
__snapshots__/test_snap_multiple.snap.new
··· 1 + --- 2 + version: 0.1.0 3 + test_name: TestSnapMultiple 4 + --- 5 + string("value1") 6 + 7 + string("value2") 8 + 9 + int(42) 10 + 11 + string("foo") 12 + 13 + string("bar") 14 + 15 + string("baz") 16 + 17 + string("wibble") 18 + 19 + string("wobble") 20 + 21 + string("tock")
__snapshots__/test_snap_string.snap __snapshots__/test_snap_string.snap.new
+20 -19
freeze.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - "reflect" 6 5 6 + "github.com/kortschak/utter" 7 7 "github.com/ptdewey/freeze/internal/diff" 8 8 "github.com/ptdewey/freeze/internal/files" 9 9 "github.com/ptdewey/freeze/internal/pretty" ··· 106 106 return "<nil>" 107 107 } 108 108 109 - if formattable, ok := v.(interface{ Format() string }); ok { 110 - return formattable.Format() 111 - } 112 - 113 - if stringer, ok := v.(interface{ String() string }); ok { 114 - return stringer.String() 115 - } 116 - 117 - val := reflect.ValueOf(v) 118 - switch val.Kind() { 119 - case reflect.String: 120 - return v.(string) 121 - case reflect.Struct, reflect.Slice, reflect.Array, reflect.Map: 122 - // TODO: make this better probably (utter?) 123 - return fmt.Sprintf("%#v", v) 124 - default: 125 - return fmt.Sprint(v) 126 - } 109 + // if formattable, ok := v.(interface{ Format() string }); ok { 110 + // return formattable.Format() 111 + // } 112 + // 113 + // if stringer, ok := v.(interface{ String() string }); ok { 114 + // return stringer.String() 115 + // } 116 + // 117 + // val := reflect.ValueOf(v) 118 + // switch val.Kind() { 119 + // case reflect.String: 120 + // return v.(string) 121 + // case reflect.Struct, reflect.Slice, reflect.Array, reflect.Map: 122 + // // TODO: make this better probably (utter?) 123 + // return fmt.Sprintf("%#v", v) 124 + // default: 125 + // return fmt.Sprint(v) 126 + // } 127 + return utter.Sdump(v) 127 128 }
+2
go.mod
··· 1 1 module github.com/ptdewey/freeze 2 2 3 3 go 1.25.2 4 + 5 + require github.com/kortschak/utter v1.7.0 // indirect
+2
go.sum
··· 1 + github.com/kortschak/utter v1.7.0 h1:6NKMynvGUyqfeMTawfah4zyInlrgwzjkDAHrT+skx/w= 2 + github.com/kortschak/utter v1.7.0/go.mod h1:vSmSjbyrlKjjsL71193LmzBOKgwePk9DH6uFaWHIInc=
+2
justfile
··· 5 5 test: 6 6 @go test ./... -cover -coverprofile=cover.out 7 7 8 + run: 9 + @go run cmd/freeze/main.go 8 10 9 11 clean: 10 12 @rm -rf ./__snapshots__
+1 -13
review.go
··· 20 20 AcceptAllChoice 21 21 RejectAllChoice 22 22 SkipAllChoice 23 - // ToggleDiff 24 23 Quit 25 24 ) 26 25 ··· 48 47 return nil 49 48 } 50 49 51 - fmt.Println(pretty.Header("🐦 Freeze - Snapshot Review")) 50 + fmt.Println(pretty.Header("Review Snapshots")) 52 51 fmt.Printf("Found %d new snapshot(s) to review\n\n", len(snapshots)) 53 52 54 53 return reviewLoop(snapshots) ··· 119 118 case SkipAllChoice: 120 119 fmt.Printf(pretty.Warning("⊘ Skipped %d snapshot(s)\n"), len(snapshots)-i) 121 120 return nil 122 - // case ToggleDiff: 123 - // showDiff = !showDiff 124 - // if acceptErr == nil { 125 - // diffLines := computeDiffLines(accepted, newSnap) 126 - // fmt.Println(pretty.DiffSnapshotBox(accepted, newSnap, diffLines)) 127 - // } else { 128 - // fmt.Println(pretty.NewSnapshotBox(newSnap)) 129 - // } 130 - // continue 131 121 case Quit: 132 122 fmt.Println("\nReview interrupted") 133 123 return nil ··· 163 153 return RejectAllChoice, nil 164 154 case "S", "Skip All": 165 155 return SkipAllChoice, nil 166 - // case "d", "diff": 167 - // return ToggleDiff, nil 168 156 case "q", "quit": 169 157 return Quit, nil 170 158 default: