@@ -368,18 +368,68 @@ func Test_MultipleTraps(t *testing.T) {
368
368
}
369
369
370
370
func Test_UnreleasedCalls (t * testing.T ) {
371
- t .Skip ("this test is meant to demonstrate how unreleased calls fail" )
372
371
t .Parallel ()
373
- testCtx , testCancel := context .WithTimeout (context .Background (), 10 * time .Second )
374
- defer testCancel ()
375
- mClock := quartz .NewMock (t )
372
+ tRunFail (t , func (t testing.TB ) {
373
+ testCtx , testCancel := context .WithTimeout (context .Background (), 10 * time .Second )
374
+ defer testCancel ()
375
+ mClock := quartz .NewMock (t )
376
376
377
- trap := mClock .Trap ().Now ()
378
- defer trap .Close ()
377
+ trap := mClock .Trap ().Now ()
378
+ defer trap .Close ()
379
379
380
- go func () {
381
- _ = mClock .Now ()
382
- }()
380
+ go func () {
381
+ _ = mClock .Now ()
382
+ }()
383
+
384
+ trap .MustWait (testCtx ) // missing release
385
+ })
386
+ }
387
+
388
+ type captureFailTB struct {
389
+ failed bool
390
+ testing.TB
391
+ }
392
+
393
+ func (t * captureFailTB ) Errorf (format string , args ... any ) {
394
+ t .Helper ()
395
+ t .Logf (format , args ... )
396
+ t .failed = true
397
+ }
383
398
384
- trap .MustWait (testCtx ) // missing release
399
+ func (t * captureFailTB ) Error (args ... any ) {
400
+ t .Helper ()
401
+ t .Log (args ... )
402
+ t .failed = true
403
+ }
404
+
405
+ func (t * captureFailTB ) Fatal (args ... any ) {
406
+ t .Helper ()
407
+ t .Log (args ... )
408
+ t .failed = true
409
+ }
410
+
411
+ func (t * captureFailTB ) Fatalf (format string , args ... any ) {
412
+ t .Helper ()
413
+ t .Logf (format , args ... )
414
+ t .failed = true
415
+ }
416
+
417
+ func (t * captureFailTB ) Fail () {
418
+ t .failed = true
419
+ }
420
+
421
+ func (t * captureFailTB ) FailNow () {
422
+ t .failed = true
423
+ }
424
+
425
+ func (t * captureFailTB ) Failed () bool {
426
+ return t .failed
427
+ }
428
+
429
+ func tRunFail (t testing.TB , f func (t testing.TB )) {
430
+ tb := & captureFailTB {TB : t }
431
+ f (tb )
432
+ if ! tb .Failed () {
433
+ t .Fatal ("want test to fail" )
434
+ }
385
435
}
0 commit comments