diff options
Diffstat (limited to 'src/pkg/testing')
-rw-r--r-- | src/pkg/testing/iotest/reader.go | 12 | ||||
-rw-r--r-- | src/pkg/testing/quick/quick.go | 8 | ||||
-rw-r--r-- | src/pkg/testing/quick/quick_test.go | 84 | ||||
-rw-r--r-- | src/pkg/testing/regexp.go | 124 | ||||
-rw-r--r-- | src/pkg/testing/script/script.go | 68 | ||||
-rw-r--r-- | src/pkg/testing/testing.go | 12 |
6 files changed, 77 insertions, 231 deletions
diff --git a/src/pkg/testing/iotest/reader.go b/src/pkg/testing/iotest/reader.go index 823124aa3..ae427e6fa 100644 --- a/src/pkg/testing/iotest/reader.go +++ b/src/pkg/testing/iotest/reader.go @@ -14,9 +14,7 @@ import ( // OneByteReader returns a Reader that implements // each non-empty Read by reading one byte from r. -func OneByteReader(r io.Reader) io.Reader { - return &oneByteReader{r}; -} +func OneByteReader(r io.Reader) io.Reader { return &oneByteReader{r} } type oneByteReader struct { r io.Reader; @@ -31,9 +29,7 @@ func (r *oneByteReader) Read(p []byte) (int, os.Error) { // HalfReader returns a Reader that implements Read // by reading half as many requested bytes from r. -func HalfReader(r io.Reader) io.Reader { - return &halfReader{r}; -} +func HalfReader(r io.Reader) io.Reader { return &halfReader{r} } type halfReader struct { r io.Reader; @@ -47,9 +43,7 @@ func (r *halfReader) Read(p []byte) (int, os.Error) { // DataErrReader returns a Reader that returns the final // error with the last data read, instead of by itself with // zero bytes of data. -func DataErrReader(r io.Reader) io.Reader { - return &dataErrReader{r, nil, make([]byte, 1024)}; -} +func DataErrReader(r io.Reader) io.Reader { return &dataErrReader{r, nil, make([]byte, 1024)} } type dataErrReader struct { r io.Reader; diff --git a/src/pkg/testing/quick/quick.go b/src/pkg/testing/quick/quick.go index 5a7e8d37a..3d47240bd 100644 --- a/src/pkg/testing/quick/quick.go +++ b/src/pkg/testing/quick/quick.go @@ -43,9 +43,7 @@ func randFloat64(rand *rand.Rand) float64 { } // randInt64 returns a random integer taking half the range of an int64. -func randInt64(rand *rand.Rand) int64 { - return rand.Int63() - 1<<62; -} +func randInt64(rand *rand.Rand) int64 { return rand.Int63() - 1<<62 } // complexSize is the maximum length of arbitrary values that contain other // values. @@ -195,9 +193,7 @@ func (c *Config) getMaxCount() (maxCount int) { // used, independent of the functions being tested. type SetupError string -func (s SetupError) String() string { - return string(s); -} +func (s SetupError) String() string { return string(s) } // A CheckError is the result of Check finding an error. type CheckError struct { diff --git a/src/pkg/testing/quick/quick_test.go b/src/pkg/testing/quick/quick_test.go index 290f171ea..951582e35 100644 --- a/src/pkg/testing/quick/quick_test.go +++ b/src/pkg/testing/quick/quick_test.go @@ -11,90 +11,50 @@ import ( "os"; ) -func fBool(a bool) bool { - return a; -} +func fBool(a bool) bool { return a } -func fFloat32(a float32) float32 { - return a; -} +func fFloat32(a float32) float32 { return a } -func fFloat64(a float64) float64 { - return a; -} +func fFloat64(a float64) float64 { return a } -func fFloat(a float) float { - return a; -} +func fFloat(a float) float { return a } -func fInt16(a int16) int16 { - return a; -} +func fInt16(a int16) int16 { return a } -func fInt32(a int32) int32 { - return a; -} +func fInt32(a int32) int32 { return a } -func fInt64(a int64) int64 { - return a; -} +func fInt64(a int64) int64 { return a } -func fInt8(a int8) int8 { - return a; -} +func fInt8(a int8) int8 { return a } -func fInt(a int) int { - return a; -} +func fInt(a int) int { return a } -func fUInt8(a uint8) uint8 { - return a; -} +func fUInt8(a uint8) uint8 { return a } -func fMap(a map[int]int) map[int]int { - return a; -} +func fMap(a map[int]int) map[int]int { return a } -func fSlice(a []byte) []byte { - return a; -} +func fSlice(a []byte) []byte { return a } -func fString(a string) string { - return a; -} +func fString(a string) string { return a } type TestStruct struct { A int; B string; } -func fStruct(a TestStruct) TestStruct { - return a; -} +func fStruct(a TestStruct) TestStruct { return a } -func fUint16(a uint16) uint16 { - return a; -} +func fUint16(a uint16) uint16 { return a } -func fUint32(a uint32) uint32 { - return a; -} +func fUint32(a uint32) uint32 { return a } -func fUint64(a uint64) uint64 { - return a; -} +func fUint64(a uint64) uint64 { return a } -func fUint8(a uint8) uint8 { - return a; -} +func fUint8(a uint8) uint8 { return a } -func fUint(a uint) uint { - return a; -} +func fUint(a uint) uint { return a } -func fUintptr(a uintptr) uintptr { - return a; -} +func fUintptr(a uintptr) uintptr { return a } func fIntptr(a *int) *int { b := *a; @@ -142,9 +102,7 @@ func (m myStruct) Generate(r *rand.Rand, _ int) reflect.Value { return reflect.NewValue(myStruct{x: 42}); } -func myStructProperty(in myStruct) bool { - return in.x == 42; -} +func myStructProperty(in myStruct) bool { return in.x == 42 } func TestCheckProperty(t *testing.T) { reportError("myStructProperty", Check(myStructProperty, nil), t); diff --git a/src/pkg/testing/regexp.go b/src/pkg/testing/regexp.go index a91ae4dbb..f4cfe5e6e 100644 --- a/src/pkg/testing/regexp.go +++ b/src/pkg/testing/regexp.go @@ -60,18 +60,10 @@ type common struct { _index int; } -func (c *common) next() instr { - return c._next; -} -func (c *common) setNext(i instr) { - c._next = i; -} -func (c *common) index() int { - return c._index; -} -func (c *common) setIndex(i int) { - c._index = i; -} +func (c *common) next() instr { return c._next } +func (c *common) setNext(i instr) { c._next = i } +func (c *common) index() int { return c._index } +func (c *common) setIndex(i int) { c._index = i } // The representation of a compiled regular expression. // The public interface is entirely through methods. @@ -103,48 +95,32 @@ type _Start struct { common; } -func (start *_Start) kind() int { - return _START; -} -func (start *_Start) print() { - print("start"); -} +func (start *_Start) kind() int { return _START } +func (start *_Start) print() { print("start") } // --- END end of program type _End struct { common; } -func (end *_End) kind() int { - return _END; -} -func (end *_End) print() { - print("end"); -} +func (end *_End) kind() int { return _END } +func (end *_End) print() { print("end") } // --- BOT beginning of text type _Bot struct { common; } -func (bot *_Bot) kind() int { - return _BOT; -} -func (bot *_Bot) print() { - print("bot"); -} +func (bot *_Bot) kind() int { return _BOT } +func (bot *_Bot) print() { print("bot") } // --- EOT end of text type _Eot struct { common; } -func (eot *_Eot) kind() int { - return _EOT; -} -func (eot *_Eot) print() { - print("eot"); -} +func (eot *_Eot) kind() int { return _EOT } +func (eot *_Eot) print() { print("eot") } // --- CHAR a regular character type _Char struct { @@ -152,12 +128,8 @@ type _Char struct { char int; } -func (char *_Char) kind() int { - return _CHAR; -} -func (char *_Char) print() { - print("char ", string(char.char)); -} +func (char *_Char) kind() int { return _CHAR } +func (char *_Char) print() { print("char ", string(char.char)) } func newChar(char int) *_Char { c := new(_Char); @@ -175,9 +147,7 @@ type _CharClass struct { ranges []int; } -func (cclass *_CharClass) kind() int { - return _CHARCLASS; -} +func (cclass *_CharClass) kind() int { return _CHARCLASS } func (cclass *_CharClass) print() { print("charclass"); @@ -234,24 +204,16 @@ type _Any struct { common; } -func (any *_Any) kind() int { - return _ANY; -} -func (any *_Any) print() { - print("any"); -} +func (any *_Any) kind() int { return _ANY } +func (any *_Any) print() { print("any") } // --- NOTNL any character but newline type _NotNl struct { common; } -func (notnl *_NotNl) kind() int { - return _NOTNL; -} -func (notnl *_NotNl) print() { - print("notnl"); -} +func (notnl *_NotNl) kind() int { return _NOTNL } +func (notnl *_NotNl) print() { print("notnl") } // --- BRA parenthesized expression type _Bra struct { @@ -259,12 +221,8 @@ type _Bra struct { n int; // subexpression number } -func (bra *_Bra) kind() int { - return _BRA; -} -func (bra *_Bra) print() { - print("bra", bra.n); -} +func (bra *_Bra) kind() int { return _BRA } +func (bra *_Bra) print() { print("bra", bra.n) } // --- EBRA end of parenthesized expression type _Ebra struct { @@ -272,12 +230,8 @@ type _Ebra struct { n int; // subexpression number } -func (ebra *_Ebra) kind() int { - return _EBRA; -} -func (ebra *_Ebra) print() { - print("ebra ", ebra.n); -} +func (ebra *_Ebra) kind() int { return _EBRA } +func (ebra *_Ebra) print() { print("ebra ", ebra.n) } // --- ALT alternation type _Alt struct { @@ -285,24 +239,16 @@ type _Alt struct { left instr; // other branch } -func (alt *_Alt) kind() int { - return _ALT; -} -func (alt *_Alt) print() { - print("alt(", alt.left.index(), ")"); -} +func (alt *_Alt) kind() int { return _ALT } +func (alt *_Alt) print() { print("alt(", alt.left.index(), ")") } // --- NOP no operation type _Nop struct { common; } -func (nop *_Nop) kind() int { - return _NOP; -} -func (nop *_Nop) print() { - print("nop"); -} +func (nop *_Nop) kind() int { return _NOP } +func (nop *_Nop) print() { print("nop") } func (re *Regexp) add(i instr) instr { n := len(re.inst); @@ -329,9 +275,7 @@ type parser struct { const endOfFile = -1 -func (p *parser) c() int { - return p.ch; -} +func (p *parser) c() int { return p.ch } func (p *parser) nextc() int { if p.pos >= len(p.re.expr) { @@ -837,23 +781,17 @@ func (re *Regexp) ExecuteString(s string) (a []int) { // b[a[2*i]:a[2*i+1]] for i > 0 is the subslice matched by the ith parenthesized subexpression. // A negative value means the subexpression did not match any element of the slice. // An empty array means "no match". -func (re *Regexp) Execute(b []byte) (a []int) { - return re.doExecute("", b, 0); -} +func (re *Regexp) Execute(b []byte) (a []int) { return re.doExecute("", b, 0) } // MatchString returns whether the Regexp matches the string s. // The return value is a boolean: true for match, false for no match. -func (re *Regexp) MatchString(s string) bool { - return len(re.doExecute(s, nil, 0)) > 0; -} +func (re *Regexp) MatchString(s string) bool { return len(re.doExecute(s, nil, 0)) > 0 } // Match returns whether the Regexp matches the byte slice b. // The return value is a boolean: true for match, false for no match. -func (re *Regexp) Match(b []byte) bool { - return len(re.doExecute("", b, 0)) > 0; -} +func (re *Regexp) Match(b []byte) bool { return len(re.doExecute("", b, 0)) > 0 } // MatchStrings matches the Regexp against the string s. diff --git a/src/pkg/testing/script/script.go b/src/pkg/testing/script/script.go index 65ccb09dd..6bf6ca26f 100644 --- a/src/pkg/testing/script/script.go +++ b/src/pkg/testing/script/script.go @@ -57,17 +57,11 @@ type Recv struct { Expected interface{}; } -func (r Recv) getRecv() recvAction { - return r; -} +func (r Recv) getRecv() recvAction { return r } -func (Recv) getSend() sendAction { - return nil; -} +func (Recv) getSend() sendAction { return nil } -func (r Recv) getChannel() interface{} { - return r.Channel; -} +func (r Recv) getChannel() interface{} { return r.Channel } func (r Recv) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelRecv); @@ -85,17 +79,11 @@ type RecvMatch struct { Match func(interface{}) bool; } -func (r RecvMatch) getRecv() recvAction { - return r; -} +func (r RecvMatch) getRecv() recvAction { return r } -func (RecvMatch) getSend() sendAction { - return nil; -} +func (RecvMatch) getSend() sendAction { return nil } -func (r RecvMatch) getChannel() interface{} { - return r.Channel; -} +func (r RecvMatch) getChannel() interface{} { return r.Channel } func (r RecvMatch) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelRecv); @@ -113,17 +101,11 @@ type Closed struct { Channel interface{}; } -func (r Closed) getRecv() recvAction { - return r; -} +func (r Closed) getRecv() recvAction { return r } -func (Closed) getSend() sendAction { - return nil; -} +func (Closed) getSend() sendAction { return nil } -func (r Closed) getChannel() interface{} { - return r.Channel; -} +func (r Closed) getChannel() interface{} { return r.Channel } func (r Closed) recvMatch(chanEvent interface{}) bool { c, ok := chanEvent.(channelClosed); @@ -141,17 +123,11 @@ type Send struct { Value interface{}; } -func (Send) getRecv() recvAction { - return nil; -} +func (Send) getRecv() recvAction { return nil } -func (s Send) getSend() sendAction { - return s; -} +func (s Send) getSend() sendAction { return s } -func (s Send) getChannel() interface{} { - return s.Channel; -} +func (s Send) getChannel() interface{} { return s.Channel } func newEmptyInterface(args ...) reflect.Value { return reflect.NewValue(args).(*reflect.StructValue).Field(0); @@ -176,21 +152,13 @@ type Close struct { Channel interface{}; } -func (Close) getRecv() recvAction { - return nil; -} +func (Close) getRecv() recvAction { return nil } -func (s Close) getSend() sendAction { - return s; -} +func (s Close) getSend() sendAction { return s } -func (s Close) getChannel() interface{} { - return s.Channel; -} +func (s Close) getChannel() interface{} { return s.Channel } -func (s Close) send() { - reflect.NewValue(s.Channel).(*reflect.ChanValue).Close(); -} +func (s Close) send() { reflect.NewValue(s.Channel).(*reflect.ChanValue).Close() } // A ReceivedUnexpected error results if no active Events match a value // received from a channel. @@ -211,9 +179,7 @@ func (r ReceivedUnexpected) String() string { // Events. type SetupError string -func (s SetupError) String() string { - return string(s); -} +func (s SetupError) String() string { return string(s) } func NewEvent(name string, predecessors []*Event, action action) *Event { e := &Event{name, false, predecessors, action}; diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go index e8dfee2bd..b04e8d40c 100644 --- a/src/pkg/testing/testing.go +++ b/src/pkg/testing/testing.go @@ -47,14 +47,10 @@ type T struct { } // Fail marks the Test function as having failed but continues execution. -func (t *T) Fail() { - t.failed = true; -} +func (t *T) Fail() { t.failed = true } // Failed returns whether the Test function has failed. -func (t *T) Failed() bool { - return t.failed; -} +func (t *T) Failed() bool { return t.failed } // FailNow marks the Test function as having failed and stops its execution. // Execution will continue at the next Test. @@ -66,9 +62,7 @@ func (t *T) FailNow() { // Log formats its arguments using default formatting, analogous to Print(), // and records the text in the error log. -func (t *T) Log(args ...) { - t.errors += "\t"+tabify(fmt.Sprintln(args)); -} +func (t *T) Log(args ...) { t.errors += "\t"+tabify(fmt.Sprintln(args)) } // Log formats its arguments according to the format, analogous to Printf(), // and records the text in the error log. |