Skip to content

Commit 2e54907

Browse files
avargitster
authored andcommitted
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/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 56722a0 commit 2e54907

File tree

1 file changed

+60
-168
lines changed

1 file changed

+60
-168
lines changed

t/t0000-basic.sh

Lines changed: 60 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,13 @@ test_expect_success 'subtest: --verbose option' '
226226
'
227227

228228
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
238233
> ok 1 - passing test
239234
> Z
240-
> expecting success of 2345.2 '\''test with output'\'': echo foo
235+
> expecting success of 1234.2 '\''test with output'\'': echo foo
241236
> foo
242237
> ok 2 - test with output
243238
> Z
@@ -250,15 +245,9 @@ test_expect_success 'subtest: --verbose-only option' '
250245

251246
test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' '
252247
(
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
262251
> ok 1 - passing test #1
263252
> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
264253
> ok 3 - passing test #3
@@ -293,15 +282,9 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' '
293282

294283
test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' '
295284
(
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
305288
> ok 1 - passing test #1
306289
> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
307290
> ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
@@ -316,31 +299,21 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' '
316299

317300
test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' '
318301
(
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
328306
> 1..0 # SKIP skip all tests in git
329307
EOF
330308
)
331309
'
332310

333311
test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '
334312
(
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
344317
> ok 1 - passing test #1
345318
> ok 2 - passing test #2
346319
> ok 3 - passing test #3
@@ -351,14 +324,8 @@ test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '
351324
'
352325

353326
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
362329
> ok 1 - passing test #1
363330
> ok 2 # skip passing test #2 (--run)
364331
> ok 3 - passing test #3
@@ -371,15 +338,9 @@ test_expect_success 'subtest: --run basic' '
371338
'
372339

373340
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
383344
> ok 1 - passing test #1
384345
> ok 2 - passing test #2
385346
> ok 3 - passing test #3
@@ -392,15 +353,9 @@ test_expect_success 'subtest: --run with a range' '
392353
'
393354

394355
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
404359
> ok 1 - passing test #1
405360
> ok 2 - passing test #2
406361
> ok 3 # skip passing test #3 (--run)
@@ -413,15 +368,9 @@ test_expect_success 'subtest: --run with two ranges' '
413368
'
414369

415370
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
425374
> ok 1 - passing test #1
426375
> ok 2 - passing test #2
427376
> ok 3 - passing test #3
@@ -434,15 +383,9 @@ test_expect_success 'subtest: --run with a left open range' '
434383
'
435384

436385
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
446389
> ok 1 # skip passing test #1 (--run)
447390
> ok 2 # skip passing test #2 (--run)
448391
> ok 3 # skip passing test #3 (--run)
@@ -455,15 +398,9 @@ test_expect_success 'subtest: --run with a right open range' '
455398
'
456399

457400
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
467404
> ok 1 - passing test #1
468405
> ok 2 - passing test #2
469406
> ok 3 # skip passing test #3 (--run)
@@ -476,15 +413,9 @@ test_expect_success 'subtest: --run with basic negation' '
476413
'
477414

478415
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
488419
> ok 1 - passing test #1
489420
> ok 2 - passing test #2
490421
> ok 3 # skip passing test #3 (--run)
@@ -497,15 +428,9 @@ test_expect_success 'subtest: --run with two negations' '
497428
'
498429

499430
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
509434
> ok 1 - passing test #1
510435
> ok 2 # skip passing test #2 (--run)
511436
> ok 3 - passing test #3
@@ -518,15 +443,9 @@ test_expect_success 'subtest: --run a range and negation' '
518443
'
519444

520445
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
530449
> ok 1 # skip passing test #1 (--run)
531450
> ok 2 # skip passing test #2 (--run)
532451
> ok 3 # skip passing test #3 (--run)
@@ -539,15 +458,9 @@ test_expect_success 'subtest: --run range negation' '
539458
'
540459

541460
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
551464
> ok 1 # skip passing test #1 (--run)
552465
> ok 2 - passing test #2
553466
> ok 3 # skip passing test #3 (--run)
@@ -560,15 +473,9 @@ test_expect_success 'subtest: --run include, exclude and include' '
560473
'
561474

562475
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
572479
> ok 1 # skip passing test #1 (--run)
573480
> ok 2 - passing test #2
574481
> ok 3 # skip passing test #3 (--run)
@@ -581,15 +488,9 @@ test_expect_success 'subtest: --run include, exclude and include, comma separate
581488
'
582489

583490
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
593494
> ok 1 - passing test #1
594495
> ok 2 - passing test #2
595496
> ok 3 # skip passing test #3 (--run)
@@ -602,15 +503,9 @@ test_expect_success 'subtest: --run exclude and include' '
602503
'
603504

604505
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
614509
> ok 1 - passing test #1
615510
> ok 2 # skip passing test #2 (--run)
616511
> ok 3 - passing test #3
@@ -660,12 +555,9 @@ test_expect_success 'subtest: --run keyword selection' '
660555
'
661556

662557
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 \
669561
<<-\EOF_OUT 3<<-EOF_ERR
670562
> FATAL: Unexpected exit with code 1
671563
EOF_OUT

0 commit comments

Comments
 (0)