mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-06 22:57:37 +03:00
Add unit tests for sources.go
Tests cover most of the cache and download related code paths and specify the expected result of various starting states and external failure modes. Where the current code's behaviour doesn't match a test's expectations, the test is disabled and annotated with a TODO until it can be fixed. Added dependency on `github.com/powerman/check` and ran `go mod vendor`.
This commit is contained in:
parent
503bfb877b
commit
af0629856c
61 changed files with 7200 additions and 0 deletions
333
vendor/github.com/powerman/check/.golangci.yml
generated
vendored
Normal file
333
vendor/github.com/powerman/check/.golangci.yml
generated
vendored
Normal file
|
@ -0,0 +1,333 @@
|
|||
# This file contains all available configuration options
|
||||
# with their default values.
|
||||
|
||||
# options for analysis running
|
||||
run:
|
||||
# default concurrency is a available CPU number
|
||||
# concurrency: 4
|
||||
|
||||
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||
# timeout: 1m
|
||||
|
||||
# exit code when at least one issue was found, default is 1
|
||||
# issues-exit-code: 1
|
||||
|
||||
# include test files or not, default is true
|
||||
# tests: true
|
||||
|
||||
# list of build tags, all linters use it. Default is empty list.
|
||||
build-tags:
|
||||
- integration
|
||||
|
||||
# which dirs to skip: they won't be analyzed;
|
||||
# can use regexp here: generated.*, regexp is applied on full path;
|
||||
# default value is empty list, but next dirs are always skipped independently
|
||||
# from this option's value:
|
||||
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||
# skip-dirs:
|
||||
# - src/external_libs
|
||||
# - autogenerated_by_my_lib
|
||||
|
||||
# which files to skip: they will be analyzed, but issues from them
|
||||
# won't be reported. Default value is empty list, but there is
|
||||
# no need to include all autogenerated files, we confidently recognize
|
||||
# autogenerated files. If it's not please let us know.
|
||||
# skip-files:
|
||||
# - "\\.\\w+\\.go$"
|
||||
|
||||
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
|
||||
# If invoked with -mod=readonly, the go command is disallowed from the implicit
|
||||
# automatic updating of go.mod described above. Instead, it fails when any changes
|
||||
# to go.mod are needed. This setting is most useful to check that go.mod does
|
||||
# not need updates, such as in a continuous integration and testing system.
|
||||
# If invoked with -mod=vendor, the go command assumes that the vendor
|
||||
# directory holds the correct copies of dependencies and ignores
|
||||
# the dependency descriptions in go.mod.
|
||||
modules-download-mode: readonly
|
||||
|
||||
|
||||
# output configuration options
|
||||
output:
|
||||
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
|
||||
# format: colored-line-number
|
||||
|
||||
# print lines of code with issue, default is true
|
||||
# print-issued-lines: true
|
||||
|
||||
# print linter name in the end of issue text, default is true
|
||||
# print-linter-name: true
|
||||
|
||||
|
||||
# all available settings of specific linters
|
||||
linters-settings:
|
||||
errcheck:
|
||||
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
# check-type-assertions: false
|
||||
|
||||
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
# check-blank: false
|
||||
|
||||
# [deprecated] comma-separated list of pairs of the form pkg:regex
|
||||
# the regex is used to ignore names within pkg. (default "fmt:.*").
|
||||
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
|
||||
# ignore: fmt:.*,io/ioutil:^Read.*
|
||||
|
||||
# path to a file containing a list of functions to exclude from checking
|
||||
# see https://github.com/kisielk/errcheck#excluding-functions for details
|
||||
# exclude: .errcheck.excludes
|
||||
|
||||
funlen:
|
||||
lines: 60
|
||||
statements: 40
|
||||
|
||||
govet:
|
||||
# report about shadowed variables
|
||||
check-shadowing: true
|
||||
|
||||
# settings per analyzer
|
||||
settings:
|
||||
printf: # analyzer name, run `go tool vet help` to see all analyzers
|
||||
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
|
||||
# - (github.com/powerman/structlog.Logger).Fatalf
|
||||
# - (github.com/powerman/structlog.Logger).Panicf
|
||||
# - (github.com/powerman/structlog.Logger).Printf
|
||||
|
||||
# enable or disable analyzers by name
|
||||
# enable:
|
||||
# - atomicalign
|
||||
enable-all: true
|
||||
# disable:
|
||||
# - shadow
|
||||
# disable-all: false
|
||||
golint:
|
||||
# minimal confidence for issues, default is 0.8
|
||||
# min-confidence: 0.8
|
||||
gofmt:
|
||||
# simplify code: gofmt with `-s` option, true by default
|
||||
# simplify: true
|
||||
goimports:
|
||||
# put imports beginning with prefix after 3rd-party packages;
|
||||
# it's a comma-separated list of prefixes
|
||||
# local-prefixes: github.com/powerman
|
||||
gocyclo:
|
||||
# minimal code complexity to report, 30 by default (but we recommend 10-20)
|
||||
min-complexity: 15
|
||||
gocognit:
|
||||
# minimal code complexity to report, 30 by default (but we recommend 10-20)
|
||||
min-complexity: 20
|
||||
maligned:
|
||||
# print struct with more effective memory layout or not, false by default
|
||||
suggest-new: true
|
||||
dupl:
|
||||
# tokens count to trigger issue, 150 by default
|
||||
threshold: 100
|
||||
goconst:
|
||||
# minimal length of string constant, 3 by default
|
||||
# min-len: 3
|
||||
# minimal occurrences count to trigger, 3 by default
|
||||
# min-occurrences: 3
|
||||
depguard:
|
||||
list-type: blacklist
|
||||
include-go-root: true
|
||||
packages:
|
||||
- log
|
||||
packages-with-error-messages:
|
||||
# specify an error message to output when a blacklisted package is used
|
||||
log: "logging is allowed only by github.com/powerman/structlog"
|
||||
misspell:
|
||||
# Correct spellings using locale preferences for US or UK.
|
||||
# Default is to use a neutral variety of English.
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
# locale: US
|
||||
# ignore-words:
|
||||
# - someword
|
||||
lll:
|
||||
# max line length, lines longer will be reported. Default is 120.
|
||||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||
# line-length: 120
|
||||
# tab width in spaces. Default to 1.
|
||||
# tab-width: 1
|
||||
unused:
|
||||
# treat code as a program (not a library) and report unused exported identifiers; default is false.
|
||||
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
|
||||
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
|
||||
# with golangci-lint call it on a directory with the changed file.
|
||||
# check-exported: false
|
||||
unparam:
|
||||
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
|
||||
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
|
||||
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
|
||||
# with golangci-lint call it on a directory with the changed file.
|
||||
# check-exported: false
|
||||
nakedret:
|
||||
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
|
||||
# max-func-lines: 30
|
||||
prealloc:
|
||||
# XXX: we don't recommend using this linter before doing performance profiling.
|
||||
# For most programs usage of prealloc will be a premature optimization.
|
||||
|
||||
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
|
||||
# True by default.
|
||||
# simple: true
|
||||
# range-loops: true # Report preallocation suggestions on range loops, true by default
|
||||
# for-loops: false # Report preallocation suggestions on for loops, false by default
|
||||
gocritic:
|
||||
# Which checks should be enabled; can't be combined with 'disabled-checks';
|
||||
# See https://go-critic.github.io/overview#checks-overview
|
||||
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
|
||||
# By default list of stable checks is used.
|
||||
# enabled-checks:
|
||||
# - rangeValCopy
|
||||
|
||||
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
|
||||
disabled-checks:
|
||||
- hugeParam # premature optimization
|
||||
- paramTypeCombine # questionable
|
||||
- ptrToRefParam
|
||||
- typeUnparen # false positive
|
||||
- yodaStyleExpr # questionable
|
||||
|
||||
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
|
||||
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
|
||||
enabled-tags:
|
||||
- diagnostic
|
||||
- style
|
||||
- performance
|
||||
- experimental
|
||||
- opinionated
|
||||
|
||||
settings: # settings passed to gocritic
|
||||
captLocal: # must be valid enabled check name
|
||||
paramsOnly: true
|
||||
rangeValCopy:
|
||||
sizeThreshold: 32
|
||||
godox:
|
||||
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
|
||||
# might be left in the code accidentally and should be resolved before merging
|
||||
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
|
||||
- BUG # marks issues that should be moved to issue tracker before merging
|
||||
- FIXME # marks issues that should be resolved before merging
|
||||
dogsled:
|
||||
# checks assignments with too many blank identifiers; default is 2
|
||||
max-blank-identifiers: 2
|
||||
|
||||
whitespace:
|
||||
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
|
||||
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
|
||||
wsl:
|
||||
# If true append is only allowed to be cuddled if appending value is
|
||||
# matching variables, fields or types on line above. Default is true.
|
||||
strict-append: true
|
||||
# Allow calls and assignments to be cuddled as long as the lines have any
|
||||
# matching variables, fields or types. Default is true.
|
||||
allow-assign-and-call: true
|
||||
# Allow multiline assignments to be cuddled. Default is true.
|
||||
allow-multiline-assign: true
|
||||
|
||||
linters:
|
||||
# enable:
|
||||
# - megacheck
|
||||
# - govet
|
||||
enable-all: true
|
||||
disable:
|
||||
- dogsled # questionable
|
||||
- dupl
|
||||
- gochecknoglobals
|
||||
- gochecknoinits
|
||||
- lll
|
||||
# - misspell
|
||||
- prealloc
|
||||
- wsl # questionable
|
||||
# disable-all: false
|
||||
# presets:
|
||||
# - bugs
|
||||
# - unused
|
||||
fast: false
|
||||
|
||||
|
||||
issues:
|
||||
# List of regexps of issue texts to exclude, empty list by default.
|
||||
# But independently from this option we use default exclude patterns,
|
||||
# it can be disabled by `exclude-use-default: false`. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`
|
||||
exclude:
|
||||
- "declaration of \"(log|err|ctx)\" shadows"
|
||||
- "Potential file inclusion via variable" # [DEFAULT] gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
|
||||
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
exclude-rules:
|
||||
# Exclude some linters from running on tests files.
|
||||
- path: _test\.go|testing\.go
|
||||
linters:
|
||||
- bodyclose
|
||||
- dupl
|
||||
- errcheck
|
||||
- funlen
|
||||
- gochecknoglobals
|
||||
- gochecknoinits
|
||||
- gocyclo
|
||||
- gosec
|
||||
- maligned
|
||||
- scopelint
|
||||
|
||||
# Ease some gocritic warnings on test files.
|
||||
- path: _test\.go|testing\.go
|
||||
text: "(unnamedResult|exitAfterDefer|rangeValCopy|commentedOutCode)"
|
||||
linters:
|
||||
- gocritic
|
||||
|
||||
# Package def is designed to contain global constants.
|
||||
- path: internal/def/
|
||||
linters:
|
||||
- gochecknoglobals
|
||||
|
||||
# Commands are allowed to contain a lot of flags.
|
||||
- path: main.go
|
||||
text: Function '(init|main)'
|
||||
linters:
|
||||
- funlen
|
||||
|
||||
# Exclude known linters from partially hard-vendored code,
|
||||
# which is impossible to exclude via "nolint" comments.
|
||||
# - path: internal/hmac/
|
||||
# text: "weak cryptographic primitive"
|
||||
# linters:
|
||||
# - gosec
|
||||
|
||||
# Exclude some staticcheck messages
|
||||
# - linters:
|
||||
# - staticcheck
|
||||
# text: "SA9003:"
|
||||
|
||||
# Exclude lll issues for long lines with go:generate
|
||||
# - linters:
|
||||
# - lll
|
||||
# source: "^//go:generate "
|
||||
|
||||
# Independently from option `exclude` we use default exclude patterns,
|
||||
# it can be disabled by this option. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`.
|
||||
# Default value for this option is true.
|
||||
exclude-use-default: false
|
||||
|
||||
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||
max-issues-per-linter: 0
|
||||
|
||||
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
|
||||
max-same-issues: 0
|
||||
|
||||
# Show only new issues: if there are unstaged changes or untracked files,
|
||||
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
|
||||
# It's a super-useful option for integration of golangci-lint into existing
|
||||
# large codebase. It's not practical to fix all existing issues at the moment
|
||||
# of integration: much better don't allow issues in new code.
|
||||
# Default is false.
|
||||
# new: false
|
||||
|
||||
# Show only new issues created after git revision `REV`
|
||||
# new-from-rev: REV
|
||||
|
||||
# Show only new issues created in git patch with set file path.
|
||||
# new-from-patch: path/to/patch/file
|
21
vendor/github.com/powerman/check/LICENSE
generated
vendored
Normal file
21
vendor/github.com/powerman/check/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 Alex Efros
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
72
vendor/github.com/powerman/check/README.md
generated
vendored
Normal file
72
vendor/github.com/powerman/check/README.md
generated
vendored
Normal file
|
@ -0,0 +1,72 @@
|
|||
# check [](http://godoc.org/github.com/powerman/check) [](https://goreportcard.com/report/github.com/powerman/check) [](https://circleci.com/gh/powerman/check) [](https://coveralls.io/github/powerman/check?branch=master)
|
||||
|
||||
Helpers to complement Go [testing](https://golang.org/pkg/testing/)
|
||||
package.
|
||||
|
||||
Write tests with ease and fun!
|
||||
|
||||
This package is like
|
||||
[testify/assert](https://godoc.org/github.com/test-go/testify/assert)
|
||||
on steroids. :)
|
||||
|
||||
## Features
|
||||
|
||||
- Compelling output from failed tests:
|
||||
- Very easy-to-read dumps for expected and actual values.
|
||||
- Same text diff you loved in testify/assert.
|
||||
- Also visual diff in [GoConvey](http://goconvey.co/) web UI, if you
|
||||
use it (recommended).
|
||||
- Statistics with amount of passed/failed checks.
|
||||
- Colored output in terminal.
|
||||
- 100% compatible with testing package - check package just provide
|
||||
convenient wrappers for `*testing.T` methods and doesn't introduce new
|
||||
concepts like BDD, custom test suite or unusual execution flow.
|
||||
- All checks you may ever need! :)
|
||||
- Very easy to add your own check functions.
|
||||
- Concise, handy and consistent API, without dot-import!
|
||||
|
||||
## Quickstart
|
||||
|
||||
Just wrap each (including subtests) `*testing.T` using `check.T()` and write
|
||||
tests as usually with testing package. Call new methods provided by this
|
||||
package to have more clean/concise test code and cool dump/diff.
|
||||
|
||||
```go
|
||||
import "github.com/powerman/check"
|
||||
|
||||
func TestSomething(tt *testing.T) {
|
||||
t := check.T(tt)
|
||||
t.Equal(2, 2)
|
||||
t.Log("You can use new t just like usual *testing.T")
|
||||
t.Run("Subtests/Parallel example", func(tt *testing.T) {
|
||||
t := check.T(tt)
|
||||
t.Parallel()
|
||||
t.NotEqual(2, 3, "should not be 3!")
|
||||
obj, err := NewObj()
|
||||
if t.Nil(err) {
|
||||
t.Match(obj.field, `^\d+$`)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
To get optional statistics about executed checkers add:
|
||||
|
||||
```go
|
||||
func TestMain(m *testing.M) { check.TestMain(m) }
|
||||
```
|
||||
|
||||
When use goconvey tool, to get nice diff in web UI
|
||||
[add](https://github.com/smartystreets/goconvey/issues/513):
|
||||
|
||||
```go
|
||||
import _ "github.com/smartystreets/goconvey/convey"
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
Require [Go 1.9](https://golang.org/doc/go1.9#test-helper).
|
||||
|
||||
```
|
||||
go get github.com/powerman/check
|
||||
```
|
1274
vendor/github.com/powerman/check/check.go
generated
vendored
Normal file
1274
vendor/github.com/powerman/check/check.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
39
vendor/github.com/powerman/check/color.go
generated
vendored
Normal file
39
vendor/github.com/powerman/check/color.go
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
package check
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ansiGreen = "\033[32m"
|
||||
ansiYellow = "\033[33m"
|
||||
ansiRed = "\033[31m"
|
||||
ansiReset = "\033[0m"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if !wantColor() {
|
||||
ansiGreen, ansiYellow, ansiRed, ansiReset = "", "", "", ""
|
||||
}
|
||||
}
|
||||
|
||||
func wantColor() bool {
|
||||
return strings.Contains(os.Getenv("TERM"), "color") &&
|
||||
(isTerminal() || os.Getenv("GO_TEST_COLOR") != "")
|
||||
}
|
||||
|
||||
func colouredDiff(diff string) string {
|
||||
lines := strings.SplitAfter(diff, "\n")
|
||||
for i := range lines {
|
||||
switch {
|
||||
case strings.HasPrefix(lines[i], "--- "):
|
||||
case strings.HasPrefix(lines[i], "+++ "):
|
||||
case strings.HasPrefix(lines[i], "-"):
|
||||
lines[i] = ansiGreen + lines[i] + ansiReset
|
||||
case strings.HasPrefix(lines[i], "+"):
|
||||
lines[i] = ansiRed + lines[i] + ansiReset
|
||||
}
|
||||
}
|
||||
return strings.Join(lines, "")
|
||||
}
|
14
vendor/github.com/powerman/check/color_bsd.go
generated
vendored
Normal file
14
vendor/github.com/powerman/check/color_bsd.go
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
// +build darwin dragonfly freebsd netbsd openbsd
|
||||
|
||||
package check
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func isTerminal() bool {
|
||||
_, err := unix.IoctlGetTermios(int(os.Stdout.Fd()), unix.TIOCGETA)
|
||||
return err == nil
|
||||
}
|
14
vendor/github.com/powerman/check/color_linux.go
generated
vendored
Normal file
14
vendor/github.com/powerman/check/color_linux.go
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
// +build linux
|
||||
|
||||
package check
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func isTerminal() bool {
|
||||
_, err := unix.IoctlGetTermios(int(os.Stdout.Fd()), unix.TCGETS)
|
||||
return err == nil
|
||||
}
|
7
vendor/github.com/powerman/check/color_other.go
generated
vendored
Normal file
7
vendor/github.com/powerman/check/color_other.go
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!windows
|
||||
|
||||
package check
|
||||
|
||||
func isTerminal() bool {
|
||||
return false
|
||||
}
|
14
vendor/github.com/powerman/check/color_windows.go
generated
vendored
Normal file
14
vendor/github.com/powerman/check/color_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
// +build windows
|
||||
|
||||
package check
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func isTerminal() bool {
|
||||
var mode uint32
|
||||
err := syscall.GetConsoleMode(syscall.Handle(os.Stdout.Fd()), &mode)
|
||||
return err == nil
|
||||
}
|
150
vendor/github.com/powerman/check/doc.go
generated
vendored
Normal file
150
vendor/github.com/powerman/check/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,150 @@
|
|||
// Package check provide helpers to complement Go testing package.
|
||||
//
|
||||
// Features
|
||||
//
|
||||
// This package is like testify/assert on steroids. :)
|
||||
//
|
||||
// - Compelling output from failed tests:
|
||||
// - Very easy-to-read dumps for expected and actual values.
|
||||
// - Same text diff you loved in testify/assert.
|
||||
// - Also visual diff in GoConvey web UI, if you use it (recommended).
|
||||
// - Statistics with amount of passed/failed checks.
|
||||
// - Colored output in terminal.
|
||||
// - 100% compatible with testing package - check package just provide
|
||||
// convenient wrappers for *testing.T methods and doesn't introduce
|
||||
// new concepts like BDD, custom test suite or unusual execution flow.
|
||||
// - All checks you may ever need! :)
|
||||
// - Very easy to add your own check functions.
|
||||
// - Concise, handy and consistent API, without dot-import!
|
||||
//
|
||||
// Quickstart
|
||||
//
|
||||
// Just wrap each (including subtests) *testing.T using check.T() and write
|
||||
// tests as usually with testing package. Call new methods provided by
|
||||
// this package to have more clean/concise test code and cool dump/diff.
|
||||
//
|
||||
// import "github.com/powerman/check"
|
||||
//
|
||||
// func TestSomething(tt *testing.T) {
|
||||
// t := check.T(tt)
|
||||
// t.Equal(2, 2)
|
||||
// t.Log("You can use new t just like usual *testing.T")
|
||||
// t.Run("Subtests/Parallel example", func(tt *testing.T) {
|
||||
// t := check.T(tt)
|
||||
// t.Parallel()
|
||||
// t.NotEqual(2, 3, "should not be 3!")
|
||||
// obj, err := NewObj()
|
||||
// if t.Nil(err) {
|
||||
// t.Match(obj.field, `^\d+$`)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// To get optional statistics about executed checkers add:
|
||||
//
|
||||
// func TestMain(m *testing.M) { check.TestMain(m) }
|
||||
//
|
||||
// When use goconvey tool, to get nice diff in web UI add:
|
||||
//
|
||||
// import _ "github.com/smartystreets/goconvey/convey"
|
||||
//
|
||||
// Hints
|
||||
//
|
||||
// ★ How to check for errors:
|
||||
//
|
||||
// // If you just want nil:
|
||||
// t.Nil(err)
|
||||
// t.Err(err, nil)
|
||||
//
|
||||
// // Check for (absence of) concrete (possibly wrapped) error:
|
||||
// t.Err(err, io.EOF)
|
||||
// t.NotErr(err, io.EOF) // nil is not io.EOF, so it's ok too
|
||||
//
|
||||
// // When need to match by error's text:
|
||||
// t.Match(err, "file.*permission")
|
||||
//
|
||||
// // Use Equal ONLY when checking for same instance:
|
||||
// t.Equal(io.EOF, io.EOF) // this works
|
||||
// t.Equal(io.EOF, errors.New("EOF")) // this doesn't work!
|
||||
// t.Err(io.EOF, errors.New("EOF")) // this works
|
||||
// t.DeepEqual(io.EOF, errors.New("EOF")) // this works too
|
||||
//
|
||||
// ★ Each check returns bool, so you can easily skip problematic code:
|
||||
//
|
||||
// if t.Nil(err) {
|
||||
// t.Match(obj.field, `^\d+$`)
|
||||
// }
|
||||
//
|
||||
// ★ You can turn any check into assertion to stop test immediately:
|
||||
//
|
||||
// t.Must(t.Nil(err))
|
||||
//
|
||||
// ★ You can provide extra description to each check:
|
||||
//
|
||||
// t.Equal(got, want, "Just msg: will Print(), % isn't special")
|
||||
// t.Equal(got, want, "Msg with args: will Printf(): %v", extra)
|
||||
//
|
||||
// ★ There are short synonyms for checks implementing usual ==, !=, etc.:
|
||||
//
|
||||
// t.EQ(got, want) // same as t.Equal
|
||||
// t.NE(got, want) // same as t.NotEqual
|
||||
// t.LT(got, want) // same as t.Less
|
||||
// t.LE(got, want) // same as t.LessOrEqual
|
||||
// t.GT(got, want) // same as t.Greater
|
||||
// t.GE(got, want) // same as t.GreaterOrEqual
|
||||
//
|
||||
// ★ If you need custom check, which isn't available out-of-box - see
|
||||
// Should checker, it'll let you plug in your own checker with ease.
|
||||
//
|
||||
// ★ It will panic when called with arg of wrong type - because this
|
||||
// means bug in your test.
|
||||
//
|
||||
// ★ If you don't see colors in `go test` output it may happens because of
|
||||
// two reasons: either your $TERM doesn't contain substring "color" or
|
||||
// you're running `go test path/to/your/package`. To force colored output
|
||||
// in last case just set this environment variable:
|
||||
//
|
||||
// export GO_TEST_COLOR=1
|
||||
//
|
||||
// Contents
|
||||
//
|
||||
// There are few special functions (assertion, custom checkers, etc.).
|
||||
//
|
||||
// Must
|
||||
// Should
|
||||
// TODO
|
||||
//
|
||||
// Everything else are just trivial (mostly) checkers which works in
|
||||
// obvious way and accept values of any types which makes sense (and
|
||||
// panics on everything else).
|
||||
//
|
||||
// Nil NotNil
|
||||
// Zero NotZero
|
||||
// True False
|
||||
//
|
||||
// Equal NotEqual EQ NE
|
||||
// DeepEqual NotDeepEqual
|
||||
// Err NotErr
|
||||
// BytesEqual NotBytesEqual
|
||||
// JSONEqual
|
||||
//
|
||||
// Greater LessOrEqual GT LE
|
||||
// Less GreaterOrEqual LT GE
|
||||
// Between NotBetween
|
||||
// BetweenOrEqual NotBetweenOrEqual
|
||||
// InDelta NotInDelta
|
||||
// InSMAPE NotInSMAPE
|
||||
//
|
||||
// Len NotLen
|
||||
// Match NotMatch
|
||||
// HasPrefix NotHasPrefix
|
||||
// HasSuffix NotHasSuffix
|
||||
// HasKey NotHasKey
|
||||
// Contains NotContains
|
||||
//
|
||||
// HasType NotHasType
|
||||
// Implements NotImplements
|
||||
//
|
||||
// Panic NotPanic
|
||||
// PanicMatch PanicNotMatch
|
||||
package check
|
160
vendor/github.com/powerman/check/dump.go
generated
vendored
Normal file
160
vendor/github.com/powerman/check/dump.go
generated
vendored
Normal file
|
@ -0,0 +1,160 @@
|
|||
package check
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/pmezard/go-difflib/difflib"
|
||||
)
|
||||
|
||||
var spewCfg = spew.ConfigState{
|
||||
Indent: " ",
|
||||
DisablePointerAddresses: true,
|
||||
DisableCapacities: true,
|
||||
SortKeys: true,
|
||||
SpewKeys: true,
|
||||
}
|
||||
|
||||
type dump struct {
|
||||
dump string
|
||||
indirectType reflect.Type
|
||||
}
|
||||
|
||||
// String returns dump of value given to newDump.
|
||||
func (v dump) String() string {
|
||||
return v.dump
|
||||
}
|
||||
|
||||
func (v dump) diff(expected dump) string {
|
||||
if v.indirectType != expected.indirectType {
|
||||
return ""
|
||||
}
|
||||
if !strings.ContainsRune(v.dump[:len(v.dump)-1], '\n') &&
|
||||
!strings.ContainsRune(expected.dump[:len(expected.dump)-1], '\n') {
|
||||
return ""
|
||||
}
|
||||
|
||||
diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
|
||||
A: difflib.SplitLines(expected.dump),
|
||||
B: difflib.SplitLines(v.dump),
|
||||
FromFile: "Expected",
|
||||
FromDate: "",
|
||||
ToFile: "Actual",
|
||||
ToDate: "",
|
||||
Context: 1,
|
||||
})
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return "Diff:\n" + diff
|
||||
}
|
||||
|
||||
// newDump prepare i dump using spew.Sdump in most cases and custom
|
||||
// improved dump for these cases:
|
||||
// - nil: remove "(interface{})" prefix
|
||||
// - byte: use 0xFF instead of decimal
|
||||
// - rune: use quoted char instead of number for valid runes
|
||||
// - string: use this instead of quoted single-line:
|
||||
// - valid utf8: don't quote ", show multiline strings on separate lines
|
||||
// - invalid utf8: use hexdump like for []byte
|
||||
// - []byte: same as string instead of hexdump for valid utf8
|
||||
// - []rune: use quoted char instead of number for valid runes in list
|
||||
// - json.RawMessage: indent, then same as string
|
||||
func newDump(i interface{}) (d dump) { // nolint:gocyclo,gocognit,funlen
|
||||
d.dump = spewCfg.Sdump(i)
|
||||
|
||||
if i == nil {
|
||||
d.dump = "<nil>\n"
|
||||
return d
|
||||
}
|
||||
|
||||
val := reflect.ValueOf(i)
|
||||
typ := reflect.TypeOf(i)
|
||||
kind := typ.Kind()
|
||||
if kind == reflect.Ptr {
|
||||
if val.IsNil() {
|
||||
return d
|
||||
}
|
||||
val = val.Elem()
|
||||
typ = typ.Elem()
|
||||
kind = typ.Kind()
|
||||
}
|
||||
d.indirectType = typ
|
||||
|
||||
switch {
|
||||
case typ == reflect.TypeOf(json.RawMessage(nil)):
|
||||
v := val.Bytes()
|
||||
var buf bytes.Buffer
|
||||
if json.Indent(&buf, v, "", " ") == nil {
|
||||
d.dump = fmt.Sprintf("(%T) (len=%d) '\n%s\n'\n", i, len(v), buf.String())
|
||||
}
|
||||
|
||||
case kind == reflect.Uint8:
|
||||
v := byte(val.Uint())
|
||||
d.dump = fmt.Sprintf("(%T) 0x%02X\n", i, v)
|
||||
|
||||
case kind == reflect.Int32:
|
||||
v := rune(val.Int())
|
||||
if utf8.ValidRune(v) {
|
||||
d.dump = fmt.Sprintf("(%T) %q\n", i, v)
|
||||
}
|
||||
|
||||
case kind == reflect.Slice && typ.Elem().Kind() == reflect.Int32:
|
||||
valid := true
|
||||
for k := 0; k < val.Len() && valid; k++ {
|
||||
valid = valid && utf8.ValidRune(rune(val.Index(k).Int()))
|
||||
}
|
||||
if valid {
|
||||
d.dump = fmt.Sprintf("(%T) %q\n", i, i)
|
||||
}
|
||||
|
||||
case kind == reflect.String:
|
||||
v := val.String()
|
||||
if utf8.ValidString(v) {
|
||||
d.dump = fmt.Sprintf("(%T) (len=%d) %s\n", i, len(v), quote(v))
|
||||
} else {
|
||||
d.dump = strings.Replace(spewCfg.Sdump([]byte(v)), "([]uint8)", fmt.Sprintf("(%T)", i), 1)
|
||||
}
|
||||
|
||||
case kind == reflect.Slice && typ.Elem().Kind() == reflect.Uint8:
|
||||
v := val.Bytes()
|
||||
if len(v) > 0 && utf8.Valid(v) || len(v) == 0 && !val.IsNil() {
|
||||
d.dump = fmt.Sprintf("(%T) (len=%d) %s\n", i, len(v), quote(string(v)))
|
||||
}
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// quote like %#v, except keep \n and " unquoted for readability.
|
||||
func quote(s string) string {
|
||||
r := []rune(strconv.Quote(s))
|
||||
q := r[:0]
|
||||
var multiline, esc bool
|
||||
for _, c := range r[1 : len(r)-1] {
|
||||
if esc {
|
||||
esc = false
|
||||
switch c {
|
||||
case 'n':
|
||||
c = '\n'
|
||||
multiline = true
|
||||
case '"':
|
||||
default:
|
||||
q = append(q, '\\')
|
||||
}
|
||||
} else if c == '\\' {
|
||||
esc = true
|
||||
continue
|
||||
}
|
||||
q = append(q, c)
|
||||
}
|
||||
if multiline {
|
||||
return fmt.Sprintf("'\n%s\n'", string(q))
|
||||
}
|
||||
return fmt.Sprintf("'%s'", string(q))
|
||||
}
|
24
vendor/github.com/powerman/check/flags.go
generated
vendored
Normal file
24
vendor/github.com/powerman/check/flags.go
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
package check
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type peekFlags struct {
|
||||
sync.Once
|
||||
conveyJSON bool
|
||||
}
|
||||
|
||||
var flags peekFlags
|
||||
|
||||
func (p *peekFlags) detect() *peekFlags {
|
||||
flags.Do(func() {
|
||||
flag.Visit(func(f *flag.Flag) {
|
||||
if f.Name == "convey-json" {
|
||||
p.conveyJSON = f.Value.String() == "true"
|
||||
}
|
||||
})
|
||||
})
|
||||
return p
|
||||
}
|
13
vendor/github.com/powerman/check/go.mod
generated
vendored
Normal file
13
vendor/github.com/powerman/check/go.mod
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
module github.com/powerman/check
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/pmezard/go-difflib v1.0.0
|
||||
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
|
||||
github.com/smartystreets/goconvey v1.6.4
|
||||
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c
|
||||
)
|
28
vendor/github.com/powerman/check/go.sum
generated
vendored
Normal file
28
vendor/github.com/powerman/check/go.sum
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
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/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 h1:hBSHahWMEgzwRyS6dRpxY0XyjZsHyQ61s084wo5PJe0=
|
||||
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190526052359-791d8a0f4d09 h1:IlD35wZE03o2qJy2o37WIskL33b7PT6cHdGnE8bieZs=
|
||||
golang.org/x/sys v0.0.0-20190526052359-791d8a0f4d09/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c h1:S/FtSvpNLtFBgjTqcKsRpsa6aVsI6iztaz1bQd9BJwE=
|
||||
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
42
vendor/github.com/powerman/check/goconvey.go
generated
vendored
Normal file
42
vendor/github.com/powerman/check/goconvey.go
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
package check
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey/reporting"
|
||||
)
|
||||
|
||||
var errNoGoConvey = errors.New("goconvey not detected")
|
||||
|
||||
func reportToGoConvey(actual, expected, failure string) error {
|
||||
if !flags.detect().conveyJSON {
|
||||
return errNoGoConvey
|
||||
}
|
||||
|
||||
testFile, testLine, funcLine := callerTestFileLines()
|
||||
report := reporting.ScopeResult{
|
||||
File: testFile,
|
||||
Line: funcLine,
|
||||
Assertions: []*reporting.AssertionResult{{
|
||||
File: testFile,
|
||||
Line: testLine,
|
||||
Expected: expected,
|
||||
Actual: actual,
|
||||
Failure: failure,
|
||||
}},
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintln(&buf, reporting.OpenJson)
|
||||
if err := json.NewEncoder(&buf).Encode(report); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(&buf, ",")
|
||||
fmt.Fprintln(&buf, reporting.CloseJson)
|
||||
_, err := buf.WriteTo(os.Stdout)
|
||||
return err
|
||||
}
|
103
vendor/github.com/powerman/check/stats.go
generated
vendored
Normal file
103
vendor/github.com/powerman/check/stats.go
generated
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
package check
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type counter struct {
|
||||
name string
|
||||
value int
|
||||
force bool
|
||||
color string
|
||||
size int
|
||||
}
|
||||
|
||||
func (c counter) String() (s string) {
|
||||
if c.value != 0 || c.force {
|
||||
color := c.color
|
||||
if c.value == 0 {
|
||||
color = ansiReset
|
||||
}
|
||||
s = fmt.Sprintf("%s%*d %s%s", color, c.size, c.value, c.name, ansiReset)
|
||||
} else {
|
||||
s = strings.Repeat(" ", c.size+1+len(c.name))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
type testStat struct {
|
||||
name string
|
||||
passed counter
|
||||
forged counter
|
||||
failed counter
|
||||
}
|
||||
|
||||
func newTestStat(desc string, force bool) *testStat {
|
||||
return &testStat{
|
||||
name: desc,
|
||||
passed: counter{force: force, name: "passed", color: ansiGreen},
|
||||
forged: counter{force: force, name: "todo", color: ansiYellow},
|
||||
failed: counter{force: force, name: "failed", color: ansiRed},
|
||||
}
|
||||
}
|
||||
|
||||
func (c testStat) String() string {
|
||||
return fmt.Sprintf("checks: %s %s %s\t%s", c.passed, c.forged, c.failed, c.name)
|
||||
}
|
||||
|
||||
var statsMu sync.Mutex
|
||||
var stats = map[*testing.T]*testStat{}
|
||||
|
||||
// Report output statistics about passed/failed checks.
|
||||
// It should be called from TestMain after m.Run(), for ex.:
|
||||
//
|
||||
// func TestMain(m *testing.M) {
|
||||
// code := m.Run()
|
||||
// check.Report()
|
||||
// os.Exit(code)
|
||||
// }
|
||||
//
|
||||
// If this is all you need - just use TestMain instead.
|
||||
func Report() {
|
||||
statsMu.Lock()
|
||||
defer statsMu.Unlock()
|
||||
|
||||
total := newTestStat("(total)", true)
|
||||
ts := make([]*testing.T, 0, len(stats))
|
||||
for t := range stats {
|
||||
ts = append(ts, t)
|
||||
total.passed.value += stats[t].passed.value
|
||||
total.forged.value += stats[t].forged.value
|
||||
total.failed.value += stats[t].failed.value
|
||||
}
|
||||
|
||||
total.passed.size = digits(total.passed.value)
|
||||
total.forged.size = digits(total.forged.value)
|
||||
total.failed.size = digits(total.failed.value)
|
||||
|
||||
if testing.Verbose() {
|
||||
sort.Slice(ts, func(a, b int) bool { return ts[a].Name() < ts[b].Name() })
|
||||
for _, t := range ts {
|
||||
stats[t].passed.size = total.passed.size
|
||||
stats[t].forged.size = total.forged.size
|
||||
stats[t].failed.size = total.failed.size
|
||||
fmt.Printf(" %s\n", stats[t])
|
||||
}
|
||||
}
|
||||
fmt.Printf(" %s\n", total)
|
||||
}
|
||||
|
||||
// TestMain provides same default implementation as used by testing
|
||||
// package with extra Report call to output statistics. Usage:
|
||||
//
|
||||
// func TestMain(m *testing.M) { check.TestMain(m) }
|
||||
func TestMain(m *testing.M) {
|
||||
code := m.Run()
|
||||
Report()
|
||||
os.Exit(code)
|
||||
}
|
64
vendor/github.com/powerman/check/util.go
generated
vendored
Normal file
64
vendor/github.com/powerman/check/util.go
generated
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
package check
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func callerTestFileLines() (file string, line int, funcLine int) {
|
||||
pc, file, line, ok := runtime.Caller(0)
|
||||
myfile := file
|
||||
for stack := 1; ok && samePackage(myfile, file); stack++ {
|
||||
pc, file, line, ok = runtime.Caller(stack)
|
||||
}
|
||||
if f := runtime.FuncForPC(pc); f != nil {
|
||||
_, funcLine = f.FileLine(f.Entry())
|
||||
}
|
||||
return file, line, funcLine
|
||||
}
|
||||
|
||||
func samePackage(basefile, file string) bool {
|
||||
return filepath.Dir(basefile) == filepath.Dir(file) && !strings.HasSuffix(file, "_test.go")
|
||||
}
|
||||
|
||||
func callerFuncName(stack int) string {
|
||||
pc, _, _, _ := runtime.Caller(stack + 1)
|
||||
return strings.TrimPrefix(funcNameAt(pc), "(*C).")
|
||||
}
|
||||
|
||||
func funcName(f interface{}) string {
|
||||
return funcNameAt(reflect.ValueOf(f).Pointer())
|
||||
}
|
||||
|
||||
func funcNameAt(pc uintptr) string {
|
||||
name := "<unknown>"
|
||||
if f := runtime.FuncForPC(pc); f != nil {
|
||||
name = f.Name()
|
||||
if i := strings.LastIndex(name, "/"); i != -1 {
|
||||
name = name[i+1:]
|
||||
}
|
||||
if i := strings.Index(name, "."); i != -1 {
|
||||
name = name[i+1:]
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func format(msg ...interface{}) string {
|
||||
if len(msg) > 1 {
|
||||
return fmt.Sprintf(msg[0].(string), msg[1:]...)
|
||||
}
|
||||
return fmt.Sprint(msg...)
|
||||
}
|
||||
|
||||
// digits return amount of decimal digits in number.
|
||||
func digits(number int) int {
|
||||
if number == 0 {
|
||||
return 1
|
||||
}
|
||||
return int(math.Floor(math.Log10(float64(number)) + 1))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue