Skip to content

Move all tests to ./tests/ with new Go module to isolate testing dependencies #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ jobs:
scheduled:
runs-on: ubuntu-latest
steps:
- name: Check out this repo
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with: {go-version: '^1.16'}
- name: Download dependencies
run: go mod download
- name: Build
run: go build ./...
- name: Test
run: go test ./...
- name: Check out this repo
uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with: { go-version: "^1.16" }
- name: Download dependencies
run: go mod download
- name: Build
run: go build ./...
- name: Test
working-directory: tests
run: go test ./...
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
module github.com/sanity-io/litter

go 1.16

require (
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b // indirect
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0 // indirect
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b h1:XxMZvQZtTXpWMNWK82vdjCLCe7uGMFXdTsJH0v3Hkvw=
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0 h1:GD+A8+e+wFkqje55/2fOVnZPkoDIu1VooBWfNrnY8Uo=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312 h1:UsFdQ3ZmlzS0BqZYGxvYaXvFGUbCmPGy8DM7qWJJiIQ=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
1 change: 0 additions & 1 deletion testdata/config_Compact.dump

This file was deleted.

3 changes: 0 additions & 3 deletions testdata/config_DisablePointerReplacement_circular.dump

This file was deleted.

15 changes: 0 additions & 15 deletions testdata/customDumper.dump

This file was deleted.

10 changes: 0 additions & 10 deletions testdata/nilIntefacesInStructs.dump

This file was deleted.

12 changes: 0 additions & 12 deletions testdata/pointerAliasing.dump

This file was deleted.

12 changes: 0 additions & 12 deletions testdata/recursive_maps.dump

This file was deleted.

5 changes: 0 additions & 5 deletions testdata/unexported.dump

This file was deleted.

20 changes: 10 additions & 10 deletions dump_test.go → tests/dump_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package litter_test
package tests_test

import (
"errors"
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestSdump_config(t *testing.T) {
Separator: " ",
}

data := []interface{}{
data := []any{
opts,
&BasicStruct{1, 2},
Function,
Expand All @@ -180,7 +180,7 @@ func TestSdump_config(t *testing.T) {
StripPackageNames: true,
}, data)
runTestWithCfg(t, "config_HomePackage", &litter.Options{
HomePackage: "litter_test",
HomePackage: "tests_test",
}, data)
runTestWithCfg(t, "config_FieldFilter", &litter.Options{
FieldFilter: func(f reflect.StructField, v reflect.Value) bool {
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestSdump_config(t *testing.T) {
basic := &BasicStruct{1, 2}
runTestWithCfg(t, "config_DisablePointerReplacement_simpleReusedStruct", &litter.Options{
DisablePointerReplacement: true,
}, []interface{}{basic, basic})
}, []any{basic, basic})
circular := &RecursiveStruct{}
circular.Ptr = circular
runTestWithCfg(t, "config_DisablePointerReplacement_circular", &litter.Options{
Expand All @@ -231,7 +231,7 @@ func TestSdump_multipleArgs(t *testing.T) {
}

func TestSdump_maps(t *testing.T) {
runTests(t, "maps", []interface{}{
runTests(t, "maps", []any{
map[string]string{
"hello": "there",
"something": "something something",
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestSdump_unexported(t *testing.T) {

var standardCfg = litter.Options{}

func runTestWithCfg(t *testing.T, name string, cfg *litter.Options, cases ...interface{}) {
func runTestWithCfg(t *testing.T, name string, cfg *litter.Options, cases ...any) {
t.Run(name, func(t *testing.T) {
fileName := fmt.Sprintf("testdata/%s.dump", name)

Expand All @@ -298,10 +298,6 @@ func runTestWithCfg(t *testing.T, name string, cfg *litter.Options, cases ...int
})
}

func runTests(t *testing.T, name string, cases ...interface{}) {
runTestWithCfg(t, name, &standardCfg, cases...)
}

func diffStrings(t *testing.T, expected, actual string) (*string, bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, it was very intentional to use diff here. assert.Equal() produces super unreadable unified diffs. If you want different output, I'd be fine with an environment variable to control it (defaulting to diff).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted, fwiw the pure go diff is a lot faster

if actual == expected {
return nil, true
Expand Down Expand Up @@ -354,3 +350,7 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string {
}
return ""
}

func runTests(t *testing.T, name string, cases ...any) {
runTestWithCfg(t, name, &standardCfg, cases...)
}
16 changes: 16 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/sanity-io/litter/tests

go 1.24.2

require (
github.com/sanity-io/litter v1.5.8
github.com/stretchr/testify v1.10.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/sanity-io/litter => ..
10 changes: 10 additions & 0 deletions tests/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1 change: 1 addition & 0 deletions tests/testdata/config_Compact.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]interface{}{tests_test.options{Compact:false,StripPackageNames:false,HidePrivateFields:true,HomePackage:"",Separator:" ",StrictGo:false},&tests_test.BasicStruct{Public:1,private:2},tests_test.Function,&20,&20,litter.Dump,func(string,int)(bool,error),time.Time{wall:0,ext:63650361600,loc:nil}}
3 changes: 3 additions & 0 deletions tests/testdata/config_DisablePointerReplacement_circular.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&tests_test.RecursiveStruct{ // p0
Ptr: p0,
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[]interface {}{
&litter_test.BasicStruct{ // p0
&tests_test.BasicStruct{ // p0
Public: 1,
private: 2,
},
&litter_test.BasicStruct{ // p0
&tests_test.BasicStruct{ // p0
Public: 1,
private: 2,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[]interface {}{
litter_test.options{
tests_test.options{
Compact: bool"off",
StripPackageNames: bool"off",
HidePrivateFields: bool"on",
HomePackage: "",
Separator: " ",
StrictGo: bool"off",
},
&litter_test.BasicStruct{
&tests_test.BasicStruct{
Public: 1,
private: 2,
},
litter_test.Function,
tests_test.Function,
&20,
&20,
litter.Dump,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[]interface {}{
litter_test.options{
tests_test.options{
HomePackage: "",
Separator: " ",
},
&litter_test.BasicStruct{},
litter_test.Function,
&tests_test.BasicStruct{},
tests_test.Function,
&20,
&20,
litter.Dump,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[]interface {}{
litter_test.options{
tests_test.options{
Compact: false,
StripPackageNames: false,
HidePrivateFields: true,
HomePackage: "",
Separator: " ",
StrictGo: false,
},
&litter_test.BasicStruct{
&tests_test.BasicStruct{
Public: 1,
private: 2,
},
litter_test.Function,
tests_test.Function,
&20,
&20,
litter.Dump,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[]interface {}{
litter_test.options{
tests_test.options{
Compact: false,
StripPackageNames: false,
HidePrivateFields: true,
HomePackage: "",
Separator: " ",
StrictGo: false,
},
&litter_test.BasicStruct{
&tests_test.BasicStruct{
Public: 1,
},
litter_test.Function,
tests_test.Function,
&20,
&20,
litter.Dump,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[]interface {}{
litter_test.options{
tests_test.options{
HidePrivateFields: true,
Separator: " ",
},
&litter_test.BasicStruct{
&tests_test.BasicStruct{
Public: 1,
private: 2,
},
litter_test.Function,
tests_test.Function,
&20,
&20,
litter.Dump,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[]interface {}{
litter_test.options{
tests_test.options{
Compact: false,
StripPackageNames: false,
HidePrivateFields: true,
HomePackage: "",
Separator: " ",
StrictGo: false,
},
(func(v litter_test.BasicStruct) *litter_test.BasicStruct { return &v })(litter_test.BasicStruct{
(func(v tests_test.BasicStruct) *tests_test.BasicStruct { return &v })(tests_test.BasicStruct{
Public: 1,
private: 2,
}),
litter_test.Function,
tests_test.Function,
(func(v int) *int { return &v })(20),
(func(v litter_test.IntAlias) *litter_test.IntAlias { return &v })(20),
(func(v tests_test.IntAlias) *tests_test.IntAlias { return &v })(20),
litter.Dump,
func(string, int) (bool, error),
time.Time{
Expand Down
15 changes: 15 additions & 0 deletions tests/testdata/customDumper.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
map[string]interface {}{
"v1": *tests_test.CustomMultiLineDumper{ // p0
multi
line
},
"v2": p0,
"v2x": *tests_test.CustomMultiLineDumper{
multi
line
},
"v3": tests_test.CustomSingleLineDumper<custom>,
"v4": *tests_test.CustomSingleLineDumper<custom>, // p1
"v5": p1,
"v6": *tests_test.CustomSingleLineDumper<custom>,
}
4 changes: 2 additions & 2 deletions testdata/maps.dump → tests/testdata/maps.dump
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
2: "two",
3: "three",
},
map[int]*litter_test.BlankStruct{
2: &litter_test.BlankStruct{},
map[int]*tests_test.BlankStruct{
2: &tests_test.BlankStruct{},
},
}
10 changes: 10 additions & 0 deletions tests/testdata/nilIntefacesInStructs.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[]*tests_test.InterfaceStruct{
&tests_test.InterfaceStruct{ // p0
Ifc: nil,
},
&tests_test.InterfaceStruct{
Ifc: p0,
},
p0,
nil,
}
Loading