Skip to content
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

tests: add names to dump test cases #5

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5d5e38f
Fork to thockin, add go.mod
thockin Jul 15, 2022
ffcc4c1
Configure and fix golangci-lint issues
thockin Jul 17, 2022
9f324dd
Delete .gitignore
thockin Jul 17, 2022
9ecf520
Fixed typo
muesli Jul 20, 2019
3c6b832
Remove unused ptrSize
muesli Jul 20, 2019
7805001
Correct spelling: satisify -> satisfy
jubalh Nov 29, 2020
5ffd3c3
Add options to disable printing of type and length
kibra Nov 4, 2016
09a7901
Add config option TrailingCommas
atombender Nov 21, 2016
2c5279d
rm panic on config.SortKeys with unexported map with array key
reinerRubin Jul 17, 2019
b874067
Feat: add DisableUnexported
flw-cn Feb 4, 2020
fdc54e4
Feat: add test cases for DisableUnexported
flw-cn Jun 24, 2020
5768d39
Add a CleanConfig var
thockin Jul 16, 2022
d6dd5bc
Add cfg .DumpListSquareBraces
thockin Jul 17, 2022
5f85b10
Add cfg .AbbreviateEmpty for printing empty things
thockin Jul 16, 2022
0e26326
Print line-numbers of failing cases
thockin Jul 16, 2022
6211033
Add newline if needed in test output
thockin Jul 16, 2022
d844b60
tests: make stringizeWants output nicer
thockin Jul 16, 2022
56c30de
Add cfg .QuoteStrings to quote strings in Printf()
thockin Jul 17, 2022
bfb8f74
Add cfg .Commas to print ',' vs ' ' in Printf()
thockin Jul 17, 2022
d7e97f3
Add cfg .FuncSymbols to print function names
thockin Jul 17, 2022
e5e9ed9
Add GH actions
thockin Jul 17, 2022
d76f9ba
Auto-assign PRs and issues to me
thockin Jul 17, 2022
366baf1
---------- TODO -----------
thockin Jul 16, 2022
e7119c9
tests: add names to dump test cases
dwlnetnl May 16, 2023
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
21 changes: 21 additions & 0 deletions .github/workflows/assign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Assign

on:
issues:
types: [opened, reopened]
pull_request_target:
types: [opened, reopened]

jobs:
assign:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.addAssignees({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
assignees: ['thockin']
})
21 changes: 21 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run lint

