Merge remote-tracking branch 'upstream/master' into kill-rogue-processes
diff --git a/README.md b/README.md
index c825591..d1add5b 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,10 @@
Learn more about Ginkgo [here](http://onsi.github.io/ginkgo/)
+## Community Matchers
+
+A collection of community matchers is available on the [wiki](https://github.com/onsi/gomega/wiki).
+
## License
Gomega is MIT-Licensed
diff --git a/format/format.go b/format/format.go
index ec9c91a..06355d9 100644
--- a/format/format.go
+++ b/format/format.go
@@ -7,6 +7,7 @@
"fmt"
"reflect"
"strings"
+ "strconv"
)
// Use MaxDepth to set the maximum recursion depth when printing deeply nested objects
@@ -143,9 +144,6 @@
case reflect.Ptr:
return formatValue(value.Elem(), indentation)
case reflect.Slice:
- if value.Type().Elem().Kind() == reflect.Uint8 {
- return formatString(value.Bytes(), indentation)
- }
return formatSlice(value, indentation)
case reflect.String:
return formatString(value.String(), indentation)
@@ -189,6 +187,10 @@
}
func formatSlice(v reflect.Value, indentation uint) string {
+ if v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.Uint8 && isPrintableString(string(v.Bytes())){
+ return formatString(v.Bytes(), indentation)
+ }
+
l := v.Len()
result := make([]string, l)
longest := 0
@@ -262,15 +264,14 @@
return false
}
-func isNil(a interface{}) bool {
- if a == nil {
- return true
+/*
+Returns true when the string is entirely made of printable runes, false otherwise.
+*/
+func isPrintableString(str string) bool {
+ for _, runeValue := range str {
+ if !strconv.IsPrint(runeValue) {
+ return false
+ }
}
-
- switch reflect.TypeOf(a).Kind() {
- case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
- return reflect.ValueOf(a).IsNil()
- }
-
- return false
+ return true
}
diff --git a/format/format_test.go b/format/format_test.go
index 59517fe..1391fe7 100644
--- a/format/format_test.go
+++ b/format/format_test.go
@@ -162,13 +162,19 @@
})
Describe("formatting []byte slices", func() {
- It("should present them as strings", func() {
- b := []byte("a\nb\nc")
- Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:5, cap:\d+`, `a
- b
- c`))
- })
- })
+ Context("when the slice is made of printable bytes", func () {
+ It("should present it as string", func() {
+ b := []byte("a b c")
+ Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:5, cap:\d+`, `a b c`))
+ })
+ })
+ Context("when the slice contains non-printable bytes", func () {
+ It("should present it as slice", func() {
+ b := []byte("a b c\n\x01\x02\x03\xff\x1bH")
+ Ω(Object(b, 1)).Should(matchRegexp(`\[\]uint8 \| len:12, cap:\d+`, `\[97, 32, 98, 32, 99, 10, 1, 2, 3, 255, 27, 72\]`))
+ })
+ })
+ })
Describe("formatting functions", func() {
It("should give the type and format values correctly", func() {
diff --git a/gbytes/say_matcher.go b/gbytes/say_matcher.go
index ce5ebcb..cbc266c 100644
--- a/gbytes/say_matcher.go
+++ b/gbytes/say_matcher.go
@@ -22,7 +22,7 @@
When Say succeeds, it fast forwards the gbytes.Buffer's read cursor to just after the succesful match.
Thus, subsequent calls to Say will only match against the unread portion of the buffer
-Say pairs very well with Eventually. To asser that a buffer eventually receives data matching "[123]-star" within 3 seconds you can:
+Say pairs very well with Eventually. To assert that a buffer eventually receives data matching "[123]-star" within 3 seconds you can:
Eventually(buffer, 3).Should(Say("[123]-star"))
diff --git a/gexec/session.go b/gexec/session.go
index 987e472..3cbfded 100644
--- a/gexec/session.go
+++ b/gexec/session.go
@@ -60,7 +60,7 @@
Ω(session).Should(gexec.Exit())
When the session exits it closes the stdout and stderr gbytes buffers. This will short circuit any
-Eventuallys waiting fo the buffers to Say something.
+Eventuallys waiting for the buffers to Say something.
*/
func Start(command *exec.Cmd, outWriter io.Writer, errWriter io.Writer) (*Session, error) {
exited := make(chan struct{})
diff --git a/ghttp/test_server.go b/ghttp/test_server.go
index 2f76bb2..093550d 100644
--- a/ghttp/test_server.go
+++ b/ghttp/test_server.go
@@ -202,7 +202,9 @@
server := s.HTTPTestServer
s.HTTPTestServer = nil
- server.Close()
+ if server != nil {
+ server.Close()
+ }
}
//ServeHTTP() makes Server an http.Handler
diff --git a/ghttp/test_server_test.go b/ghttp/test_server_test.go
index b8a9318..88b3246 100644
--- a/ghttp/test_server_test.go
+++ b/ghttp/test_server_test.go
@@ -78,6 +78,13 @@
})
})
+ Describe("closing server mulitple times", func() {
+ It("should not fail", func() {
+ s.Close()
+ Ω(s.Close).ShouldNot(Panic())
+ })
+ })
+
Describe("allowing unhandled requests", func() {
Context("when true", func() {
BeforeEach(func() {