t4015: modernise style

Move the preparatory steps that create the expected output inside the test bodies, remove unnecessary blank lines before and after the test bodies, and drop SP between redirection operator and its target. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed May 26, 2015 at 11:19 UTC d55ef3e04459a5f1a24f494b873d8590f2523add
1 file changed +173 -238
t/t4015-diff-whitespace.sh
+173 -238
@@ -9,138 +9,144 @@ test_description='Test special whitespace in diff engine.
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/diff-lib.sh
11
12 -# Ray Lehtiniemi's example
12 +test_expect_success "Ray Lehtiniemi's example" '
13 + cat <<-\EOF >x &&
14 + do {
15 + nothing;
16 + } while (0);
17 + EOF
18 + git update-index --add x &&
19
14 -cat << EOF > x
15 -do {
16 - nothing;
17 -} while (0);
18 -EOF
20 + cat <<-\EOF >x &&
21 + do
22 + {
23 + nothing;
24 + }
25 + while (0);
26 + EOF
27
20 -git update-index --add x
28 + cat <<-\EOF >expect &&
29 + diff --git a/x b/x
30 + index adf3937..6edc172 100644
31 + --- a/x
32 + +++ b/x
33 + @@ -1,3 +1,5 @@
34 + -do {
35 + +do
36 + +{
37 + nothing;
38 + -} while (0);
39 + +}
40 + +while (0);
41 + EOF
42
22 -cat << EOF > x
23 -do
24 -{
25 - nothing;
26 -}
27 -while (0);
28 -EOF
43 + git diff >out &&
44 + test_cmp expect out &&
45
30 -cat << EOF > expect
31 -diff --git a/x b/x
32 -index adf3937..6edc172 100644
33 ---- a/x
34 -+++ b/x
35 -@@ -1,3 +1,5 @@
36 --do {
37 -+do
38 -+{
39 - nothing;
40 --} while (0);
41 -+}
42 -+while (0);
43 -EOF
46 + git diff -w >out &&
47 + test_cmp expect out &&
48
45 -git diff > out
46 -test_expect_success "Ray's example without options" 'test_cmp expect out'
49 + git diff -b >out &&
50 + test_cmp expect out
51 +'
52
48 -git diff -w > out
49 -test_expect_success "Ray's example with -w" 'test_cmp expect out'
53 +test_expect_success 'another test, without options' '
54 + tr Q "\015" <<-\EOF >x &&
55 + whitespace at beginning
56 + whitespace change
57 + whitespace in the middle
58 + whitespace at end
59 + unchanged line
60 + CR at endQ
61 + EOF
62
51 -git diff -b > out
52 -test_expect_success "Ray's example with -b" 'test_cmp expect out'
63 + git update-index x &&
64
54 -tr 'Q' '\015' << EOF > x
55 -whitespace at beginning
56 -whitespace change
57 -whitespace in the middle
58 -whitespace at end
59 -unchanged line
60 -CR at endQ
61 -EOF
65 + tr "_" " " <<-\EOF >x &&
66 + _ whitespace at beginning
67 + whitespace change
68 + white space in the middle
69 + whitespace at end__
70 + unchanged line
71 + CR at end
72 + EOF
73
63 -git update-index x
74 + tr "Q_" "\015 " <<-\EOF >expect &&
75 + diff --git a/x b/x
76 + index d99af23..22d9f73 100644
77 + --- a/x
78 + +++ b/x
79 + @@ -1,6 +1,6 @@
80 + -whitespace at beginning
81 + -whitespace change
82 + -whitespace in the middle
83 + -whitespace at end
84 + + whitespace at beginning
85 + +whitespace change
86 + +white space in the middle
87 + +whitespace at end__
88 + unchanged line
89 + -CR at endQ
90 + +CR at end
91 + EOF
92
65 -tr '_' ' ' << EOF > x
66 - whitespace at beginning
67 -whitespace change
68 -white space in the middle
69 -whitespace at end__
70 -unchanged line
71 -CR at end
72 -EOF
93 + git diff >out &&
94 + test_cmp expect out &&
95
74 -tr 'Q_' '\015 ' << EOF > expect
75 -diff --git a/x b/x
76 -index d99af23..8b32fb5 100644
77 ---- a/x
78 -+++ b/x
79 -@@ -1,6 +1,6 @@
80 --whitespace at beginning
81 --whitespace change
82 --whitespace in the middle
83 --whitespace at end
84 -+ whitespace at beginning
85 -+whitespace change
86 -+white space in the middle
87 -+whitespace at end__
88 - unchanged line
89 --CR at endQ
90 -+CR at end
91 -EOF
92 -git diff > out
93 -test_expect_success 'another test, without options' 'test_cmp expect out'
96 + >expect &&
97 + git diff -w >out &&
98 + test_cmp expect out &&
99 +
100 + git diff -w -b >out &&
101 + test_cmp expect out &&
102 +
103 + git diff -w --ignore-space-at-eol >out &&
104 + test_cmp expect out &&
105 +
106 + git diff -w -b --ignore-space-at-eol >out &&
107 + test_cmp expect out &&
108
95 -cat << EOF > expect
96 -EOF
97 -git diff -w > out
98 -test_expect_success 'another test, with -w' 'test_cmp expect out'
99 -git diff -w -b > out
100 -test_expect_success 'another test, with -w -b' 'test_cmp expect out'
101 -git diff -w --ignore-space-at-eol > out
102 -test_expect_success 'another test, with -w --ignore-space-at-eol' 'test_cmp expect out'
103 -git diff -w -b --ignore-space-at-eol > out
104 -test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out'
105 -
106 -tr 'Q_' '\015 ' << EOF > expect
107 -diff --git a/x b/x
108 -index d99af23..8b32fb5 100644
109 ---- a/x
110 -+++ b/x
111 -@@ -1,6 +1,6 @@
112 --whitespace at beginning
113 -+ whitespace at beginning
114 - whitespace change
115 --whitespace in the middle
116 -+white space in the middle
117 - whitespace at end__
118 - unchanged line
119 - CR at end
120 -EOF
121 -git diff -b > out
122 -test_expect_success 'another test, with -b' 'test_cmp expect out'
123 -git diff -b --ignore-space-at-eol > out
124 -test_expect_success 'another test, with -b --ignore-space-at-eol' 'test_cmp expect out'
125 -
126 -tr 'Q_' '\015 ' << EOF > expect
127 -diff --git a/x b/x
128 -index d99af23..8b32fb5 100644
129 ---- a/x
130 -+++ b/x
131 -@@ -1,6 +1,6 @@
132 --whitespace at beginning
133 --whitespace change
134 --whitespace in the middle
135 -+ whitespace at beginning
136 -+whitespace change
137 -+white space in the middle
138 - whitespace at end__
139 - unchanged line
140 - CR at end
141 -EOF
142 -git diff --ignore-space-at-eol > out
143 -test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect out'
109 +
110 + tr "Q_" "\015 " <<-\EOF >expect &&
111 + diff --git a/x b/x
112 + index d99af23..22d9f73 100644
113 + --- a/x
114 + +++ b/x
115 + @@ -1,6 +1,6 @@
116 + -whitespace at beginning
117 + +_ whitespace at beginning
118 + whitespace change
119 + -whitespace in the middle
120 + +white space in the middle
121 + whitespace at end__
122 + unchanged line
123 + CR at end
124 + EOF
125 + git diff -b >out &&
126 + test_cmp expect out &&
127 +
128 + git diff -b --ignore-space-at-eol >out &&
129 + test_cmp expect out &&
130 +
131 + tr "Q_" "\015 " <<-\EOF >expect &&
132 + diff --git a/x b/x
133 + index d99af23..22d9f73 100644
134 + --- a/x
135 + +++ b/x
136 + @@ -1,6 +1,6 @@
137 + -whitespace at beginning
138 + -whitespace change
139 + -whitespace in the middle
140 + +_ whitespace at beginning
141 + +whitespace change
142 + +white space in the middle
143 + whitespace at end__
144 + unchanged line
145 + CR at end
146 + EOF
147 + git diff --ignore-space-at-eol >out &&
148 + test_cmp expect out
149 +'
150
151 test_expect_success 'ignore-blank-lines: only new lines' '
152 test_seq 5 >x &&
@@ -489,291 +495,219 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
495 '
496
497 test_expect_success 'check mixed spaces and tabs in indent' '
492 -
498 # This is indented with SP HT SP.
494 - echo " foo();" > x &&
499 + echo " foo();" >x &&
500 git diff --check | grep "space before tab in indent"
496 -
501 '
502
503 test_expect_success 'check mixed tabs and spaces in indent' '
500 -
504 # This is indented with HT SP HT.
502 - echo " foo();" > x &&
505 + echo " foo();" >x &&
506 git diff --check | grep "space before tab in indent"
504 -
507 '
508
509 test_expect_success 'check with no whitespace errors' '
508 -
510 git commit -m "snapshot" &&
510 - echo "foo();" > x &&
511 + echo "foo();" >x &&
512 git diff --check
512 -
513 '
514
515 test_expect_success 'check with trailing whitespace' '
516 -
517 - echo "foo(); " > x &&
516 + echo "foo(); " >x &&
517 test_must_fail git diff --check
519 -
518 '
519
520 test_expect_success 'check with space before tab in indent' '
523 -
521 # indent has space followed by hard tab
525 - echo " foo();" > x &&
522 + echo " foo();" >x &&
523 test_must_fail git diff --check
527 -
524 '
525
526 test_expect_success '--check and --exit-code are not exclusive' '
531 -
527 git checkout x &&
528 git diff --check --exit-code
534 -
529 '
530
531 test_expect_success '--check and --quiet are not exclusive' '
538 -
532 git diff --check --quiet
540 -
533 '
534
535 test_expect_success 'check staged with no whitespace errors' '
544 -
545 - echo "foo();" > x &&
536 + echo "foo();" >x &&
537 git add x &&
538 git diff --cached --check
548 -
539 '
540
541 test_expect_success 'check staged with trailing whitespace' '
552 -
553 - echo "foo(); " > x &&
542 + echo "foo(); " >x &&
543 git add x &&
544 test_must_fail git diff --cached --check
556 -
545 '
546
547 test_expect_success 'check staged with space before tab in indent' '
560 -
548 # indent has space followed by hard tab
562 - echo " foo();" > x &&
549 + echo " foo();" >x &&
550 git add x &&
551 test_must_fail git diff --cached --check
565 -
552 '
553
554 test_expect_success 'check with no whitespace errors (diff-index)' '
569 -
570 - echo "foo();" > x &&
555 + echo "foo();" >x &&
556 git add x &&
557 git diff-index --check HEAD
573 -
558 '
559
560 test_expect_success 'check with trailing whitespace (diff-index)' '
577 -
578 - echo "foo(); " > x &&
561 + echo "foo(); " >x &&
562 git add x &&
563 test_must_fail git diff-index --check HEAD
581 -
564 '
565
566 test_expect_success 'check with space before tab in indent (diff-index)' '
585 -
567 # indent has space followed by hard tab
587 - echo " foo();" > x &&
568 + echo " foo();" >x &&
569 git add x &&
570 test_must_fail git diff-index --check HEAD
590 -
571 '
572
573 test_expect_success 'check staged with no whitespace errors (diff-index)' '
594 -
595 - echo "foo();" > x &&
574 + echo "foo();" >x &&
575 git add x &&
576 git diff-index --cached --check HEAD
598 -
577 '
578
579 test_expect_success 'check staged with trailing whitespace (diff-index)' '
602 -
603 - echo "foo(); " > x &&
580 + echo "foo(); " >x &&
581 git add x &&
582 test_must_fail git diff-index --cached --check HEAD
606 -
583 '
584
585 test_expect_success 'check staged with space before tab in indent (diff-index)' '
610 -
586 # indent has space followed by hard tab
612 - echo " foo();" > x &&
587 + echo " foo();" >x &&
588 git add x &&
589 test_must_fail git diff-index --cached --check HEAD
615 -
590 '
591
592 test_expect_success 'check with no whitespace errors (diff-tree)' '
619 -
620 - echo "foo();" > x &&
593 + echo "foo();" >x &&
594 git commit -m "new commit" x &&
595 git diff-tree --check HEAD^ HEAD
623 -
596 '
597
598 test_expect_success 'check with trailing whitespace (diff-tree)' '
627 -
628 - echo "foo(); " > x &&
599 + echo "foo(); " >x &&
600 git commit -m "another commit" x &&
601 test_must_fail git diff-tree --check HEAD^ HEAD
631 -
602 '
603
604 test_expect_success 'check with space before tab in indent (diff-tree)' '
635 -
605 # indent has space followed by hard tab
637 - echo " foo();" > x &&
606 + echo " foo();" >x &&
607 git commit -m "yet another" x &&
608 test_must_fail git diff-tree --check HEAD^ HEAD
640 -
609 '
610
611 test_expect_success 'check trailing whitespace (trailing-space: off)' '
644 -
612 git config core.whitespace "-trailing-space" &&
646 - echo "foo (); " > x &&
613 + echo "foo (); " >x &&
614 git diff --check
648 -
615 '
616
617 test_expect_success 'check trailing whitespace (trailing-space: on)' '
652 -
618 git config core.whitespace "trailing-space" &&
654 - echo "foo (); " > x &&
619 + echo "foo (); " >x &&
620 test_must_fail git diff --check
656 -
621 '
622
623 test_expect_success 'check space before tab in indent (space-before-tab: off)' '
660 -
624 # indent contains space followed by HT
625 git config core.whitespace "-space-before-tab" &&
663 - echo " foo ();" > x &&
626 + echo " foo ();" >x &&
627 git diff --check
665 -
628 '
629
630 test_expect_success 'check space before tab in indent (space-before-tab: on)' '
669 -
631 # indent contains space followed by HT
632 git config core.whitespace "space-before-tab" &&
672 - echo " foo (); " > x &&
633 + echo " foo (); " >x &&
634 test_must_fail git diff --check
674 -
635 '
636
637 test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '
678 -
638 git config core.whitespace "-indent-with-non-tab" &&
680 - echo " foo ();" > x &&
639 + echo " foo ();" >x &&
640 git diff --check
682 -
641 '
642
643 test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '
686 -
644 git config core.whitespace "indent-with-non-tab" &&
688 - echo " foo ();" > x &&
645 + echo " foo ();" >x &&
646 test_must_fail git diff --check
690 -
647 '
648
649 test_expect_success 'ditto, but tabwidth=9' '
694 -
650 git config core.whitespace "indent-with-non-tab,tabwidth=9" &&
651 git diff --check
697 -
652 '
653
654 test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' '
701 -
655 git config core.whitespace "indent-with-non-tab" &&
703 - echo " foo ();" > x &&
656 + echo " foo ();" >x &&
657 test_must_fail git diff --check
705 -
658 '
659
660 test_expect_success 'ditto, but tabwidth=10' '
709 -
661 git config core.whitespace "indent-with-non-tab,tabwidth=10" &&
662 test_must_fail git diff --check
712 -
663 '
664
665 test_expect_success 'ditto, but tabwidth=20' '
716 -
666 git config core.whitespace "indent-with-non-tab,tabwidth=20" &&
667 git diff --check
719 -
668 '
669
670 test_expect_success 'check tabs as indentation (tab-in-indent: off)' '
723 -
671 git config core.whitespace "-tab-in-indent" &&
725 - echo " foo ();" > x &&
672 + echo " foo ();" >x &&
673 git diff --check
727 -
674 '
675
676 test_expect_success 'check tabs as indentation (tab-in-indent: on)' '
731 -
677 git config core.whitespace "tab-in-indent" &&
733 - echo " foo ();" > x &&
678 + echo " foo ();" >x &&
679 test_must_fail git diff --check
735 -
680 '
681
682 test_expect_success 'check tabs and spaces as indentation (tab-in-indent: on)' '
739 -
683 git config core.whitespace "tab-in-indent" &&
741 - echo " foo ();" > x &&
684 + echo " foo ();" >x &&
685 test_must_fail git diff --check
743 -
686 '
687
688 test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' '
747 -
689 git config core.whitespace "tab-in-indent,tabwidth=1" &&
690 test_must_fail git diff --check
750 -
691 '
692
693 test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '
754 -
694 git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
756 - echo "foo ();" > x &&
695 + echo "foo ();" >x &&
696 test_must_fail git diff --check
758 -
697 '
698
699 test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '
762 -
700 git config --unset core.whitespace &&
764 - echo "x whitespace" > .gitattributes &&
765 - echo " foo ();" > x &&
701 + echo "x whitespace" >.gitattributes &&
702 + echo " foo ();" >x &&
703 git diff --check &&
704 rm -f .gitattributes
768 -
705 '
706
707 test_expect_success 'line numbers in --check output are correct' '
772 -
773 - echo "" > x &&
774 - echo "foo(); " >> x &&
708 + echo "" >x &&
709 + echo "foo(); " >>x &&
710 git diff --check | grep "x:2:"
776 -
711 '
712
713 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
@@ -878,26 +812,27 @@ test_expect_success 'setup diff colors' '
812 git config color.diff.commit yellow &&
813 git config color.diff.whitespace "normal red" &&
814
881 - git config core.autocrlf false
815 + git config core.autocrlf false &&
816 +
817 + cat >expected <<-\EOF
818 + <BOLD>diff --git a/x b/x<RESET>
819 + <BOLD>index 9daeafb..2874b91 100644<RESET>
820 + <BOLD>--- a/x<RESET>
821 + <BOLD>+++ b/x<RESET>
822 + <CYAN>@@ -1 +1,4 @@<RESET>
823 + test<RESET>
824 + <GREEN>+<RESET><GREEN>{<RESET>
825 + <GREEN>+<RESET><BRED> <RESET>
826 + <GREEN>+<RESET><GREEN>}<RESET>
827 + EOF
828 '
883 -cat >expected <<\EOF
884 -<BOLD>diff --git a/x b/x<RESET>
885 -<BOLD>index 9daeafb..2874b91 100644<RESET>
886 -<BOLD>--- a/x<RESET>
887 -<BOLD>+++ b/x<RESET>
888 -<CYAN>@@ -1 +1,4 @@<RESET>
889 - test<RESET>
890 -<GREEN>+<RESET><GREEN>{<RESET>
891 -<GREEN>+<RESET><BRED> <RESET>
892 -<GREEN>+<RESET><GREEN>}<RESET>
893 -EOF
829
830 test_expect_success 'diff that introduces a line with only tabs' '
831 git config core.whitespace blank-at-eol &&
832 git reset --hard &&
898 - echo "test" > x &&
833 + echo "test" >x &&
834 git commit -m "initial" x &&
900 - echo "{NTN}" | tr "NT" "\n\t" >> x &&
835 + echo "{NTN}" | tr "NT" "\n\t" >>x &&
836 git -c color.diff=always diff | test_decode_color >current &&
837 test_cmp expected current
838 '