on: [ push, pull_request ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Read args from .golangci.yaml
# args:
22 changes: 22 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run tests

on: [ push, pull_request ]

jobs:
test:
strategy:
matrix:
version: [ '1.15', '1.16', '1.17', '1.18' ]
platform: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Build
run: go build -v ./...
- name: Test
run: go test -v -race ./...
22 changes: 0 additions & 22 deletions .gitignore

This file was deleted.

28 changes: 28 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
run:
timeout: 1m
tests: true

linters:
disable-all: true
enable:
- asciicheck
- deadcode
- forcetypeassert
- gocritic
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- revive
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 10
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/thockin/go-spew

go 1.18
Empty file added go.sum
Empty file.
9 changes: 9 additions & 0 deletions spew/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
benchmark
optimize
- avoid reflect first
use `string` where possible in tests
comprehend tests
remove linewraps in tests
update docs
OmitNilValues
- if I have a `[]*Foo{&Foo{}, &Foo{}, nil}` - should still print nil
4 changes: 1 addition & 3 deletions spew/bypass.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// tag is deprecated and thus should not be used.
// Go versions prior to 1.4 are disabled because they use a different layout
// for interfaces which make the implementation of unsafeReflectValue more complex.
//go:build !js && !appengine && !safe && !disableunsafe && go1.4
// +build !js,!appengine,!safe,!disableunsafe,go1.4

package spew
Expand All @@ -31,9 +32,6 @@ const (
// UnsafeDisabled is a build-time constant which specifies whether or
// not access to the unsafe package is available.
UnsafeDisabled = false

// ptrSize is the size of a pointer on the current arch.
ptrSize = unsafe.Sizeof((*byte)(nil))
)

type flag uintptr
Expand Down
61 changes: 43 additions & 18 deletions spew/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ var (
trueBytes = []byte("true")
falseBytes = []byte("false")
interfaceBytes = []byte("(interface {})")
commaBytes = []byte(",")
commaNewlineBytes = []byte(",\n")
newlineBytes = []byte("\n")
openBraceBytes = []byte("{")
openBraceNewlineBytes = []byte("{\n")
closeBraceBytes = []byte("}")
emptyBracesBytes = []byte("{}")
openListNewlineBytes = []byte("[\n")
closeListBytes = []byte("]")
emptyListBytes = []byte("[]")
asteriskBytes = []byte("*")
colonBytes = []byte(":")
colonSpaceBytes = []byte(": ")
Expand Down Expand Up @@ -100,7 +105,7 @@ func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool)
// Choose whether or not to do error and Stringer interface lookups against
// the base type or a pointer to the base type depending on settings.
// Technically calling one of these methods with a pointer receiver can
// mutate the value, however, types which choose to satisify an error or
// mutate the value, however, types which choose to satisfy an error or
// Stringer interface with a pointer receiver should not be mutating their
// state inside these interface methods.
if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() {
Expand All @@ -114,27 +119,35 @@ func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool)
switch iface := v.Interface().(type) {
case error:
defer catchPanic(w, v)
s := iface.Error()
if cs.QuoteStrings {
s = strconv.Quote(s)
}
if cs.ContinueOnMethod {
w.Write(openParenBytes)
w.Write([]byte(iface.Error()))
w.Write([]byte(s))
w.Write(closeParenBytes)
w.Write(spaceBytes)
return false
}

w.Write([]byte(iface.Error()))
w.Write([]byte(s))
return true

case fmt.Stringer:
defer catchPanic(w, v)
s := iface.String()
if cs.QuoteStrings {
s = strconv.Quote(s)
}
if cs.ContinueOnMethod {
w.Write(openParenBytes)
w.Write([]byte(iface.String()))
w.Write([]byte(s))
w.Write(closeParenBytes)
w.Write(spaceBytes)
return false
}
w.Write([]byte(iface.String()))
w.Write([]byte(s))
return true
}
return false
Expand Down Expand Up @@ -254,7 +267,7 @@ func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface {
// directly, or whether it should be considered for sorting by surrogate keys
// (if the ConfigState allows it).
func canSortSimply(kind reflect.Kind) bool {
// This switch parallels valueSortLess, except for the default case.
// This switch parallels valueLessEqual, except for the default case.
switch kind {
case reflect.Bool:
return true
Expand Down Expand Up @@ -289,43 +302,55 @@ func (s *valuesSorter) Swap(i, j int) {
}
}

// valueSortLess returns whether the first value should sort before the second
// valueLessEqual returns whether the first value should sort before the second
// value. It is used by valueSorter.Less as part of the sort.Interface
// implementation.
func valueSortLess(a, b reflect.Value) bool {
func valueLessEqual(a, b reflect.Value) (less, equal bool) {
switch a.Kind() {
case reflect.Bool:
return !a.Bool() && b.Bool()
av, bv := a.Bool(), b.Bool()
return !av && bv, av == bv
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
return a.Int() < b.Int()
av, bv := a.Int(), b.Int()
return av < bv, av == bv
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
return a.Uint() < b.Uint()
av, bv := a.Uint(), b.Uint()
return av < bv, av == bv
case reflect.Float32, reflect.Float64:
return a.Float() < b.Float()
av, bv := a.Float(), b.Float()
return av < bv, av == bv
case reflect.String:
return a.String() < b.String()
av, bv := a.String(), b.String()
return av < bv, av == bv
case reflect.Uintptr:
return a.Uint() < b.Uint()
av, bv := a.Uint(), b.Uint()
return av < bv, av == bv
case reflect.Array:
// Compare the contents of both arrays.
l := a.Len()
for i := 0; i < l; i++ {
av := a.Index(i)
bv := b.Index(i)
if av.Interface() == bv.Interface() {

less, equal := valueLessEqual(av, bv)
if equal {
continue
}
return valueSortLess(av, bv)

return less, false
}
}
return a.String() < b.String()

av, bv := a.String(), b.String()
return av < bv, av == bv
}

// Less returns whether the value at index i should sort before the
// value at index j. It is part of the sort.Interface implementation.
func (s *valuesSorter) Less(i, j int) bool {
if s.strings == nil {
return valueSortLess(s.values[i], s.values[j])
less, _ := valueLessEqual(s.values[i], s.values[j])
return less
}
return s.strings[i] < s.strings[j]
}
Expand Down
Loading