test-lib tests: get rid of copy/pasted mock test code
Now that we've split up the write_sub_test_lib_test*() and run_sub_test_lib_test*() functions let's fix those tests in t0000-basic.sh that were verbosely copy/pasting earlier tests. That we caught all of them was asserted with a follow-up change that's not part of this series[1], we might add such a duplication check at some later time, but for now let's just one-off remove the duplicate boilerplate. 1. https://lore.kernel.org/git/patch-v3-6.9-bc79b29f3c-20210805T103237Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Sep 22, 2021 at 13:19 UTC
2e54907e83febc637484255491c6a65b004fd648
1 file changed
+60
-168
t/t0000-basic.sh
+60
-168
@@ -226,18 +226,13 @@ test_expect_success 'subtest: --verbose option' '
226
'
227
228
test_expect_success 'subtest: --verbose-only option' '
229
- write_and_run_sub_test_lib_test_err \
230
- t2345-verbose-only-2 \
231
- --verbose-only=2 <<-\EOF &&
232
- test_expect_success "passing test" true
233
- test_expect_success "test with output" "echo foo"
234
- test_expect_success "failing test" false
235
- test_done
236
- EOF
237
- check_sub_test_lib_test t2345-verbose-only-2 <<-\EOF
229
+ run_sub_test_lib_test_err \
230
+ t1234-verbose \
231
+ --verbose-only=2 &&
232
+ check_sub_test_lib_test t1234-verbose <<-\EOF
233
> ok 1 - passing test
234
> Z
240
- > expecting success of 2345.2 '\''test with output'\'': echo foo
235
+ > expecting success of 1234.2 '\''test with output'\'': echo foo
236
> foo
237
> ok 2 - test with output
238
> Z
@@ -250,15 +245,9 @@ test_expect_success 'subtest: --verbose-only option' '
245
246
test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' '
247
(
253
- write_and_run_sub_test_lib_test git-skip-tests-basic \
254
- --skip="git.2" <<-\EOF &&
255
- for i in 1 2 3
256
- do
257
- test_expect_success "passing test #$i" "true"
258
- done
259
- test_done
260
- EOF
261
- check_sub_test_lib_test git-skip-tests-basic <<-\EOF
248
+ run_sub_test_lib_test full-pass \
249
+ --skip="full.2" &&
250
+ check_sub_test_lib_test full-pass <<-\EOF
251
> ok 1 - passing test #1
252
> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
253
> ok 3 - passing test #3
@@ -293,15 +282,9 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' '
282
283
test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' '
284
(
296
- write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \
297
- --skip="git.[2-5]" <<-\EOF &&
298
- for i in 1 2 3 4 5 6
299
- do
300
- test_expect_success "passing test #$i" "true"
301
- done
302
- test_done
303
- EOF
304
- check_sub_test_lib_test git-skip-tests-sh-pattern <<-\EOF
285
+ run_sub_test_lib_test git-skip-tests-several \
286
+ --skip="git.[2-5]" &&
287
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
288
> ok 1 - passing test #1
289
> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
290
> ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
@@ -316,15 +299,10 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' '
299
300
test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' '
301
(
319
- write_and_run_sub_test_lib_test git-skip-tests-entire-suite \
320
- --skip="git" <<-\EOF &&
321
- for i in 1 2 3
322
- do
323
- test_expect_success "passing test #$i" "true"
324
- done
325
- test_done
326
- EOF
327
- check_sub_test_lib_test git-skip-tests-entire-suite <<-\EOF
302
+ GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS &&
303
+ run_sub_test_lib_test git-skip-tests-several \
304
+ --skip="git" &&
305
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
306
> 1..0 # SKIP skip all tests in git
307
EOF
308
)
@@ -332,15 +310,10 @@ test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' '
310
311
test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '
312
(
335
- write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \
336
- --skip="notgit" <<-\EOF &&
337
- for i in 1 2 3
338
- do
339
- test_expect_success "passing test #$i" "true"
340
- done
341
- test_done
342
- EOF
343
- check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\EOF
313
+ GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS &&
314
+ run_sub_test_lib_test full-pass \
315
+ --skip="notfull" &&
316
+ check_sub_test_lib_test full-pass <<-\EOF
317
> ok 1 - passing test #1
318
> ok 2 - passing test #2
319
> ok 3 - passing test #3
@@ -351,14 +324,8 @@ test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '
324
'
325
326
test_expect_success 'subtest: --run basic' '
354
- write_and_run_sub_test_lib_test run-basic --run="1,3,5" <<-\EOF &&
355
- for i in 1 2 3 4 5 6
356
- do
357
- test_expect_success "passing test #$i" "true"
358
- done
359
- test_done
360
- EOF
361
- check_sub_test_lib_test run-basic <<-\EOF
327
+ run_sub_test_lib_test git-skip-tests-several --run="1,3,5" &&
328
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
329
> ok 1 - passing test #1
330
> ok 2 # skip passing test #2 (--run)
331
> ok 3 - passing test #3
@@ -371,15 +338,9 @@ test_expect_success 'subtest: --run basic' '
338
'
339
340
test_expect_success 'subtest: --run with a range' '
374
- write_and_run_sub_test_lib_test run-range \
375
- --run="1-3" <<-\EOF &&
376
- for i in 1 2 3 4 5 6
377
- do
378
- test_expect_success "passing test #$i" "true"
379
- done
380
- test_done
381
- EOF
382
- check_sub_test_lib_test run-range <<-\EOF
341
+ run_sub_test_lib_test git-skip-tests-several \
342
+ --run="1-3" &&
343
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
344
> ok 1 - passing test #1
345
> ok 2 - passing test #2
346
> ok 3 - passing test #3
@@ -392,15 +353,9 @@ test_expect_success 'subtest: --run with a range' '
353
'
354
355
test_expect_success 'subtest: --run with two ranges' '
395
- write_and_run_sub_test_lib_test run-two-ranges \
396
- --run="1-2,5-6" <<-\EOF &&
397
- for i in 1 2 3 4 5 6
398
- do
399
- test_expect_success "passing test #$i" "true"
400
- done
401
- test_done
402
- EOF
403
- check_sub_test_lib_test run-two-ranges <<-\EOF
356
+ run_sub_test_lib_test git-skip-tests-several \
357
+ --run="1-2,5-6" &&
358
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
359
> ok 1 - passing test #1
360
> ok 2 - passing test #2
361
> ok 3 # skip passing test #3 (--run)
@@ -413,15 +368,9 @@ test_expect_success 'subtest: --run with two ranges' '
368
'
369
370
test_expect_success 'subtest: --run with a left open range' '
416
- write_and_run_sub_test_lib_test run-left-open-range \
417
- --run="-3" <<-\EOF &&
418
- for i in 1 2 3 4 5 6
419
- do
420
- test_expect_success "passing test #$i" "true"
421
- done
422
- test_done
423
- EOF
424
- check_sub_test_lib_test run-left-open-range <<-\EOF
371
+ run_sub_test_lib_test git-skip-tests-several \
372
+ --run="-3" &&
373
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
374
> ok 1 - passing test #1
375
> ok 2 - passing test #2
376
> ok 3 - passing test #3
@@ -434,15 +383,9 @@ test_expect_success 'subtest: --run with a left open range' '
383
'
384
385
test_expect_success 'subtest: --run with a right open range' '
437
- write_and_run_sub_test_lib_test run-right-open-range \
438
- --run="4-" <<-\EOF &&
439
- for i in 1 2 3 4 5 6
440
- do
441
- test_expect_success "passing test #$i" "true"
442
- done
443
- test_done
444
- EOF
445
- check_sub_test_lib_test run-right-open-range <<-\EOF
386
+ run_sub_test_lib_test git-skip-tests-several \
387
+ --run="4-" &&
388
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
389
> ok 1 # skip passing test #1 (--run)
390
> ok 2 # skip passing test #2 (--run)
391
> ok 3 # skip passing test #3 (--run)
@@ -455,15 +398,9 @@ test_expect_success 'subtest: --run with a right open range' '
398
'
399
400
test_expect_success 'subtest: --run with basic negation' '
458
- write_and_run_sub_test_lib_test run-basic-neg \
459
- --run="!3" <<-\EOF &&
460
- for i in 1 2 3 4 5 6
461
- do
462
- test_expect_success "passing test #$i" "true"
463
- done
464
- test_done
465
- EOF
466
- check_sub_test_lib_test run-basic-neg <<-\EOF
401
+ run_sub_test_lib_test git-skip-tests-several \
402
+ --run="!3" &&
403
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
404
> ok 1 - passing test #1
405
> ok 2 - passing test #2
406
> ok 3 # skip passing test #3 (--run)
@@ -476,15 +413,9 @@ test_expect_success 'subtest: --run with basic negation' '
413
'
414
415
test_expect_success 'subtest: --run with two negations' '
479
- write_and_run_sub_test_lib_test run-two-neg \
480
- --run="!3,!6" <<-\EOF &&
481
- for i in 1 2 3 4 5 6
482
- do
483
- test_expect_success "passing test #$i" "true"
484
- done
485
- test_done
486
- EOF
487
- check_sub_test_lib_test run-two-neg <<-\EOF
416
+ run_sub_test_lib_test git-skip-tests-several \
417
+ --run="!3,!6" &&
418
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
419
> ok 1 - passing test #1
420
> ok 2 - passing test #2
421
> ok 3 # skip passing test #3 (--run)
@@ -497,15 +428,9 @@ test_expect_success 'subtest: --run with two negations' '
428
'
429
430
test_expect_success 'subtest: --run a range and negation' '
500
- write_and_run_sub_test_lib_test run-range-and-neg \
501
- --run="-4,!2" <<-\EOF &&
502
- for i in 1 2 3 4 5 6
503
- do
504
- test_expect_success "passing test #$i" "true"
505
- done
506
- test_done
507
- EOF
508
- check_sub_test_lib_test run-range-and-neg <<-\EOF
431
+ run_sub_test_lib_test git-skip-tests-several \
432
+ --run="-4,!2" &&
433
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
434
> ok 1 - passing test #1
435
> ok 2 # skip passing test #2 (--run)
436
> ok 3 - passing test #3
@@ -518,15 +443,9 @@ test_expect_success 'subtest: --run a range and negation' '
443
'
444
445
test_expect_success 'subtest: --run range negation' '
521
- write_and_run_sub_test_lib_test run-range-neg \
522
- --run="!1-3" <<-\EOF &&
523
- for i in 1 2 3 4 5 6
524
- do
525
- test_expect_success "passing test #$i" "true"
526
- done
527
- test_done
528
- EOF
529
- check_sub_test_lib_test run-range-neg <<-\EOF
446
+ run_sub_test_lib_test git-skip-tests-several \
447
+ --run="!1-3" &&
448
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
449
> ok 1 # skip passing test #1 (--run)
450
> ok 2 # skip passing test #2 (--run)
451
> ok 3 # skip passing test #3 (--run)
@@ -539,15 +458,9 @@ test_expect_success 'subtest: --run range negation' '
458
'
459
460
test_expect_success 'subtest: --run include, exclude and include' '
542
- write_and_run_sub_test_lib_test run-inc-neg-inc \
543
- --run="1-5,!1-3,2" <<-\EOF &&
544
- for i in 1 2 3 4 5 6
545
- do
546
- test_expect_success "passing test #$i" "true"
547
- done
548
- test_done
549
- EOF
550
- check_sub_test_lib_test run-inc-neg-inc <<-\EOF
461
+ run_sub_test_lib_test git-skip-tests-several \
462
+ --run="1-5,!1-3,2" &&
463
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
464
> ok 1 # skip passing test #1 (--run)
465
> ok 2 - passing test #2
466
> ok 3 # skip passing test #3 (--run)
@@ -560,15 +473,9 @@ test_expect_success 'subtest: --run include, exclude and include' '
473
'
474
475
test_expect_success 'subtest: --run include, exclude and include, comma separated' '
563
- write_and_run_sub_test_lib_test run-inc-neg-inc-comma \
564
- --run=1-5,!1-3,2 <<-\EOF &&
565
- for i in 1 2 3 4 5 6
566
- do
567
- test_expect_success "passing test #$i" "true"
568
- done
569
- test_done
570
- EOF
571
- check_sub_test_lib_test run-inc-neg-inc-comma <<-\EOF
476
+ run_sub_test_lib_test git-skip-tests-several \
477
+ --run=1-5,!1-3,2 &&
478
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
479
> ok 1 # skip passing test #1 (--run)
480
> ok 2 - passing test #2
481
> ok 3 # skip passing test #3 (--run)
@@ -581,15 +488,9 @@ test_expect_success 'subtest: --run include, exclude and include, comma separate
488
'
489
490
test_expect_success 'subtest: --run exclude and include' '
584
- write_and_run_sub_test_lib_test run-neg-inc \
585
- --run="!3-,5" <<-\EOF &&
586
- for i in 1 2 3 4 5 6
587
- do
588
- test_expect_success "passing test #$i" "true"
589
- done
590
- test_done
591
- EOF
592
- check_sub_test_lib_test run-neg-inc <<-\EOF
491
+ run_sub_test_lib_test git-skip-tests-several \
492
+ --run="!3-,5" &&
493
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
494
> ok 1 - passing test #1
495
> ok 2 - passing test #2
496
> ok 3 # skip passing test #3 (--run)
@@ -602,15 +503,9 @@ test_expect_success 'subtest: --run exclude and include' '
503
'
504
505
test_expect_success 'subtest: --run empty selectors' '
605
- write_and_run_sub_test_lib_test run-empty-sel \
606
- --run="1,,3,,,5" <<-\EOF &&
607
- for i in 1 2 3 4 5 6
608
- do
609
- test_expect_success "passing test #$i" "true"
610
- done
611
- test_done
612
- EOF
613
- check_sub_test_lib_test run-empty-sel <<-\EOF
506
+ run_sub_test_lib_test git-skip-tests-several \
507
+ --run="1,,3,,,5" &&
508
+ check_sub_test_lib_test git-skip-tests-several <<-\EOF
509
> ok 1 - passing test #1
510
> ok 2 # skip passing test #2 (--run)
511
> ok 3 - passing test #3
@@ -660,12 +555,9 @@ test_expect_success 'subtest: --run keyword selection' '
555
'
556
557
test_expect_success 'subtest: --run invalid range end' '
663
- write_and_run_sub_test_lib_test_err run-inv-range-end \
664
- --run="1-z" <<-\EOF &&
665
- test_expect_success "passing test #1" "true"
666
- test_done
667
- EOF
668
- check_sub_test_lib_test_err run-inv-range-end \
558
+ run_sub_test_lib_test_err run-inv-range-start \
559
+ --run="1-z" &&
560
+ check_sub_test_lib_test_err run-inv-range-start \
561
<<-\EOF_OUT 3<<-EOF_ERR
562
> FATAL: Unexpected exit with code 1
563
EOF_OUT