github.com/chrislusf/greenpack@v3.7.1-0.20170911073826-ad5bd10b7c47+incompatible/cmd/addzid/old_bambam_tests/utilities_for_test.go (about)

     1  package main
     2  
     3  /*
     4  Copyright (c) 2014 SmartyStreets, LLC
     5  
     6  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:
     7  
     8  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
     9  
    10  	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.
    11  
    12  NOTE: Various optional and subordinate components carry their own licensing requirements and restrictions. Use of those components is subject to the terms and conditions outlined the respective license of each component.
    13  */
    14  
    15  import (
    16  	"fmt"
    17  	"path"
    18  	"runtime"
    19  	"strings"
    20  	"testing"
    21  )
    22  
    23  func pass(t *testing.T, result string) {
    24  	if result != success {
    25  		_, file, line, _ := runtime.Caller(1)
    26  		base := path.Base(file)
    27  		t.Errorf("Expectation should have passed but failed (see %s: line %d): '%s'", base, line, result)
    28  	}
    29  }
    30  
    31  func fail(t *testing.T, actual string, expected string) {
    32  	actual = format(actual)
    33  	expected = format(expected)
    34  
    35  	if actual != expected {
    36  		if actual == "" {
    37  			actual = "(empty)"
    38  		}
    39  		_, file, line, _ := runtime.Caller(1)
    40  		base := path.Base(file)
    41  		t.Errorf("Expectation should have failed but passed (see %s: line %d). \nExpected: %s\nActual:   %s\n",
    42  			base, line, expected, actual)
    43  	}
    44  }
    45  func format(message string) string {
    46  	message = strings.Replace(message, "\n", " ", -1)
    47  	for strings.Contains(message, "  ") {
    48  		message = strings.Replace(message, "  ", " ", -1)
    49  	}
    50  	return message
    51  }
    52  
    53  func so(actual interface{}, assert func(interface{}, ...interface{}) string, expected ...interface{}) string {
    54  	return assert(actual, expected...)
    55  }
    56  
    57  type Thing1 struct {
    58  	a string
    59  }
    60  type Thing2 struct {
    61  	a string
    62  }
    63  
    64  type Thinger interface {
    65  	Hi()
    66  }
    67  
    68  type Thing struct{}
    69  
    70  func (self *Thing) Hi() {}
    71  
    72  type IntAlias int
    73  type StringAlias string
    74  type StringSliceAlias []string
    75  type StringStringMapAlias map[string]string
    76  
    77  /******** FakeSerialzier ********/
    78  
    79  type fakeSerializer struct{}
    80  
    81  func (self *fakeSerializer) serialize(expected, actual interface{}, message string) string {
    82  	return fmt.Sprintf("%v|%v|%s", expected, actual, message)
    83  }
    84  
    85  func (self *fakeSerializer) serializeDetailed(expected, actual interface{}, message string) string {
    86  	return fmt.Sprintf("%v|%v|%s", expected, actual, message)
    87  }
    88  
    89  func newFakeSerializer() *fakeSerializer {
    90  	return new(fakeSerializer)
    91  }