コード例 #1
0
ファイル: foundation_test.go プロジェクト: dvln/check
import (
	"fmt"
	"log"
	"os"
	"regexp"
	"strings"

	"github.com/dvln/check"
)

// -----------------------------------------------------------------------
// Foundation test suite.

type FoundationS struct{}

var foundationS = check.Suite(&FoundationS{})

func (s *FoundationS) TestCountSuite(c *check.C) {
	suitesRun += 1
}

func (s *FoundationS) TestErrorf(c *check.C) {
	// Do not use checkState() here.  It depends on Errorf() working.
	expectedLog := fmt.Sprintf("foundation_test.go:%d:\n"+
		"    c.Errorf(\"Error %%v!\", \"message\")\n"+
		"... Error: Error message!\n\n",
		getMyLine()+1)
	c.Errorf("Error %v!", "message")
	failed := c.Failed()
	c.Succeed()
	if log := c.GetTestLog(); log != expectedLog {
コード例 #2
0
ファイル: bootstrap_test.go プロジェクト: dvln/check
//
// Do not assume *any* internal functionality works as expected besides
// what's actually tested here.

package check_test

import (
	"fmt"
	"strings"

	"github.com/dvln/check"
)

type BootstrapS struct{}

var boostrapS = check.Suite(&BootstrapS{})

func (s *BootstrapS) TestCountSuite(c *check.C) {
	suitesRun += 1
}

func (s *BootstrapS) TestFailedAndFail(c *check.C) {
	if c.Failed() {
		critical("c.Failed() must be false first!")
	}
	c.Fail()
	if !c.Failed() {
		critical("c.Fail() didn't put the test in a failed state!")
	}
	c.Succeed()
}
コード例 #3
0
ファイル: helpers_test.go プロジェクト: dvln/check
// These tests verify the inner workings of the helper methods associated
// with check.T.

package check_test

import (
	"os"
	"reflect"
	"runtime"
	"sync"

	"github.com/dvln/check"
)

var helpersS = check.Suite(&HelpersS{})

type HelpersS struct{}

func (s *HelpersS) TestCountSuite(c *check.C) {
	suitesRun += 1
}

// -----------------------------------------------------------------------
// Fake checker and bug info to verify the behavior of Assert() and Check().

type MyChecker struct {
	info   *check.CheckerInfo
	params []interface{}
	names  []string
	result bool
	error  string
コード例 #4
0
ファイル: checkers_test.go プロジェクト: dvln/check
package check_test

import (
	"errors"
	"reflect"
	"runtime"

	"github.com/dvln/check"
)

type CheckersS struct{}

var _ = check.Suite(&CheckersS{})

func testInfo(c *check.C, checker check.Checker, name string, paramNames []string) {
	info := checker.Info()
	if info.Name != name {
		c.Fatalf("Got name %s, expected %s", info.Name, name)
	}
	if !reflect.DeepEqual(info.Params, paramNames) {
		c.Fatalf("Got param names %#v, expected %#v", info.Params, paramNames)
	}
}

func testCheck(c *check.C, checker check.Checker, result bool, error string, params ...interface{}) ([]interface{}, []string) {
	info := checker.Info()
	if len(params) != len(info.Params) {
		c.Fatalf("unexpected param count in test; expected %d got %d", len(info.Params), len(params))
	}
	names := append([]string{}, info.Params...)
	result_, error_ := checker.Check(params, names)