Merge lp:~waigani/juju-core/remove-checkers-dir into lp:~go-bot/juju-core/trunk
- remove-checkers-dir
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Jesse Meek |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2435 |
Proposed branch: | lp:~waigani/juju-core/remove-checkers-dir |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
1774 lines (+1/-1698) 13 files modified
testing/checkers/bool.go (+0/-115) testing/checkers/bool_test.go (+0/-120) testing/checkers/checker.go (+0/-202) testing/checkers/checker_test.go (+0/-119) testing/checkers/deepequal.go (+0/-303) testing/checkers/deepequal_test.go (+0/-171) testing/checkers/file.go (+0/-154) testing/checkers/file_test.go (+0/-165) testing/checkers/log.go (+0/-109) testing/checkers/log_test.go (+0/-111) testing/checkers/relop.go (+0/-93) testing/checkers/relop_test.go (+0/-35) worker/instancepoller/aggregate_test.go (+1/-1) |
To merge this branch: | bzr merge lp:~waigani/juju-core/remove-checkers-dir |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+210935@code.launchpad.net |
Commit message
Remove Checkers Dir
We now get checkers from github branch.
Description of the change
Remove Checkers Dir
We now get checkers from github branch.
Jesse Meek (waigani) wrote : | # |
Andrew Wilkins (axwalk) wrote : | # |
On 2014/03/13 23:19:53, waigani wrote:
> Please take a look.
LGTM
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~waigani/juju-core/remove-checkers-dir into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
?...
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~waigani/juju-core/remove-checkers-dir into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
o...
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~waigani/juju-core/remove-checkers-dir into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
-------
FAIL: storage_
[LOG] 12.41139 DEBUG juju.utils.ssh running: ssh -o "StrictHostKeyC
storage_
c.Assert(err, gc.IsNil)
... value *errors.errorString = &errors.
OOPS: 21 passed, 1 FAILED
--- FAIL: Test (0.95 seconds)
FAIL
FAIL launchpad.
Preview Diff
1 | === removed directory 'testing/checkers' |
2 | === removed file 'testing/checkers/bool.go' |
3 | --- testing/checkers/bool.go 2014-01-13 15:00:49 +0000 |
4 | +++ testing/checkers/bool.go 1970-01-01 00:00:00 +0000 |
5 | @@ -1,115 +0,0 @@ |
6 | -// Copyright 2013 Canonical Ltd. |
7 | -// Licensed under the AGPLv3, see LICENCE file for details. |
8 | - |
9 | -package checkers |
10 | - |
11 | -import ( |
12 | - "fmt" |
13 | - "reflect" |
14 | - |
15 | - gc "launchpad.net/gocheck" |
16 | -) |
17 | - |
18 | -type isTrueChecker struct { |
19 | - *gc.CheckerInfo |
20 | -} |
21 | - |
22 | -// IsTrue checks whether a value has an underlying |
23 | -// boolean type and is true. |
24 | -var IsTrue gc.Checker = &isTrueChecker{ |
25 | - &gc.CheckerInfo{Name: "IsTrue", Params: []string{"obtained"}}, |
26 | -} |
27 | - |
28 | -// IsTrue checks whether a value has an underlying |
29 | -// boolean type and is false. |
30 | -var IsFalse gc.Checker = gc.Not(IsTrue) |
31 | - |
32 | -func (checker *isTrueChecker) Check(params []interface{}, names []string) (result bool, error string) { |
33 | - |
34 | - value := reflect.ValueOf(params[0]) |
35 | - |
36 | - switch value.Kind() { |
37 | - case reflect.Bool: |
38 | - return value.Bool(), "" |
39 | - } |
40 | - |
41 | - return false, fmt.Sprintf("expected type bool, received type %s", value.Type()) |
42 | -} |
43 | - |
44 | -type satisfiesChecker struct { |
45 | - *gc.CheckerInfo |
46 | -} |
47 | - |
48 | -// Satisfies checks whether a value causes the argument |
49 | -// function to return true. The function must be of |
50 | -// type func(T) bool where the value being checked |
51 | -// is assignable to T. |
52 | -var Satisfies gc.Checker = &satisfiesChecker{ |
53 | - &gc.CheckerInfo{ |
54 | - Name: "Satisfies", |
55 | - Params: []string{"obtained", "func(T) bool"}, |
56 | - }, |
57 | -} |
58 | - |
59 | -func (checker *satisfiesChecker) Check(params []interface{}, names []string) (result bool, error string) { |
60 | - f := reflect.ValueOf(params[1]) |
61 | - ft := f.Type() |
62 | - if ft.Kind() != reflect.Func || |
63 | - ft.NumIn() != 1 || |
64 | - ft.NumOut() != 1 || |
65 | - ft.Out(0) != reflect.TypeOf(true) { |
66 | - return false, fmt.Sprintf("expected func(T) bool, got %s", ft) |
67 | - } |
68 | - v := reflect.ValueOf(params[0]) |
69 | - if !v.IsValid() { |
70 | - if !canBeNil(ft.In(0)) { |
71 | - return false, fmt.Sprintf("cannot assign nil to argument %T", ft.In(0)) |
72 | - } |
73 | - v = reflect.Zero(ft.In(0)) |
74 | - } |
75 | - if !v.Type().AssignableTo(ft.In(0)) { |
76 | - return false, fmt.Sprintf("wrong argument type %s for %s", v.Type(), ft) |
77 | - } |
78 | - return f.Call([]reflect.Value{v})[0].Interface().(bool), "" |
79 | -} |
80 | - |
81 | -func canBeNil(t reflect.Type) bool { |
82 | - switch t.Kind() { |
83 | - case reflect.Chan, |
84 | - reflect.Func, |
85 | - reflect.Interface, |
86 | - reflect.Map, |
87 | - reflect.Ptr, |
88 | - reflect.Slice: |
89 | - return true |
90 | - } |
91 | - return false |
92 | -} |
93 | - |
94 | -type deepEqualsChecker struct { |
95 | - *gc.CheckerInfo |
96 | -} |
97 | - |
98 | -// The DeepEquals checker verifies that the obtained value is deep-equal to |
99 | -// the expected value. The check will work correctly even when facing |
100 | -// slices, interfaces, and values of different types (which always fail |
101 | -// the test). |
102 | -// |
103 | -// For example: |
104 | -// |
105 | -// c.Assert(value, DeepEquals, 42) |
106 | -// c.Assert(array, DeepEquals, []string{"hi", "there"}) |
107 | -// |
108 | -// This checker differs from gocheck.DeepEquals in that |
109 | -// it will compare a nil slice equal to an empty slice, |
110 | -// and a nil map equal to an empty map. |
111 | -var DeepEquals gc.Checker = &deepEqualsChecker{ |
112 | - &gc.CheckerInfo{Name: "DeepEquals", Params: []string{"obtained", "expected"}}, |
113 | -} |
114 | - |
115 | -func (checker *deepEqualsChecker) Check(params []interface{}, names []string) (result bool, error string) { |
116 | - if ok, err := DeepEqual(params[0], params[1]); !ok { |
117 | - return false, err.Error() |
118 | - } |
119 | - return true, "" |
120 | -} |
121 | |
122 | === removed file 'testing/checkers/bool_test.go' |
123 | --- testing/checkers/bool_test.go 2014-03-13 07:54:56 +0000 |
124 | +++ testing/checkers/bool_test.go 1970-01-01 00:00:00 +0000 |
125 | @@ -1,120 +0,0 @@ |
126 | -// Copyright 2013 Canonical Ltd. |
127 | -// Licensed under the AGPLv3, see LICENCE file for details. |
128 | - |
129 | -package checkers_test |
130 | - |
131 | -import ( |
132 | - "errors" |
133 | - "os" |
134 | - |
135 | - jc "github.com/juju/testing/checkers" |
136 | - gc "launchpad.net/gocheck" |
137 | -) |
138 | - |
139 | -type BoolSuite struct{} |
140 | - |
141 | -var _ = gc.Suite(&BoolSuite{}) |
142 | - |
143 | -func (s *BoolSuite) TestIsTrue(c *gc.C) { |
144 | - c.Assert(true, jc.IsTrue) |
145 | - c.Assert(false, gc.Not(jc.IsTrue)) |
146 | - |
147 | - result, msg := jc.IsTrue.Check([]interface{}{false}, nil) |
148 | - c.Assert(result, gc.Equals, false) |
149 | - c.Assert(msg, gc.Equals, "") |
150 | - |
151 | - result, msg = jc.IsTrue.Check([]interface{}{"foo"}, nil) |
152 | - c.Assert(result, gc.Equals, false) |
153 | - c.Check(msg, gc.Equals, `expected type bool, received type string`) |
154 | - |
155 | - result, msg = jc.IsTrue.Check([]interface{}{42}, nil) |
156 | - c.Assert(result, gc.Equals, false) |
157 | - c.Assert(msg, gc.Equals, `expected type bool, received type int`) |
158 | -} |
159 | - |
160 | -func (s *BoolSuite) TestIsFalse(c *gc.C) { |
161 | - c.Assert(false, jc.IsFalse) |
162 | - c.Assert(true, gc.Not(jc.IsFalse)) |
163 | -} |
164 | - |
165 | -func is42(i int) bool { |
166 | - return i == 42 |
167 | -} |
168 | - |
169 | -var satisfiesTests = []struct { |
170 | - f interface{} |
171 | - arg interface{} |
172 | - result bool |
173 | - msg string |
174 | -}{{ |
175 | - f: is42, |
176 | - arg: 42, |
177 | - result: true, |
178 | -}, { |
179 | - f: is42, |
180 | - arg: 41, |
181 | - result: false, |
182 | -}, { |
183 | - f: is42, |
184 | - arg: "", |
185 | - result: false, |
186 | - msg: "wrong argument type string for func(int) bool", |
187 | -}, { |
188 | - f: os.IsNotExist, |
189 | - arg: errors.New("foo"), |
190 | - result: false, |
191 | -}, { |
192 | - f: os.IsNotExist, |
193 | - arg: os.ErrNotExist, |
194 | - result: true, |
195 | -}, { |
196 | - f: os.IsNotExist, |
197 | - arg: nil, |
198 | - result: false, |
199 | -}, { |
200 | - f: func(chan int) bool { return true }, |
201 | - arg: nil, |
202 | - result: true, |
203 | -}, { |
204 | - f: func(func()) bool { return true }, |
205 | - arg: nil, |
206 | - result: true, |
207 | -}, { |
208 | - f: func(interface{}) bool { return true }, |
209 | - arg: nil, |
210 | - result: true, |
211 | -}, { |
212 | - f: func(map[string]bool) bool { return true }, |
213 | - arg: nil, |
214 | - result: true, |
215 | -}, { |
216 | - f: func(*int) bool { return true }, |
217 | - arg: nil, |
218 | - result: true, |
219 | -}, { |
220 | - f: func([]string) bool { return true }, |
221 | - arg: nil, |
222 | - result: true, |
223 | -}} |
224 | - |
225 | -func (s *BoolSuite) TestSatisfies(c *gc.C) { |
226 | - for i, test := range satisfiesTests { |
227 | - c.Logf("test %d. %T %T", i, test.f, test.arg) |
228 | - result, msg := jc.Satisfies.Check([]interface{}{test.arg, test.f}, nil) |
229 | - c.Check(result, gc.Equals, test.result) |
230 | - c.Check(msg, gc.Equals, test.msg) |
231 | - } |
232 | -} |
233 | - |
234 | -func (s *BoolSuite) TestDeepEquals(c *gc.C) { |
235 | - for i, test := range deepEqualTests { |
236 | - c.Logf("test %d. %v == %v is %v", i, test.a, test.b, test.eq) |
237 | - result, msg := jc.DeepEquals.Check([]interface{}{test.a, test.b}, nil) |
238 | - c.Check(result, gc.Equals, test.eq) |
239 | - if test.eq { |
240 | - c.Check(msg, gc.Equals, "") |
241 | - } else { |
242 | - c.Check(msg, gc.Not(gc.Equals), "") |
243 | - } |
244 | - } |
245 | -} |
246 | |
247 | === removed file 'testing/checkers/checker.go' |
248 | --- testing/checkers/checker.go 2013-09-13 14:48:13 +0000 |
249 | +++ testing/checkers/checker.go 1970-01-01 00:00:00 +0000 |
250 | @@ -1,202 +0,0 @@ |
251 | -// Copyright 2012, 2013 Canonical Ltd. |
252 | -// Licensed under the AGPLv3, see LICENCE file for details. |
253 | - |
254 | -package checkers |
255 | - |
256 | -import ( |
257 | - "fmt" |
258 | - "reflect" |
259 | - "strings" |
260 | - "time" |
261 | - |
262 | - gc "launchpad.net/gocheck" |
263 | -) |
264 | - |
265 | -func TimeBetween(start, end time.Time) gc.Checker { |
266 | - if end.Before(start) { |
267 | - return &timeBetweenChecker{end, start} |
268 | - } |
269 | - return &timeBetweenChecker{start, end} |
270 | -} |
271 | - |
272 | -type timeBetweenChecker struct { |
273 | - start, end time.Time |
274 | -} |
275 | - |
276 | -func (checker *timeBetweenChecker) Info() *gc.CheckerInfo { |
277 | - info := gc.CheckerInfo{ |
278 | - Name: "TimeBetween", |
279 | - Params: []string{"obtained"}, |
280 | - } |
281 | - return &info |
282 | -} |
283 | - |
284 | -func (checker *timeBetweenChecker) Check(params []interface{}, names []string) (result bool, error string) { |
285 | - when, ok := params[0].(time.Time) |
286 | - if !ok { |
287 | - return false, "obtained value type must be time.Time" |
288 | - } |
289 | - if when.Before(checker.start) { |
290 | - return false, fmt.Sprintf("obtained value %#v type must before start value of %#v", when, checker.start) |
291 | - } |
292 | - if when.After(checker.end) { |
293 | - return false, fmt.Sprintf("obtained value %#v type must after end value of %#v", when, checker.end) |
294 | - } |
295 | - return true, "" |
296 | -} |
297 | - |
298 | -// DurationLessThan checker |
299 | - |
300 | -type durationLessThanChecker struct { |
301 | - *gc.CheckerInfo |
302 | -} |
303 | - |
304 | -var DurationLessThan gc.Checker = &durationLessThanChecker{ |
305 | - &gc.CheckerInfo{Name: "DurationLessThan", Params: []string{"obtained", "expected"}}, |
306 | -} |
307 | - |
308 | -func (checker *durationLessThanChecker) Check(params []interface{}, names []string) (result bool, error string) { |
309 | - obtained, ok := params[0].(time.Duration) |
310 | - if !ok { |
311 | - return false, "obtained value type must be time.Duration" |
312 | - } |
313 | - expected, ok := params[1].(time.Duration) |
314 | - if !ok { |
315 | - return false, "expected value type must be time.Duration" |
316 | - } |
317 | - return obtained.Nanoseconds() < expected.Nanoseconds(), "" |
318 | -} |
319 | - |
320 | -// HasPrefix checker for checking strings |
321 | - |
322 | -func stringOrStringer(value interface{}) (string, bool) { |
323 | - result, isString := value.(string) |
324 | - if !isString { |
325 | - if stringer, isStringer := value.(fmt.Stringer); isStringer { |
326 | - result, isString = stringer.String(), true |
327 | - } |
328 | - } |
329 | - return result, isString |
330 | -} |
331 | - |
332 | -type hasPrefixChecker struct { |
333 | - *gc.CheckerInfo |
334 | -} |
335 | - |
336 | -var HasPrefix gc.Checker = &hasPrefixChecker{ |
337 | - &gc.CheckerInfo{Name: "HasPrefix", Params: []string{"obtained", "expected"}}, |
338 | -} |
339 | - |
340 | -func (checker *hasPrefixChecker) Check(params []interface{}, names []string) (result bool, error string) { |
341 | - expected, ok := params[1].(string) |
342 | - if !ok { |
343 | - return false, "expected must be a string" |
344 | - } |
345 | - |
346 | - obtained, isString := stringOrStringer(params[0]) |
347 | - if isString { |
348 | - return strings.HasPrefix(obtained, expected), "" |
349 | - } |
350 | - |
351 | - return false, "Obtained value is not a string and has no .String()" |
352 | -} |
353 | - |
354 | -type hasSuffixChecker struct { |
355 | - *gc.CheckerInfo |
356 | -} |
357 | - |
358 | -var HasSuffix gc.Checker = &hasSuffixChecker{ |
359 | - &gc.CheckerInfo{Name: "HasSuffix", Params: []string{"obtained", "expected"}}, |
360 | -} |
361 | - |
362 | -func (checker *hasSuffixChecker) Check(params []interface{}, names []string) (result bool, error string) { |
363 | - expected, ok := params[1].(string) |
364 | - if !ok { |
365 | - return false, "expected must be a string" |
366 | - } |
367 | - |
368 | - obtained, isString := stringOrStringer(params[0]) |
369 | - if isString { |
370 | - return strings.HasSuffix(obtained, expected), "" |
371 | - } |
372 | - |
373 | - return false, "Obtained value is not a string and has no .String()" |
374 | -} |
375 | - |
376 | -type containsChecker struct { |
377 | - *gc.CheckerInfo |
378 | -} |
379 | - |
380 | -var Contains gc.Checker = &containsChecker{ |
381 | - &gc.CheckerInfo{Name: "Contains", Params: []string{"obtained", "expected"}}, |
382 | -} |
383 | - |
384 | -func (checker *containsChecker) Check(params []interface{}, names []string) (result bool, error string) { |
385 | - expected, ok := params[1].(string) |
386 | - if !ok { |
387 | - return false, "expected must be a string" |
388 | - } |
389 | - |
390 | - obtained, isString := stringOrStringer(params[0]) |
391 | - if isString { |
392 | - return strings.Contains(obtained, expected), "" |
393 | - } |
394 | - |
395 | - return false, "Obtained value is not a string and has no .String()" |
396 | -} |
397 | - |
398 | -type sameContents struct { |
399 | - *gc.CheckerInfo |
400 | -} |
401 | - |
402 | -// SameContents checks that the obtained slice contains all the values (and |
403 | -// same number of values) of the expected slice and vice versa, without respect |
404 | -// to order or duplicates. Uses DeepEquals on mapped contents to compare. |
405 | -var SameContents gc.Checker = &sameContents{ |
406 | - &gc.CheckerInfo{Name: "SameContents", Params: []string{"obtained", "expected"}}, |
407 | -} |
408 | - |
409 | -func (checker *sameContents) Check(params []interface{}, names []string) (result bool, error string) { |
410 | - if len(params) != 2 { |
411 | - return false, "SameContents expects two slice arguments" |
412 | - } |
413 | - obtained := params[0] |
414 | - expected := params[1] |
415 | - |
416 | - tob := reflect.TypeOf(obtained) |
417 | - if tob.Kind() != reflect.Slice { |
418 | - return false, fmt.Sprintf("SameContents expects the obtained value to be a slice, got %q", |
419 | - tob.Kind()) |
420 | - } |
421 | - |
422 | - texp := reflect.TypeOf(expected) |
423 | - if texp.Kind() != reflect.Slice { |
424 | - return false, fmt.Sprintf("SameContents expects the expected value to be a slice, got %q", |
425 | - texp.Kind()) |
426 | - } |
427 | - |
428 | - if texp != tob { |
429 | - return false, fmt.Sprintf( |
430 | - "SameContents expects two slices of the same type, expected: %q, got: %q", |
431 | - texp, tob) |
432 | - } |
433 | - |
434 | - vexp := reflect.ValueOf(expected) |
435 | - vob := reflect.ValueOf(obtained) |
436 | - length := vexp.Len() |
437 | - |
438 | - if vob.Len() != length { |
439 | - // Slice has incorrect number of elements |
440 | - return false, "" |
441 | - } |
442 | - |
443 | - // spin up maps with the entries as keys and the counts as values |
444 | - mob := make(map[interface{}]int, length) |
445 | - mexp := make(map[interface{}]int, length) |
446 | - |
447 | - for i := 0; i < length; i++ { |
448 | - mexp[vexp.Index(i).Interface()]++ |
449 | - mob[vob.Index(i).Interface()]++ |
450 | - } |
451 | - return reflect.DeepEqual(mob, mexp), "" |
452 | -} |
453 | |
454 | === removed file 'testing/checkers/checker_test.go' |
455 | --- testing/checkers/checker_test.go 2014-03-13 07:54:56 +0000 |
456 | +++ testing/checkers/checker_test.go 1970-01-01 00:00:00 +0000 |
457 | @@ -1,119 +0,0 @@ |
458 | -// Copyright 2013 Canonical Ltd. |
459 | -// Licensed under the AGPLv3, see LICENCE file for details. |
460 | - |
461 | -package checkers_test |
462 | - |
463 | -import ( |
464 | - "testing" |
465 | - |
466 | - jc "github.com/juju/testing/checkers" |
467 | - gc "launchpad.net/gocheck" |
468 | -) |
469 | - |
470 | -func Test(t *testing.T) { gc.TestingT(t) } |
471 | - |
472 | -type CheckerSuite struct{} |
473 | - |
474 | -var _ = gc.Suite(&CheckerSuite{}) |
475 | - |
476 | -func (s *CheckerSuite) TestHasPrefix(c *gc.C) { |
477 | - c.Assert("foo bar", jc.HasPrefix, "foo") |
478 | - c.Assert("foo bar", gc.Not(jc.HasPrefix), "omg") |
479 | -} |
480 | - |
481 | -func (s *CheckerSuite) TestHasSuffix(c *gc.C) { |
482 | - c.Assert("foo bar", jc.HasSuffix, "bar") |
483 | - c.Assert("foo bar", gc.Not(jc.HasSuffix), "omg") |
484 | -} |
485 | - |
486 | -func (s *CheckerSuite) TestContains(c *gc.C) { |
487 | - c.Assert("foo bar baz", jc.Contains, "foo") |
488 | - c.Assert("foo bar baz", jc.Contains, "bar") |
489 | - c.Assert("foo bar baz", jc.Contains, "baz") |
490 | - c.Assert("foo bar baz", gc.Not(jc.Contains), "omg") |
491 | -} |
492 | - |
493 | -func (s *CheckerSuite) TestSameContents(c *gc.C) { |
494 | - //// positive cases //// |
495 | - |
496 | - // same |
497 | - c.Check( |
498 | - []int{1, 2, 3}, jc.SameContents, |
499 | - []int{1, 2, 3}) |
500 | - |
501 | - // empty |
502 | - c.Check( |
503 | - []int{}, jc.SameContents, |
504 | - []int{}) |
505 | - |
506 | - // single |
507 | - c.Check( |
508 | - []int{1}, jc.SameContents, |
509 | - []int{1}) |
510 | - |
511 | - // different order |
512 | - c.Check( |
513 | - []int{1, 2, 3}, jc.SameContents, |
514 | - []int{3, 2, 1}) |
515 | - |
516 | - // multiple copies of same |
517 | - c.Check( |
518 | - []int{1, 1, 2}, jc.SameContents, |
519 | - []int{2, 1, 1}) |
520 | - |
521 | - type test struct { |
522 | - s string |
523 | - i int |
524 | - } |
525 | - |
526 | - // test structs |
527 | - c.Check( |
528 | - []test{{"a", 1}, {"b", 2}}, jc.SameContents, |
529 | - []test{{"b", 2}, {"a", 1}}) |
530 | - |
531 | - //// negative cases //// |
532 | - |
533 | - // different contents |
534 | - c.Check( |
535 | - []int{1, 3, 2, 5}, gc.Not(jc.SameContents), |
536 | - []int{5, 2, 3, 4}) |
537 | - |
538 | - // different size slices |
539 | - c.Check( |
540 | - []int{1, 2, 3}, gc.Not(jc.SameContents), |
541 | - []int{1, 2}) |
542 | - |
543 | - // different counts of same items |
544 | - c.Check( |
545 | - []int{1, 1, 2}, gc.Not(jc.SameContents), |
546 | - []int{1, 2, 2}) |
547 | - |
548 | - /// Error cases /// |
549 | - // note: for these tests, we can't use gc.Not, since Not passes the error value through |
550 | - // and checks with a non-empty error always count as failed |
551 | - // Oddly, there doesn't seem to actually be a way to check for an error from a Checker. |
552 | - |
553 | - // different type |
554 | - res, err := jc.SameContents.Check([]interface{}{ |
555 | - []string{"1", "2"}, |
556 | - []int{1, 2}, |
557 | - }, []string{}) |
558 | - c.Check(res, jc.IsFalse) |
559 | - c.Check(err, gc.Not(gc.Equals), "") |
560 | - |
561 | - // obtained not a slice |
562 | - res, err = jc.SameContents.Check([]interface{}{ |
563 | - "test", |
564 | - []int{1}, |
565 | - }, []string{}) |
566 | - c.Check(res, jc.IsFalse) |
567 | - c.Check(err, gc.Not(gc.Equals), "") |
568 | - |
569 | - // expected not a slice |
570 | - res, err = jc.SameContents.Check([]interface{}{ |
571 | - []int{1}, |
572 | - "test", |
573 | - }, []string{}) |
574 | - c.Check(res, jc.IsFalse) |
575 | - c.Check(err, gc.Not(gc.Equals), "") |
576 | -} |
577 | |
578 | === removed file 'testing/checkers/deepequal.go' |
579 | --- testing/checkers/deepequal.go 2014-01-13 16:04:29 +0000 |
580 | +++ testing/checkers/deepequal.go 1970-01-01 00:00:00 +0000 |
581 | @@ -1,303 +0,0 @@ |
582 | -// Copied with small adaptations from the reflect package in the |
583 | -// Go source tree. |
584 | - |
585 | -// Copyright 2009 The Go Authors. All rights reserved. |
586 | -// Use of this source code is governed by a BSD-style |
587 | -// license that can be found in the LICENSE file. |
588 | - |
589 | -package checkers |
590 | - |
591 | -import ( |
592 | - "fmt" |
593 | - "reflect" |
594 | - "unsafe" |
595 | -) |
596 | - |
597 | -// During deepValueEqual, must keep track of checks that are |
598 | -// in progress. The comparison algorithm assumes that all |
599 | -// checks in progress are true when it reencounters them. |
600 | -// Visited comparisons are stored in a map indexed by visit. |
601 | -type visit struct { |
602 | - a1 uintptr |
603 | - a2 uintptr |
604 | - typ reflect.Type |
605 | -} |
606 | - |
607 | -type mismatchError struct { |
608 | - v1, v2 reflect.Value |
609 | - path string |
610 | - how string |
611 | -} |
612 | - |
613 | -func (err *mismatchError) Error() string { |
614 | - path := err.path |
615 | - if path == "" { |
616 | - path = "top level" |
617 | - } |
618 | - return fmt.Sprintf("mismatch at %s: %s; obtained %#v; expected %#v", path, err.how, interfaceOf(err.v1), interfaceOf(err.v2)) |
619 | -} |
620 | - |
621 | -// Tests for deep equality using reflected types. The map argument tracks |
622 | -// comparisons that have already been seen, which allows short circuiting on |
623 | -// recursive types. |
624 | -func deepValueEqual(path string, v1, v2 reflect.Value, visited map[visit]bool, depth int) (ok bool, err error) { |
625 | - errorf := func(f string, a ...interface{}) error { |
626 | - return &mismatchError{ |
627 | - v1: v1, |
628 | - v2: v2, |
629 | - path: path, |
630 | - how: fmt.Sprintf(f, a...), |
631 | - } |
632 | - } |
633 | - if !v1.IsValid() || !v2.IsValid() { |
634 | - if v1.IsValid() == v2.IsValid() { |
635 | - return true, nil |
636 | - } |
637 | - return false, errorf("validity mismatch") |
638 | - } |
639 | - if v1.Type() != v2.Type() { |
640 | - return false, errorf("type mismatch %s vs %s", v1.Type(), v2.Type()) |
641 | - } |
642 | - |
643 | - // if depth > 10 { panic("deepValueEqual") } // for debugging |
644 | - hard := func(k reflect.Kind) bool { |
645 | - switch k { |
646 | - case reflect.Array, reflect.Map, reflect.Slice, reflect.Struct: |
647 | - return true |
648 | - } |
649 | - return false |
650 | - } |
651 | - |
652 | - if v1.CanAddr() && v2.CanAddr() && hard(v1.Kind()) { |
653 | - addr1 := v1.UnsafeAddr() |
654 | - addr2 := v2.UnsafeAddr() |
655 | - if addr1 > addr2 { |
656 | - // Canonicalize order to reduce number of entries in visited. |
657 | - addr1, addr2 = addr2, addr1 |
658 | - } |
659 | - |
660 | - // Short circuit if references are identical ... |
661 | - if addr1 == addr2 { |
662 | - return true, nil |
663 | - } |
664 | - |
665 | - // ... or already seen |
666 | - typ := v1.Type() |
667 | - v := visit{addr1, addr2, typ} |
668 | - if visited[v] { |
669 | - return true, nil |
670 | - } |
671 | - |
672 | - // Remember for later. |
673 | - visited[v] = true |
674 | - } |
675 | - |
676 | - switch v1.Kind() { |
677 | - case reflect.Array: |
678 | - if v1.Len() != v2.Len() { |
679 | - // can't happen! |
680 | - return false, errorf("length mismatch, %d vs %d", v1.Len(), v2.Len()) |
681 | - } |
682 | - for i := 0; i < v1.Len(); i++ { |
683 | - if ok, err := deepValueEqual( |
684 | - fmt.Sprintf("%s[%d]", path, i), |
685 | - v1.Index(i), v2.Index(i), visited, depth+1); !ok { |
686 | - return false, err |
687 | - } |
688 | - } |
689 | - return true, nil |
690 | - case reflect.Slice: |
691 | - // We treat a nil slice the same as an empty slice. |
692 | - if v1.Len() != v2.Len() { |
693 | - return false, errorf("length mismatch, %d vs %d", v1.Len(), v2.Len()) |
694 | - } |
695 | - if v1.Pointer() == v2.Pointer() { |
696 | - return true, nil |
697 | - } |
698 | - for i := 0; i < v1.Len(); i++ { |
699 | - if ok, err := deepValueEqual( |
700 | - fmt.Sprintf("%s[%d]", path, i), |
701 | - v1.Index(i), v2.Index(i), visited, depth+1); !ok { |
702 | - return false, err |
703 | - } |
704 | - } |
705 | - return true, nil |
706 | - case reflect.Interface: |
707 | - if v1.IsNil() || v2.IsNil() { |
708 | - if v1.IsNil() != v2.IsNil() { |
709 | - return false, fmt.Errorf("nil vs non-nil interface mismatch") |
710 | - } |
711 | - return true, nil |
712 | - } |
713 | - return deepValueEqual(path, v1.Elem(), v2.Elem(), visited, depth+1) |
714 | - case reflect.Ptr: |
715 | - return deepValueEqual("(*"+path+")", v1.Elem(), v2.Elem(), visited, depth+1) |
716 | - case reflect.Struct: |
717 | - for i, n := 0, v1.NumField(); i < n; i++ { |
718 | - path := path + "." + v1.Type().Field(i).Name |
719 | - if ok, err := deepValueEqual(path, v1.Field(i), v2.Field(i), visited, depth+1); !ok { |
720 | - return false, err |
721 | - } |
722 | - } |
723 | - return true, nil |
724 | - case reflect.Map: |
725 | - if v1.IsNil() != v2.IsNil() { |
726 | - return false, errorf("nil vs non-nil mismatch") |
727 | - } |
728 | - if v1.Len() != v2.Len() { |
729 | - return false, errorf("length mismatch, %d vs %d", v1.Len(), v2.Len()) |
730 | - } |
731 | - if v1.Pointer() == v2.Pointer() { |
732 | - return true, nil |
733 | - } |
734 | - for _, k := range v1.MapKeys() { |
735 | - var p string |
736 | - if k.CanInterface() { |
737 | - p = path + "[" + fmt.Sprintf("%#v", k.Interface()) + "]" |
738 | - } else { |
739 | - p = path + "[someKey]" |
740 | - } |
741 | - if ok, err := deepValueEqual(p, v1.MapIndex(k), v2.MapIndex(k), visited, depth+1); !ok { |
742 | - return false, err |
743 | - } |
744 | - } |
745 | - return true, nil |
746 | - case reflect.Func: |
747 | - if v1.IsNil() && v2.IsNil() { |
748 | - return true, nil |
749 | - } |
750 | - // Can't do better than this: |
751 | - return false, errorf("non-nil functions") |
752 | - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
753 | - if v1.Int() != v2.Int() { |
754 | - return false, errorf("unequal") |
755 | - } |
756 | - return true, nil |
757 | - case reflect.Uint, reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: |
758 | - if v1.Uint() != v2.Uint() { |
759 | - return false, errorf("unequal") |
760 | - } |
761 | - return true, nil |
762 | - case reflect.Float32, reflect.Float64: |
763 | - if v1.Float() != v2.Float() { |
764 | - return false, errorf("unequal") |
765 | - } |
766 | - return true, nil |
767 | - case reflect.Complex64, reflect.Complex128: |
768 | - if v1.Complex() != v2.Complex() { |
769 | - return false, errorf("unequal") |
770 | - } |
771 | - return true, nil |
772 | - case reflect.Bool: |
773 | - if v1.Bool() != v2.Bool() { |
774 | - return false, errorf("unequal") |
775 | - } |
776 | - return true, nil |
777 | - case reflect.String: |
778 | - if v1.String() != v2.String() { |
779 | - return false, errorf("unequal") |
780 | - } |
781 | - return true, nil |
782 | - case reflect.Chan, reflect.UnsafePointer: |
783 | - if v1.Pointer() != v2.Pointer() { |
784 | - return false, errorf("unequal") |
785 | - } |
786 | - return true, nil |
787 | - default: |
788 | - panic("unexpected type " + v1.Type().String()) |
789 | - } |
790 | -} |
791 | - |
792 | -// DeepEqual tests for deep equality. It uses normal == equality where |
793 | -// possible but will scan elements of arrays, slices, maps, and fields |
794 | -// of structs. In maps, keys are compared with == but elements use deep |
795 | -// equality. DeepEqual correctly handles recursive types. Functions are |
796 | -// equal only if they are both nil. |
797 | -// |
798 | -// DeepEqual differs from reflect.DeepEqual in that an empty slice is |
799 | -// equal to a nil slice. If the two values compare unequal, the |
800 | -// resulting error holds the first difference encountered. |
801 | -func DeepEqual(a1, a2 interface{}) (bool, error) { |
802 | - errorf := func(f string, a ...interface{}) error { |
803 | - return &mismatchError{ |
804 | - v1: reflect.ValueOf(a1), |
805 | - v2: reflect.ValueOf(a2), |
806 | - path: "", |
807 | - how: fmt.Sprintf(f, a...), |
808 | - } |
809 | - } |
810 | - if a1 == nil || a2 == nil { |
811 | - if a1 == a2 { |
812 | - return true, nil |
813 | - } |
814 | - return false, errorf("nil vs non-nil mismatch") |
815 | - } |
816 | - v1 := reflect.ValueOf(a1) |
817 | - v2 := reflect.ValueOf(a2) |
818 | - if v1.Type() != v2.Type() { |
819 | - return false, errorf("type mismatch %s vs %s", v1.Type(), v2.Type()) |
820 | - } |
821 | - return deepValueEqual("", v1, v2, make(map[visit]bool), 0) |
822 | -} |
823 | - |
824 | -// interfaceOf returns v.Interface() even if v.CanInterface() == false. |
825 | -// This enables us to call fmt.Printf on a value even if it's derived |
826 | -// from inside an unexported field. |
827 | -func interfaceOf(v reflect.Value) interface{} { |
828 | - if !v.IsValid() { |
829 | - return nil |
830 | - } |
831 | - return bypassCanInterface(v).Interface() |
832 | -} |
833 | - |
834 | -type flag uintptr |
835 | - |
836 | -// copied from reflect/value.go |
837 | -const ( |
838 | - flagRO flag = 1 << iota |
839 | -) |
840 | - |
841 | -var flagValOffset = func() uintptr { |
842 | - field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") |
843 | - if !ok { |
844 | - panic("reflect.Value has no flag field") |
845 | - } |
846 | - return field.Offset |
847 | -}() |
848 | - |
849 | -func flagField(v *reflect.Value) *flag { |
850 | - return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset)) |
851 | -} |
852 | - |
853 | -// bypassCanInterface returns a version of v that |
854 | -// bypasses the CanInterface check. |
855 | -func bypassCanInterface(v reflect.Value) reflect.Value { |
856 | - if !v.IsValid() || v.CanInterface() { |
857 | - return v |
858 | - } |
859 | - *flagField(&v) &^= flagRO |
860 | - return v |
861 | -} |
862 | - |
863 | -// Sanity checks against future reflect package changes |
864 | -// to the type or semantics of the Value.flag field. |
865 | -func init() { |
866 | - field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") |
867 | - if !ok { |
868 | - panic("reflect.Value has no flag field") |
869 | - } |
870 | - if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { |
871 | - panic("reflect.Value flag field has changed kind") |
872 | - } |
873 | - var t struct { |
874 | - a int |
875 | - A int |
876 | - } |
877 | - vA := reflect.ValueOf(t).FieldByName("A") |
878 | - va := reflect.ValueOf(t).FieldByName("a") |
879 | - flagA := *flagField(&vA) |
880 | - flaga := *flagField(&va) |
881 | - if flagA&flagRO != 0 || flaga&flagRO == 0 { |
882 | - panic("reflect.Value read-only flag has changed value") |
883 | - } |
884 | -} |
885 | |
886 | === removed file 'testing/checkers/deepequal_test.go' |
887 | --- testing/checkers/deepequal_test.go 2014-03-13 07:54:56 +0000 |
888 | +++ testing/checkers/deepequal_test.go 1970-01-01 00:00:00 +0000 |
889 | @@ -1,171 +0,0 @@ |
890 | -// Copied with small adaptations from the reflect package in the |
891 | -// Go source tree. We use testing rather than gocheck to preserve |
892 | -// as much source equivalence as possible. |
893 | - |
894 | -// TODO tests for error messages |
895 | - |
896 | -// Copyright 2009 The Go Authors. All rights reserved. |
897 | -// Use of this source code is governed by a BSD-style |
898 | -// license that can be found in the LICENSE file. |
899 | - |
900 | -package checkers_test |
901 | - |
902 | -import ( |
903 | - "regexp" |
904 | - "testing" |
905 | - |
906 | - "github.com/juju/testing/checkers" |
907 | -) |
908 | - |
909 | -func deepEqual(a1, a2 interface{}) bool { |
910 | - ok, _ := checkers.DeepEqual(a1, a2) |
911 | - return ok |
912 | -} |
913 | - |
914 | -type Basic struct { |
915 | - x int |
916 | - y float32 |
917 | -} |
918 | - |
919 | -type NotBasic Basic |
920 | - |
921 | -type DeepEqualTest struct { |
922 | - a, b interface{} |
923 | - eq bool |
924 | - msg string |
925 | -} |
926 | - |
927 | -// Simple functions for DeepEqual tests. |
928 | -var ( |
929 | - fn1 func() // nil. |
930 | - fn2 func() // nil. |
931 | - fn3 = func() { fn1() } // Not nil. |
932 | -) |
933 | - |
934 | -var deepEqualTests = []DeepEqualTest{ |
935 | - // Equalities |
936 | - {nil, nil, true, ""}, |
937 | - {1, 1, true, ""}, |
938 | - {int32(1), int32(1), true, ""}, |
939 | - {0.5, 0.5, true, ""}, |
940 | - {float32(0.5), float32(0.5), true, ""}, |
941 | - {"hello", "hello", true, ""}, |
942 | - {make([]int, 10), make([]int, 10), true, ""}, |
943 | - {&[3]int{1, 2, 3}, &[3]int{1, 2, 3}, true, ""}, |
944 | - {Basic{1, 0.5}, Basic{1, 0.5}, true, ""}, |
945 | - {error(nil), error(nil), true, ""}, |
946 | - {map[int]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, true, ""}, |
947 | - {fn1, fn2, true, ""}, |
948 | - |
949 | - // Inequalities |
950 | - {1, 2, false, `mismatch at top level: unequal; obtained 1; expected 2`}, |
951 | - {int32(1), int32(2), false, `mismatch at top level: unequal; obtained 1; expected 2`}, |
952 | - {0.5, 0.6, false, `mismatch at top level: unequal; obtained 0\.5; expected 0\.6`}, |
953 | - {float32(0.5), float32(0.6), false, `mismatch at top level: unequal; obtained 0\.5; expected 0\.6`}, |
954 | - {"hello", "hey", false, `mismatch at top level: unequal; obtained "hello"; expected "hey"`}, |
955 | - {make([]int, 10), make([]int, 11), false, `mismatch at top level: length mismatch, 10 vs 11; obtained \[\]int\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\}; expected \[\]int\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\}`}, |
956 | - {&[3]int{1, 2, 3}, &[3]int{1, 2, 4}, false, `mismatch at \(\*\)\[2\]: unequal; obtained 3; expected 4`}, |
957 | - {Basic{1, 0.5}, Basic{1, 0.6}, false, `mismatch at \.y: unequal; obtained 0\.5; expected 0\.6`}, |
958 | - {Basic{1, 0}, Basic{2, 0}, false, `mismatch at \.x: unequal; obtained 1; expected 2`}, |
959 | - {map[int]string{1: "one", 3: "two"}, map[int]string{2: "two", 1: "one"}, false, `mismatch at \[3\]: validity mismatch; obtained "two"; expected <nil>`}, |
960 | - {map[int]string{1: "one", 2: "txo"}, map[int]string{2: "two", 1: "one"}, false, `mismatch at \[2\]: unequal; obtained "txo"; expected "two"`}, |
961 | - {map[int]string{1: "one"}, map[int]string{2: "two", 1: "one"}, false, `mismatch at top level: length mismatch, 1 vs 2; obtained map\[int\]string\{1:"one"\}; expected map\[int\]string\{2:"two", 1:"one"\}`}, |
962 | - {map[int]string{2: "two", 1: "one"}, map[int]string{1: "one"}, false, `mismatch at top level: length mismatch, 2 vs 1; obtained map\[int\]string\{2:"two", 1:"one"\}; expected map\[int\]string\{1:"one"\}`}, |
963 | - {nil, 1, false, `mismatch at top level: nil vs non-nil mismatch; obtained <nil>; expected 1`}, |
964 | - {1, nil, false, `mismatch at top level: nil vs non-nil mismatch; obtained 1; expected <nil>`}, |
965 | - {fn1, fn3, false, `mismatch at top level: non-nil functions; obtained \(func\(\)\)\(nil\); expected \(func\(\)\)\(0x[0-9a-f]+\)`}, |
966 | - {fn3, fn3, false, `mismatch at top level: non-nil functions; obtained \(func\(\)\)\(0x[0-9a-f]+\); expected \(func\(\)\)\(0x[0-9a-f]+\)`}, |
967 | - |
968 | - // Nil vs empty: they're the same (difference from normal DeepEqual) |
969 | - {[]int{}, []int(nil), true, ""}, |
970 | - {[]int{}, []int{}, true, ""}, |
971 | - {[]int(nil), []int(nil), true, ""}, |
972 | - |
973 | - // Mismatched types |
974 | - {1, 1.0, false, `mismatch at top level: type mismatch int vs float64; obtained 1; expected 1`}, |
975 | - {int32(1), int64(1), false, `mismatch at top level: type mismatch int32 vs int64; obtained 1; expected 1`}, |
976 | - {0.5, "hello", false, `mismatch at top level: type mismatch float64 vs string; obtained 0\.5; expected "hello"`}, |
977 | - {[]int{1, 2, 3}, [3]int{1, 2, 3}, false, `mismatch at top level: type mismatch \[\]int vs \[3\]int; obtained \[\]int\{1, 2, 3\}; expected \[3\]int\{1, 2, 3\}`}, |
978 | - {&[3]interface{}{1, 2, 4}, &[3]interface{}{1, 2, "s"}, false, `mismatch at \(\*\)\[2\]: type mismatch int vs string; obtained 4; expected "s"`}, |
979 | - {Basic{1, 0.5}, NotBasic{1, 0.5}, false, `mismatch at top level: type mismatch checkers_test\.Basic vs checkers_test\.NotBasic; obtained checkers_test\.Basic\{x:1, y:0\.5\}; expected checkers_test\.NotBasic\{x:1, y:0\.5\}`}, |
980 | - {map[uint]string{1: "one", 2: "two"}, map[int]string{2: "two", 1: "one"}, false, `mismatch at top level: type mismatch map\[uint\]string vs map\[int\]string; obtained map\[uint\]string\{0x1:"one", 0x2:"two"\}; expected map\[int\]string\{2:"two", 1:"one"\}`}, |
981 | -} |
982 | - |
983 | -func TestDeepEqual(t *testing.T) { |
984 | - for _, test := range deepEqualTests { |
985 | - r, err := checkers.DeepEqual(test.a, test.b) |
986 | - if r != test.eq { |
987 | - t.Errorf("deepEqual(%v, %v) = %v, want %v", test.a, test.b, r, test.eq) |
988 | - } |
989 | - if test.eq { |
990 | - if err != nil { |
991 | - t.Errorf("deepEqual(%v, %v): unexpected error message %q when equal", test.a, test.b, err) |
992 | - } |
993 | - } else { |
994 | - if ok, _ := regexp.MatchString(test.msg, err.Error()); !ok { |
995 | - t.Errorf("deepEqual(%v, %v); unexpected error %q, want %q", test.a, test.b, err.Error(), test.msg) |
996 | - } |
997 | - } |
998 | - } |
999 | -} |
1000 | - |
1001 | -type Recursive struct { |
1002 | - x int |
1003 | - r *Recursive |
1004 | -} |
1005 | - |
1006 | -func TestDeepEqualRecursiveStruct(t *testing.T) { |
1007 | - a, b := new(Recursive), new(Recursive) |
1008 | - *a = Recursive{12, a} |
1009 | - *b = Recursive{12, b} |
1010 | - if !deepEqual(a, b) { |
1011 | - t.Error("deepEqual(recursive same) = false, want true") |
1012 | - } |
1013 | -} |
1014 | - |
1015 | -type _Complex struct { |
1016 | - a int |
1017 | - b [3]*_Complex |
1018 | - c *string |
1019 | - d map[float64]float64 |
1020 | -} |
1021 | - |
1022 | -func TestDeepEqualComplexStruct(t *testing.T) { |
1023 | - m := make(map[float64]float64) |
1024 | - stra, strb := "hello", "hello" |
1025 | - a, b := new(_Complex), new(_Complex) |
1026 | - *a = _Complex{5, [3]*_Complex{a, b, a}, &stra, m} |
1027 | - *b = _Complex{5, [3]*_Complex{b, a, a}, &strb, m} |
1028 | - if !deepEqual(a, b) { |
1029 | - t.Error("deepEqual(complex same) = false, want true") |
1030 | - } |
1031 | -} |
1032 | - |
1033 | -func TestDeepEqualComplexStructInequality(t *testing.T) { |
1034 | - m := make(map[float64]float64) |
1035 | - stra, strb := "hello", "helloo" // Difference is here |
1036 | - a, b := new(_Complex), new(_Complex) |
1037 | - *a = _Complex{5, [3]*_Complex{a, b, a}, &stra, m} |
1038 | - *b = _Complex{5, [3]*_Complex{b, a, a}, &strb, m} |
1039 | - if deepEqual(a, b) { |
1040 | - t.Error("deepEqual(complex different) = true, want false") |
1041 | - } |
1042 | -} |
1043 | - |
1044 | -type UnexpT struct { |
1045 | - m map[int]int |
1046 | -} |
1047 | - |
1048 | -func TestDeepEqualUnexportedMap(t *testing.T) { |
1049 | - // Check that DeepEqual can look at unexported fields. |
1050 | - x1 := UnexpT{map[int]int{1: 2}} |
1051 | - x2 := UnexpT{map[int]int{1: 2}} |
1052 | - if !deepEqual(&x1, &x2) { |
1053 | - t.Error("deepEqual(x1, x2) = false, want true") |
1054 | - } |
1055 | - |
1056 | - y1 := UnexpT{map[int]int{2: 3}} |
1057 | - if deepEqual(&x1, &y1) { |
1058 | - t.Error("deepEqual(x1, y1) = true, want false") |
1059 | - } |
1060 | -} |
1061 | |
1062 | === removed file 'testing/checkers/file.go' |
1063 | --- testing/checkers/file.go 2013-10-01 21:20:11 +0000 |
1064 | +++ testing/checkers/file.go 1970-01-01 00:00:00 +0000 |
1065 | @@ -1,154 +0,0 @@ |
1066 | -// Copyright 2013 Canonical Ltd. |
1067 | -// Licensed under the AGPLv3, see LICENCE file for details. |
1068 | - |
1069 | -package checkers |
1070 | - |
1071 | -import ( |
1072 | - "fmt" |
1073 | - "os" |
1074 | - "reflect" |
1075 | - |
1076 | - gc "launchpad.net/gocheck" |
1077 | -) |
1078 | - |
1079 | -// IsNonEmptyFile checker |
1080 | - |
1081 | -type isNonEmptyFileChecker struct { |
1082 | - *gc.CheckerInfo |
1083 | -} |
1084 | - |
1085 | -var IsNonEmptyFile gc.Checker = &isNonEmptyFileChecker{ |
1086 | - &gc.CheckerInfo{Name: "IsNonEmptyFile", Params: []string{"obtained"}}, |
1087 | -} |
1088 | - |
1089 | -func (checker *isNonEmptyFileChecker) Check(params []interface{}, names []string) (result bool, error string) { |
1090 | - filename, isString := stringOrStringer(params[0]) |
1091 | - if isString { |
1092 | - fileInfo, err := os.Stat(filename) |
1093 | - if os.IsNotExist(err) { |
1094 | - return false, fmt.Sprintf("%s does not exist", filename) |
1095 | - } else if err != nil { |
1096 | - return false, fmt.Sprintf("other stat error: %v", err) |
1097 | - } |
1098 | - if fileInfo.Size() > 0 { |
1099 | - return true, "" |
1100 | - } else { |
1101 | - return false, fmt.Sprintf("%s is empty", filename) |
1102 | - } |
1103 | - } |
1104 | - |
1105 | - value := reflect.ValueOf(params[0]) |
1106 | - return false, fmt.Sprintf("obtained value is not a string and has no .String(), %s:%#v", value.Kind(), params[0]) |
1107 | -} |
1108 | - |
1109 | -// IsDirectory checker |
1110 | - |
1111 | -type isDirectoryChecker struct { |
1112 | - *gc.CheckerInfo |
1113 | -} |
1114 | - |
1115 | -var IsDirectory gc.Checker = &isDirectoryChecker{ |
1116 | - &gc.CheckerInfo{Name: "IsDirectory", Params: []string{"obtained"}}, |
1117 | -} |
1118 | - |
1119 | -func (checker *isDirectoryChecker) Check(params []interface{}, names []string) (result bool, error string) { |
1120 | - path, isString := stringOrStringer(params[0]) |
1121 | - if isString { |
1122 | - fileInfo, err := os.Stat(path) |
1123 | - if os.IsNotExist(err) { |
1124 | - return false, fmt.Sprintf("%s does not exist", path) |
1125 | - } else if err != nil { |
1126 | - return false, fmt.Sprintf("other stat error: %v", err) |
1127 | - } |
1128 | - if fileInfo.IsDir() { |
1129 | - return true, "" |
1130 | - } else { |
1131 | - return false, fmt.Sprintf("%s is not a directory", path) |
1132 | - } |
1133 | - } |
1134 | - |
1135 | - value := reflect.ValueOf(params[0]) |
1136 | - return false, fmt.Sprintf("obtained value is not a string and has no .String(), %s:%#v", value.Kind(), params[0]) |
1137 | -} |
1138 | - |
1139 | -// IsSymlink checker |
1140 | - |
1141 | -type isSymlinkChecker struct { |
1142 | - *gc.CheckerInfo |
1143 | -} |
1144 | - |
1145 | -var IsSymlink gc.Checker = &isSymlinkChecker{ |
1146 | - &gc.CheckerInfo{Name: "IsSymlink", Params: []string{"obtained"}}, |
1147 | -} |
1148 | - |
1149 | -func (checker *isSymlinkChecker) Check(params []interface{}, names []string) (result bool, error string) { |
1150 | - path, isString := stringOrStringer(params[0]) |
1151 | - if isString { |
1152 | - fileInfo, err := os.Lstat(path) |
1153 | - if os.IsNotExist(err) { |
1154 | - return false, fmt.Sprintf("%s does not exist", path) |
1155 | - } else if err != nil { |
1156 | - return false, fmt.Sprintf("other stat error: %v", err) |
1157 | - } |
1158 | - if fileInfo.Mode()&os.ModeSymlink != 0 { |
1159 | - return true, "" |
1160 | - } else { |
1161 | - return false, fmt.Sprintf("%s is not a symlink: %+v", path, fileInfo) |
1162 | - } |
1163 | - } |
1164 | - |
1165 | - value := reflect.ValueOf(params[0]) |
1166 | - return false, fmt.Sprintf("obtained value is not a string and has no .String(), %s:%#v", value.Kind(), params[0]) |
1167 | -} |
1168 | - |
1169 | -// DoesNotExist checker makes sure the path specified doesn't exist. |
1170 | - |
1171 | -type doesNotExistChecker struct { |
1172 | - *gc.CheckerInfo |
1173 | -} |
1174 | - |
1175 | -var DoesNotExist gc.Checker = &doesNotExistChecker{ |
1176 | - &gc.CheckerInfo{Name: "DoesNotExist", Params: []string{"obtained"}}, |
1177 | -} |
1178 | - |
1179 | -func (checker *doesNotExistChecker) Check(params []interface{}, names []string) (result bool, error string) { |
1180 | - path, isString := stringOrStringer(params[0]) |
1181 | - if isString { |
1182 | - _, err := os.Stat(path) |
1183 | - if os.IsNotExist(err) { |
1184 | - return true, "" |
1185 | - } else if err != nil { |
1186 | - return false, fmt.Sprintf("other stat error: %v", err) |
1187 | - } |
1188 | - return false, fmt.Sprintf("%s exists", path) |
1189 | - } |
1190 | - |
1191 | - value := reflect.ValueOf(params[0]) |
1192 | - return false, fmt.Sprintf("obtained value is not a string and has no .String(), %s:%#v", value.Kind(), params[0]) |
1193 | -} |
1194 | - |
1195 | -// SymlinkDoesNotExist checker makes sure the path specified doesn't exist. |
1196 | - |
1197 | -type symlinkDoesNotExistChecker struct { |
1198 | - *gc.CheckerInfo |
1199 | -} |
1200 | - |
1201 | -var SymlinkDoesNotExist gc.Checker = &symlinkDoesNotExistChecker{ |
1202 | - &gc.CheckerInfo{Name: "SymlinkDoesNotExist", Params: []string{"obtained"}}, |
1203 | -} |
1204 | - |
1205 | -func (checker *symlinkDoesNotExistChecker) Check(params []interface{}, names []string) (result bool, error string) { |
1206 | - path, isString := stringOrStringer(params[0]) |
1207 | - if isString { |
1208 | - _, err := os.Lstat(path) |
1209 | - if os.IsNotExist(err) { |
1210 | - return true, "" |
1211 | - } else if err != nil { |
1212 | - return false, fmt.Sprintf("other stat error: %v", err) |
1213 | - } |
1214 | - return false, fmt.Sprintf("%s exists", path) |
1215 | - } |
1216 | - |
1217 | - value := reflect.ValueOf(params[0]) |
1218 | - return false, fmt.Sprintf("obtained value is not a string and has no .String(), %s:%#v", value.Kind(), params[0]) |
1219 | -} |
1220 | |
1221 | === removed file 'testing/checkers/file_test.go' |
1222 | --- testing/checkers/file_test.go 2014-03-13 07:54:56 +0000 |
1223 | +++ testing/checkers/file_test.go 1970-01-01 00:00:00 +0000 |
1224 | @@ -1,165 +0,0 @@ |
1225 | -// Copyright 2013 Canonical Ltd. |
1226 | -// Licensed under the AGPLv3, see LICENCE file for details. |
1227 | - |
1228 | -package checkers_test |
1229 | - |
1230 | -import ( |
1231 | - "fmt" |
1232 | - "io/ioutil" |
1233 | - "os" |
1234 | - "path/filepath" |
1235 | - |
1236 | - jc "github.com/juju/testing/checkers" |
1237 | - gc "launchpad.net/gocheck" |
1238 | -) |
1239 | - |
1240 | -type FileSuite struct{} |
1241 | - |
1242 | -var _ = gc.Suite(&FileSuite{}) |
1243 | - |
1244 | -func (s *FileSuite) TestIsNonEmptyFile(c *gc.C) { |
1245 | - file, err := ioutil.TempFile(c.MkDir(), "") |
1246 | - c.Assert(err, gc.IsNil) |
1247 | - fmt.Fprintf(file, "something") |
1248 | - file.Close() |
1249 | - |
1250 | - c.Assert(file.Name(), jc.IsNonEmptyFile) |
1251 | -} |
1252 | - |
1253 | -func (s *FileSuite) TestIsNonEmptyFileWithEmptyFile(c *gc.C) { |
1254 | - file, err := ioutil.TempFile(c.MkDir(), "") |
1255 | - c.Assert(err, gc.IsNil) |
1256 | - file.Close() |
1257 | - |
1258 | - result, message := jc.IsNonEmptyFile.Check([]interface{}{file.Name()}, nil) |
1259 | - c.Assert(result, jc.IsFalse) |
1260 | - c.Assert(message, gc.Equals, file.Name()+" is empty") |
1261 | -} |
1262 | - |
1263 | -func (s *FileSuite) TestIsNonEmptyFileWithMissingFile(c *gc.C) { |
1264 | - name := filepath.Join(c.MkDir(), "missing") |
1265 | - |
1266 | - result, message := jc.IsNonEmptyFile.Check([]interface{}{name}, nil) |
1267 | - c.Assert(result, jc.IsFalse) |
1268 | - c.Assert(message, gc.Equals, name+" does not exist") |
1269 | -} |
1270 | - |
1271 | -func (s *FileSuite) TestIsNonEmptyFileWithNumber(c *gc.C) { |
1272 | - result, message := jc.IsNonEmptyFile.Check([]interface{}{42}, nil) |
1273 | - c.Assert(result, jc.IsFalse) |
1274 | - c.Assert(message, gc.Equals, "obtained value is not a string and has no .String(), int:42") |
1275 | -} |
1276 | - |
1277 | -func (s *FileSuite) TestIsDirectory(c *gc.C) { |
1278 | - dir := c.MkDir() |
1279 | - c.Assert(dir, jc.IsDirectory) |
1280 | -} |
1281 | - |
1282 | -func (s *FileSuite) TestIsDirectoryMissing(c *gc.C) { |
1283 | - absentDir := filepath.Join(c.MkDir(), "foo") |
1284 | - |
1285 | - result, message := jc.IsDirectory.Check([]interface{}{absentDir}, nil) |
1286 | - c.Assert(result, jc.IsFalse) |
1287 | - c.Assert(message, gc.Equals, absentDir+" does not exist") |
1288 | -} |
1289 | - |
1290 | -func (s *FileSuite) TestIsDirectoryWithFile(c *gc.C) { |
1291 | - file, err := ioutil.TempFile(c.MkDir(), "") |
1292 | - c.Assert(err, gc.IsNil) |
1293 | - file.Close() |
1294 | - |
1295 | - result, message := jc.IsDirectory.Check([]interface{}{file.Name()}, nil) |
1296 | - c.Assert(result, jc.IsFalse) |
1297 | - c.Assert(message, gc.Equals, file.Name()+" is not a directory") |
1298 | -} |
1299 | - |
1300 | -func (s *FileSuite) TestIsDirectoryWithNumber(c *gc.C) { |
1301 | - result, message := jc.IsDirectory.Check([]interface{}{42}, nil) |
1302 | - c.Assert(result, jc.IsFalse) |
1303 | - c.Assert(message, gc.Equals, "obtained value is not a string and has no .String(), int:42") |
1304 | -} |
1305 | - |
1306 | -func (s *FileSuite) TestDoesNotExist(c *gc.C) { |
1307 | - absentDir := filepath.Join(c.MkDir(), "foo") |
1308 | - c.Assert(absentDir, jc.DoesNotExist) |
1309 | -} |
1310 | - |
1311 | -func (s *FileSuite) TestDoesNotExistWithPath(c *gc.C) { |
1312 | - dir := c.MkDir() |
1313 | - result, message := jc.DoesNotExist.Check([]interface{}{dir}, nil) |
1314 | - c.Assert(result, jc.IsFalse) |
1315 | - c.Assert(message, gc.Equals, dir+" exists") |
1316 | -} |
1317 | - |
1318 | -func (s *FileSuite) TestDoesNotExistWithSymlink(c *gc.C) { |
1319 | - dir := c.MkDir() |
1320 | - deadPath := filepath.Join(dir, "dead") |
1321 | - symlinkPath := filepath.Join(dir, "a-symlink") |
1322 | - err := os.Symlink(deadPath, symlinkPath) |
1323 | - c.Assert(err, gc.IsNil) |
1324 | - // A valid symlink pointing to something that doesn't exist passes. |
1325 | - // Use SymlinkDoesNotExist to check for the non-existence of the link itself. |
1326 | - c.Assert(symlinkPath, jc.DoesNotExist) |
1327 | -} |
1328 | - |
1329 | -func (s *FileSuite) TestDoesNotExistWithNumber(c *gc.C) { |
1330 | - result, message := jc.DoesNotExist.Check([]interface{}{42}, nil) |
1331 | - c.Assert(result, jc.IsFalse) |
1332 | - c.Assert(message, gc.Equals, "obtained value is not a string and has no .String(), int:42") |
1333 | -} |
1334 | - |
1335 | -func (s *FileSuite) TestSymlinkDoesNotExist(c *gc.C) { |
1336 | - absentDir := filepath.Join(c.MkDir(), "foo") |
1337 | - c.Assert(absentDir, jc.SymlinkDoesNotExist) |
1338 | -} |
1339 | - |
1340 | -func (s *FileSuite) TestSymlinkDoesNotExistWithPath(c *gc.C) { |
1341 | - dir := c.MkDir() |
1342 | - result, message := jc.SymlinkDoesNotExist.Check([]interface{}{dir}, nil) |
1343 | - c.Assert(result, jc.IsFalse) |
1344 | - c.Assert(message, gc.Equals, dir+" exists") |
1345 | -} |
1346 | - |
1347 | -func (s *FileSuite) TestSymlinkDoesNotExistWithSymlink(c *gc.C) { |
1348 | - dir := c.MkDir() |
1349 | - deadPath := filepath.Join(dir, "dead") |
1350 | - symlinkPath := filepath.Join(dir, "a-symlink") |
1351 | - err := os.Symlink(deadPath, symlinkPath) |
1352 | - c.Assert(err, gc.IsNil) |
1353 | - |
1354 | - result, message := jc.SymlinkDoesNotExist.Check([]interface{}{symlinkPath}, nil) |
1355 | - c.Assert(result, jc.IsFalse) |
1356 | - c.Assert(message, gc.Equals, symlinkPath+" exists") |
1357 | -} |
1358 | - |
1359 | -func (s *FileSuite) TestSymlinkDoesNotExistWithNumber(c *gc.C) { |
1360 | - result, message := jc.SymlinkDoesNotExist.Check([]interface{}{42}, nil) |
1361 | - c.Assert(result, jc.IsFalse) |
1362 | - c.Assert(message, gc.Equals, "obtained value is not a string and has no .String(), int:42") |
1363 | -} |
1364 | - |
1365 | -func (s *FileSuite) TestIsSymlink(c *gc.C) { |
1366 | - file, err := ioutil.TempFile(c.MkDir(), "") |
1367 | - c.Assert(err, gc.IsNil) |
1368 | - c.Log(file.Name()) |
1369 | - c.Log(filepath.Dir(file.Name())) |
1370 | - symlinkPath := filepath.Join(filepath.Dir(file.Name()), "a-symlink") |
1371 | - err = os.Symlink(file.Name(), symlinkPath) |
1372 | - c.Assert(err, gc.IsNil) |
1373 | - |
1374 | - c.Assert(symlinkPath, jc.IsSymlink) |
1375 | -} |
1376 | - |
1377 | -func (s *FileSuite) TestIsSymlinkWithFile(c *gc.C) { |
1378 | - file, err := ioutil.TempFile(c.MkDir(), "") |
1379 | - c.Assert(err, gc.IsNil) |
1380 | - result, message := jc.IsSymlink.Check([]interface{}{file.Name()}, nil) |
1381 | - c.Assert(result, jc.IsFalse) |
1382 | - c.Assert(message, jc.Contains, " is not a symlink") |
1383 | -} |
1384 | - |
1385 | -func (s *FileSuite) TestIsSymlinkWithDir(c *gc.C) { |
1386 | - result, message := jc.IsSymlink.Check([]interface{}{c.MkDir()}, nil) |
1387 | - c.Assert(result, jc.IsFalse) |
1388 | - c.Assert(message, jc.Contains, " is not a symlink") |
1389 | -} |
1390 | |
1391 | === removed file 'testing/checkers/log.go' |
1392 | --- testing/checkers/log.go 2014-03-05 19:41:34 +0000 |
1393 | +++ testing/checkers/log.go 1970-01-01 00:00:00 +0000 |
1394 | @@ -1,109 +0,0 @@ |
1395 | -// Copyright 2012, 2013 Canonical Ltd. |
1396 | -// Licensed under the AGPLv3, see LICENCE file for details. |
1397 | - |
1398 | -package checkers |
1399 | - |
1400 | -import ( |
1401 | - "fmt" |
1402 | - "regexp" |
1403 | - "strings" |
1404 | - |
1405 | - "github.com/juju/loggo" |
1406 | - gc "launchpad.net/gocheck" |
1407 | -) |
1408 | - |
1409 | -type SimpleMessage struct { |
1410 | - Level loggo.Level |
1411 | - Message string |
1412 | -} |
1413 | - |
1414 | -type SimpleMessages []SimpleMessage |
1415 | - |
1416 | -func (s SimpleMessage) String() string { |
1417 | - return fmt.Sprintf("%s %s", s.Level, s.Message) |
1418 | -} |
1419 | - |
1420 | -func (s SimpleMessages) GoString() string { |
1421 | - out := make([]string, len(s)) |
1422 | - for i, m := range s { |
1423 | - out[i] = m.String() |
1424 | - } |
1425 | - return fmt.Sprintf("SimpleMessages{\n%s\n}", strings.Join(out, "\n")) |
1426 | -} |
1427 | - |
1428 | -func logToSimpleMessages(log []loggo.TestLogValues) SimpleMessages { |
1429 | - out := make(SimpleMessages, len(log)) |
1430 | - for i, val := range log { |
1431 | - out[i].Level = val.Level |
1432 | - out[i].Message = val.Message |
1433 | - } |
1434 | - return out |
1435 | -} |
1436 | - |
1437 | -type logMatches struct { |
1438 | - *gc.CheckerInfo |
1439 | -} |
1440 | - |
1441 | -func (checker *logMatches) Check(params []interface{}, names []string) (result bool, error string) { |
1442 | - var obtained SimpleMessages |
1443 | - switch params[0].(type) { |
1444 | - case []loggo.TestLogValues: |
1445 | - obtained = logToSimpleMessages(params[0].([]loggo.TestLogValues)) |
1446 | - default: |
1447 | - return false, "Obtained value must be of type []loggo.TestLogValues or SimpleMessage" |
1448 | - } |
1449 | - |
1450 | - var expected SimpleMessages |
1451 | - switch param := params[1].(type) { |
1452 | - case []SimpleMessage: |
1453 | - expected = SimpleMessages(param) |
1454 | - case SimpleMessages: |
1455 | - expected = param |
1456 | - case []string: |
1457 | - expected = make(SimpleMessages, len(param)) |
1458 | - for i, s := range param { |
1459 | - expected[i] = SimpleMessage{ |
1460 | - Message: s, |
1461 | - Level: loggo.UNSPECIFIED, |
1462 | - } |
1463 | - } |
1464 | - default: |
1465 | - return false, "Expected value must be of type []string or []SimpleMessage" |
1466 | - } |
1467 | - |
1468 | - obtainedSinceLastMatch := obtained |
1469 | - for len(expected) > 0 && len(obtained) >= len(expected) { |
1470 | - var msg SimpleMessage |
1471 | - msg, obtained = obtained[0], obtained[1:] |
1472 | - expect := expected[0] |
1473 | - if expect.Level != loggo.UNSPECIFIED && msg.Level != expect.Level { |
1474 | - continue |
1475 | - } |
1476 | - matched, err := regexp.MatchString(expect.Message, msg.Message) |
1477 | - if err != nil { |
1478 | - return false, fmt.Sprintf("bad message regexp %q: %v", expect.Message, err) |
1479 | - } else if !matched { |
1480 | - continue |
1481 | - } |
1482 | - expected = expected[1:] |
1483 | - obtainedSinceLastMatch = obtained |
1484 | - } |
1485 | - if len(obtained) < len(expected) { |
1486 | - params[0] = obtainedSinceLastMatch |
1487 | - params[1] = expected |
1488 | - return false, "" |
1489 | - } |
1490 | - return true, "" |
1491 | -} |
1492 | - |
1493 | -// LogMatches checks whether a given TestLogValues actually contains the log |
1494 | -// messages we expected. If you compare it against a list of strings, we only |
1495 | -// compare that the strings in the messages are correct. You can alternatively |
1496 | -// pass a slice of SimpleMessage and we will check that the log levels are |
1497 | -// also correct. |
1498 | -// |
1499 | -// The log may contain additional messages before and after each of the specified |
1500 | -// expected messages. |
1501 | -var LogMatches gc.Checker = &logMatches{ |
1502 | - &gc.CheckerInfo{Name: "LogMatches", Params: []string{"obtained", "expected"}}, |
1503 | -} |
1504 | |
1505 | === removed file 'testing/checkers/log_test.go' |
1506 | --- testing/checkers/log_test.go 2014-03-13 07:54:56 +0000 |
1507 | +++ testing/checkers/log_test.go 1970-01-01 00:00:00 +0000 |
1508 | @@ -1,111 +0,0 @@ |
1509 | -// Copyright 2013 Canonical Ltd. |
1510 | -// Licensed under the AGPLv3, see LICENCE file for details. |
1511 | - |
1512 | -package checkers_test |
1513 | - |
1514 | -import ( |
1515 | - "github.com/juju/loggo" |
1516 | - jc "github.com/juju/testing/checkers" |
1517 | - gc "launchpad.net/gocheck" |
1518 | -) |
1519 | - |
1520 | -type LogMatchesSuite struct{} |
1521 | - |
1522 | -var _ = gc.Suite(&LogMatchesSuite{}) |
1523 | - |
1524 | -func (s *LogMatchesSuite) TestMatchSimpleMessage(c *gc.C) { |
1525 | - log := []loggo.TestLogValues{ |
1526 | - {Level: loggo.INFO, Message: "foo bar"}, |
1527 | - {Level: loggo.INFO, Message: "12345"}, |
1528 | - } |
1529 | - c.Check(log, jc.LogMatches, []jc.SimpleMessage{ |
1530 | - {loggo.INFO, "foo bar"}, |
1531 | - {loggo.INFO, "12345"}, |
1532 | - }) |
1533 | - c.Check(log, jc.LogMatches, []jc.SimpleMessage{ |
1534 | - {loggo.INFO, "foo .*"}, |
1535 | - {loggo.INFO, "12345"}, |
1536 | - }) |
1537 | - // UNSPECIFIED means we don't care what the level is, |
1538 | - // just check the message string matches. |
1539 | - c.Check(log, jc.LogMatches, []jc.SimpleMessage{ |
1540 | - {loggo.UNSPECIFIED, "foo .*"}, |
1541 | - {loggo.INFO, "12345"}, |
1542 | - }) |
1543 | - c.Check(log, gc.Not(jc.LogMatches), []jc.SimpleMessage{ |
1544 | - {loggo.INFO, "foo bar"}, |
1545 | - {loggo.DEBUG, "12345"}, |
1546 | - }) |
1547 | -} |
1548 | - |
1549 | -func (s *LogMatchesSuite) TestMatchStrings(c *gc.C) { |
1550 | - log := []loggo.TestLogValues{ |
1551 | - {Level: loggo.INFO, Message: "foo bar"}, |
1552 | - {Level: loggo.INFO, Message: "12345"}, |
1553 | - } |
1554 | - c.Check(log, jc.LogMatches, []string{"foo bar", "12345"}) |
1555 | - c.Check(log, jc.LogMatches, []string{"foo .*", "12345"}) |
1556 | - c.Check(log, gc.Not(jc.LogMatches), []string{"baz", "bing"}) |
1557 | -} |
1558 | - |
1559 | -func (s *LogMatchesSuite) TestMatchInexact(c *gc.C) { |
1560 | - log := []loggo.TestLogValues{ |
1561 | - {Level: loggo.INFO, Message: "foo bar"}, |
1562 | - {Level: loggo.INFO, Message: "baz"}, |
1563 | - {Level: loggo.DEBUG, Message: "12345"}, |
1564 | - {Level: loggo.ERROR, Message: "12345"}, |
1565 | - {Level: loggo.INFO, Message: "67890"}, |
1566 | - } |
1567 | - c.Check(log, jc.LogMatches, []string{"foo bar", "12345"}) |
1568 | - c.Check(log, jc.LogMatches, []string{"foo .*", "12345"}) |
1569 | - c.Check(log, jc.LogMatches, []string{"foo .*", "67890"}) |
1570 | - c.Check(log, jc.LogMatches, []string{"67890"}) |
1571 | - |
1572 | - // Matches are always left-most after the previous match. |
1573 | - c.Check(log, jc.LogMatches, []string{".*", "baz"}) |
1574 | - c.Check(log, jc.LogMatches, []string{"foo bar", ".*", "12345"}) |
1575 | - c.Check(log, jc.LogMatches, []string{"foo bar", ".*", "67890"}) |
1576 | - |
1577 | - // Order is important: 67890 advances to the last item in obtained, |
1578 | - // and so there's nothing after to match against ".*". |
1579 | - c.Check(log, gc.Not(jc.LogMatches), []string{"67890", ".*"}) |
1580 | - // ALL specified patterns MUST match in the order given. |
1581 | - c.Check(log, gc.Not(jc.LogMatches), []string{".*", "foo bar"}) |
1582 | - |
1583 | - // Check that levels are matched. |
1584 | - c.Check(log, jc.LogMatches, []jc.SimpleMessage{ |
1585 | - {loggo.UNSPECIFIED, "12345"}, |
1586 | - {loggo.UNSPECIFIED, "12345"}, |
1587 | - }) |
1588 | - c.Check(log, jc.LogMatches, []jc.SimpleMessage{ |
1589 | - {loggo.DEBUG, "12345"}, |
1590 | - {loggo.ERROR, "12345"}, |
1591 | - }) |
1592 | - c.Check(log, jc.LogMatches, []jc.SimpleMessage{ |
1593 | - {loggo.DEBUG, "12345"}, |
1594 | - {loggo.INFO, ".*"}, |
1595 | - }) |
1596 | - c.Check(log, gc.Not(jc.LogMatches), []jc.SimpleMessage{ |
1597 | - {loggo.DEBUG, "12345"}, |
1598 | - {loggo.INFO, ".*"}, |
1599 | - {loggo.UNSPECIFIED, ".*"}, |
1600 | - }) |
1601 | -} |
1602 | - |
1603 | -func (s *LogMatchesSuite) TestFromLogMatches(c *gc.C) { |
1604 | - tw := &loggo.TestWriter{} |
1605 | - _, err := loggo.ReplaceDefaultWriter(tw) |
1606 | - c.Assert(err, gc.IsNil) |
1607 | - defer loggo.ResetWriters() |
1608 | - logger := loggo.GetLogger("test") |
1609 | - logger.SetLogLevel(loggo.DEBUG) |
1610 | - logger.Infof("foo") |
1611 | - logger.Debugf("bar") |
1612 | - logger.Tracef("hidden") |
1613 | - c.Check(tw.Log, jc.LogMatches, []string{"foo", "bar"}) |
1614 | - c.Check(tw.Log, gc.Not(jc.LogMatches), []string{"foo", "bad"}) |
1615 | - c.Check(tw.Log, gc.Not(jc.LogMatches), []jc.SimpleMessage{ |
1616 | - {loggo.INFO, "foo"}, |
1617 | - {loggo.INFO, "bar"}, |
1618 | - }) |
1619 | -} |
1620 | |
1621 | === removed file 'testing/checkers/relop.go' |
1622 | --- testing/checkers/relop.go 2013-09-13 14:48:13 +0000 |
1623 | +++ testing/checkers/relop.go 1970-01-01 00:00:00 +0000 |
1624 | @@ -1,93 +0,0 @@ |
1625 | -// Copyright 2013 Canonical Ltd. |
1626 | -// Licensed under the AGPLv3, see LICENCE file for details. |
1627 | - |
1628 | -package checkers |
1629 | - |
1630 | -import ( |
1631 | - "fmt" |
1632 | - "reflect" |
1633 | - |
1634 | - gc "launchpad.net/gocheck" |
1635 | -) |
1636 | - |
1637 | -// GreaterThan checker |
1638 | - |
1639 | -type greaterThanChecker struct { |
1640 | - *gc.CheckerInfo |
1641 | -} |
1642 | - |
1643 | -var GreaterThan gc.Checker = &greaterThanChecker{ |
1644 | - &gc.CheckerInfo{Name: "GreaterThan", Params: []string{"obtained", "expected"}}, |
1645 | -} |
1646 | - |
1647 | -func (checker *greaterThanChecker) Check(params []interface{}, names []string) (result bool, error string) { |
1648 | - defer func() { |
1649 | - if v := recover(); v != nil { |
1650 | - result = false |
1651 | - error = fmt.Sprint(v) |
1652 | - } |
1653 | - }() |
1654 | - |
1655 | - p0value := reflect.ValueOf(params[0]) |
1656 | - p1value := reflect.ValueOf(params[1]) |
1657 | - switch p0value.Kind() { |
1658 | - case reflect.Int, |
1659 | - reflect.Int8, |
1660 | - reflect.Int16, |
1661 | - reflect.Int32, |
1662 | - reflect.Int64: |
1663 | - return p0value.Int() > p1value.Int(), "" |
1664 | - case reflect.Uint, |
1665 | - reflect.Uint8, |
1666 | - reflect.Uint16, |
1667 | - reflect.Uint32, |
1668 | - reflect.Uint64: |
1669 | - return p0value.Uint() > p1value.Uint(), "" |
1670 | - case reflect.Float32, |
1671 | - reflect.Float64: |
1672 | - return p0value.Float() > p1value.Float(), "" |
1673 | - default: |
1674 | - } |
1675 | - return false, fmt.Sprintf("obtained value %s:%#v not supported", p0value.Kind(), params[0]) |
1676 | -} |
1677 | - |
1678 | -// LessThan checker |
1679 | - |
1680 | -type lessThanChecker struct { |
1681 | - *gc.CheckerInfo |
1682 | -} |
1683 | - |
1684 | -var LessThan gc.Checker = &lessThanChecker{ |
1685 | - &gc.CheckerInfo{Name: "LessThan", Params: []string{"obtained", "expected"}}, |
1686 | -} |
1687 | - |
1688 | -func (checker *lessThanChecker) Check(params []interface{}, names []string) (result bool, error string) { |
1689 | - defer func() { |
1690 | - if v := recover(); v != nil { |
1691 | - result = false |
1692 | - error = fmt.Sprint(v) |
1693 | - } |
1694 | - }() |
1695 | - |
1696 | - p0value := reflect.ValueOf(params[0]) |
1697 | - p1value := reflect.ValueOf(params[1]) |
1698 | - switch p0value.Kind() { |
1699 | - case reflect.Int, |
1700 | - reflect.Int8, |
1701 | - reflect.Int16, |
1702 | - reflect.Int32, |
1703 | - reflect.Int64: |
1704 | - return p0value.Int() < p1value.Int(), "" |
1705 | - case reflect.Uint, |
1706 | - reflect.Uint8, |
1707 | - reflect.Uint16, |
1708 | - reflect.Uint32, |
1709 | - reflect.Uint64: |
1710 | - return p0value.Uint() < p1value.Uint(), "" |
1711 | - case reflect.Float32, |
1712 | - reflect.Float64: |
1713 | - return p0value.Float() < p1value.Float(), "" |
1714 | - default: |
1715 | - } |
1716 | - return false, fmt.Sprintf("obtained value %s:%#v not supported", p0value.Kind(), params[0]) |
1717 | -} |
1718 | |
1719 | === removed file 'testing/checkers/relop_test.go' |
1720 | --- testing/checkers/relop_test.go 2014-03-13 07:54:56 +0000 |
1721 | +++ testing/checkers/relop_test.go 1970-01-01 00:00:00 +0000 |
1722 | @@ -1,35 +0,0 @@ |
1723 | -// Copyright 2013 Canonical Ltd. |
1724 | -// Licensed under the AGPLv3, see LICENCE file for details. |
1725 | - |
1726 | -package checkers_test |
1727 | - |
1728 | -import ( |
1729 | - jc "github.com/juju/testing/checkers" |
1730 | - gc "launchpad.net/gocheck" |
1731 | -) |
1732 | - |
1733 | -type RelopSuite struct{} |
1734 | - |
1735 | -var _ = gc.Suite(&RelopSuite{}) |
1736 | - |
1737 | -func (s *RelopSuite) TestGreaterThan(c *gc.C) { |
1738 | - c.Assert(45, jc.GreaterThan, 42) |
1739 | - c.Assert(2.25, jc.GreaterThan, 1.0) |
1740 | - c.Assert(42, gc.Not(jc.GreaterThan), 42) |
1741 | - c.Assert(10, gc.Not(jc.GreaterThan), 42) |
1742 | - |
1743 | - result, msg := jc.GreaterThan.Check([]interface{}{"Hello", "World"}, nil) |
1744 | - c.Assert(result, jc.IsFalse) |
1745 | - c.Assert(msg, gc.Equals, `obtained value string:"Hello" not supported`) |
1746 | -} |
1747 | - |
1748 | -func (s *RelopSuite) TestLessThan(c *gc.C) { |
1749 | - c.Assert(42, jc.LessThan, 45) |
1750 | - c.Assert(1.0, jc.LessThan, 2.25) |
1751 | - c.Assert(42, gc.Not(jc.LessThan), 42) |
1752 | - c.Assert(42, gc.Not(jc.LessThan), 10) |
1753 | - |
1754 | - result, msg := jc.LessThan.Check([]interface{}{"Hello", "World"}, nil) |
1755 | - c.Assert(result, jc.IsFalse) |
1756 | - c.Assert(msg, gc.Equals, `obtained value string:"Hello" not supported`) |
1757 | -} |
1758 | |
1759 | === modified file 'worker/instancepoller/aggregate_test.go' |
1760 | --- worker/instancepoller/aggregate_test.go 2014-03-13 18:40:06 +0000 |
1761 | +++ worker/instancepoller/aggregate_test.go 2014-03-18 02:58:54 +0000 |
1762 | @@ -9,12 +9,12 @@ |
1763 | "sync/atomic" |
1764 | "time" |
1765 | |
1766 | + jc "github.com/juju/testing/checkers" |
1767 | gc "launchpad.net/gocheck" |
1768 | |
1769 | "launchpad.net/juju-core/environs" |
1770 | "launchpad.net/juju-core/errors" |
1771 | "launchpad.net/juju-core/instance" |
1772 | - jc "launchpad.net/juju-core/testing/checkers" |
1773 | "launchpad.net/juju-core/testing/testbase" |
1774 | ) |
1775 |
Reviewers: mp+210935_ code.launchpad. net,
Message:
Please take a look.
Description:
Remove Checkers Dir
We now get checkers from github branch.
https:/ /code.launchpad .net/~waigani/ juju-core/ remove- checkers- dir/+merge/ 210935
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/75630044/
Affected files (+2, -1697 lines): checkers/ bool.go checkers/ bool_test. go checkers/ checker. go checkers/ checker_ test.go checkers/ deepequal. go checkers/ deepequal_ test.go checkers/ file.go checkers/ file_test. go checkers/ log.go checkers/ log_test. go checkers/ relop.go checkers/ relop_test. go
A [revision details]
D testing/
D testing/
D testing/
D testing/
D testing/
D testing/
D testing/
D testing/
D testing/
D testing/
D testing/
D testing/