@matheusbsbs / matheus-bagliano / commits / 79b0edc1a0
Fork 0

t4015: abstract away SHA-1-specific constants

Adjust the test so that it computes variables for object IDs instead of using hard-coded hashes. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Oct 28, 2019 at 00:59 UTC 79b0edc1a0ae856511d5923195c4d144461a955e
1 file changed +53 -36
t/t4015-diff-whitespace.sh
+53 -36
@@ -16,6 +16,7 @@ test_expect_success "Ray Lehtiniemi's example" '
16 } while (0);
17 EOF
18 git update-index --add x &&
19 + before=$(git rev-parse --short $(git hash-object x)) &&
20
21 cat <<-\EOF >x &&
22 do
@@ -24,10 +25,11 @@ test_expect_success "Ray Lehtiniemi's example" '
25 }
26 while (0);
27 EOF
28 + after=$(git rev-parse --short $(git hash-object x)) &&
29
28 - cat <<-\EOF >expect &&
30 + cat <<-EOF >expect &&
31 diff --git a/x b/x
30 - index adf3937..6edc172 100644
32 + index $before..$after 100644
33 --- a/x
34 +++ b/x
35 @@ -1,3 +1,5 @@
@@ -61,6 +63,7 @@ test_expect_success 'another test, without options' '
63 EOF
64
65 git update-index x &&
66 + before=$(git rev-parse --short $(git hash-object x)) &&
67
68 tr "_" " " <<-\EOF >x &&
69 _ whitespace at beginning
@@ -70,10 +73,11 @@ test_expect_success 'another test, without options' '
73 unchanged line
74 CR at end
75 EOF
76 + after=$(git rev-parse --short $(git hash-object x)) &&
77
74 - tr "Q_" "\015 " <<-\EOF >expect &&
78 + tr "Q_" "\015 " <<-EOF >expect &&
79 diff --git a/x b/x
76 - index d99af23..22d9f73 100644
80 + index $before..$after 100644
81 --- a/x
82 +++ b/x
83 @@ -1,6 +1,6 @@
@@ -108,9 +112,9 @@ test_expect_success 'another test, without options' '
112 git diff -w --ignore-cr-at-eol >out &&
113 test_must_be_empty out &&
114
111 - tr "Q_" "\015 " <<-\EOF >expect &&
115 + tr "Q_" "\015 " <<-EOF >expect &&
116 diff --git a/x b/x
113 - index d99af23..22d9f73 100644
117 + index $before..$after 100644
118 --- a/x
119 +++ b/x
120 @@ -1,6 +1,6 @@
@@ -132,9 +136,9 @@ test_expect_success 'another test, without options' '
136 git diff -b --ignore-cr-at-eol >out &&
137 test_cmp expect out &&
138
135 - tr "Q_" "\015 " <<-\EOF >expect &&
139 + tr "Q_" "\015 " <<-EOF >expect &&
140 diff --git a/x b/x
137 - index d99af23..22d9f73 100644
141 + index $before..$after 100644
142 --- a/x
143 +++ b/x
144 @@ -1,6 +1,6 @@
@@ -154,9 +158,9 @@ test_expect_success 'another test, without options' '
158 git diff --ignore-space-at-eol --ignore-cr-at-eol >out &&
159 test_cmp expect out &&
160
157 - tr "Q_" "\015 " <<-\EOF >expect &&
161 + tr "Q_" "\015 " <<-EOF >expect &&
162 diff --git a/x b/x
159 - index_d99af23..22d9f73 100644
163 + index_$before..$after 100644
164 --- a/x
165 +++ b/x
166 @@ -1,6 +1,6 @@
@@ -786,23 +790,25 @@ test_expect_success 'whitespace-only changes not reported' '
790 test_must_be_empty actual
791 '
792
789 -cat <<EOF >expect
790 -diff --git a/x b/z
791 -similarity index NUM%
792 -rename from x
793 -rename to z
794 -index 380c32a..a97b785 100644
795 -EOF
793 test_expect_success 'whitespace-only changes reported across renames' '
794 git reset --hard &&
795 for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
796 git add x &&
797 + before=$(git rev-parse --short $(git hash-object x)) &&
798 git commit -m "base" &&
799 sed -e "5s/^/ /" x >z &&
800 git rm x &&
801 git add z &&
802 + after=$(git rev-parse --short $(git hash-object z)) &&
803 git diff -w -M --cached |
804 sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
805 + cat <<-EOF >expect &&
806 + diff --git a/x b/z
807 + similarity index NUM%
808 + rename from x
809 + rename to z
810 + index $before..$after 100644
811 + EOF
812 test_cmp expect actual
813 '
814
@@ -858,13 +864,15 @@ test_expect_success 'diff that introduces a line with only tabs' '
864 git config core.whitespace blank-at-eol &&
865 git reset --hard &&
866 echo "test" >x &&
867 + before=$(git rev-parse --short $(git hash-object x)) &&
868 git commit -m "initial" x &&
869 echo "{NTN}" | tr "NT" "\n\t" >>x &&
870 + after=$(git rev-parse --short $(git hash-object x)) &&
871 git diff --color | test_decode_color >current &&
872
865 - cat >expected <<-\EOF &&
873 + cat >expected <<-EOF &&
874 <BOLD>diff --git a/x b/x<RESET>
867 - <BOLD>index 9daeafb..2874b91 100644<RESET>
875 + <BOLD>index $before..$after 100644<RESET>
876 <BOLD>--- a/x<RESET>
877 <BOLD>+++ b/x<RESET>
878 <CYAN>@@ -1 +1,4 @@<RESET>
@@ -883,19 +891,21 @@ test_expect_success 'diff that introduces and removes ws breakages' '
891 echo "0. blank-at-eol " &&
892 echo "1. blank-at-eol "
893 } >x &&
894 + before=$(git rev-parse --short $(git hash-object x)) &&
895 git commit -a --allow-empty -m preimage &&
896 {
897 echo "0. blank-at-eol " &&
898 echo "1. still-blank-at-eol " &&
899 echo "2. and a new line "
900 } >x &&
901 + after=$(git rev-parse --short $(git hash-object x)) &&
902
903 git diff --color |
904 test_decode_color >current &&
905
896 - cat >expected <<-\EOF &&
906 + cat >expected <<-EOF &&
907 <BOLD>diff --git a/x b/x<RESET>
898 - <BOLD>index d0233a2..700886e 100644<RESET>
908 + <BOLD>index $before..$after 100644<RESET>
909 <BOLD>--- a/x<RESET>
910 <BOLD>+++ b/x<RESET>
911 <CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -915,16 +925,18 @@ test_expect_success 'ws-error-highlight test setup' '
925 echo "0. blank-at-eol " &&
926 echo "1. blank-at-eol "
927 } >x &&
928 + before=$(git rev-parse --short $(git hash-object x)) &&
929 git commit -a --allow-empty -m preimage &&
930 {
931 echo "0. blank-at-eol " &&
932 echo "1. still-blank-at-eol " &&
933 echo "2. and a new line "
934 } >x &&
935 + after=$(git rev-parse --short $(git hash-object x)) &&
936
925 - cat >expect.default-old <<-\EOF &&
937 + cat >expect.default-old <<-EOF &&
938 <BOLD>diff --git a/x b/x<RESET>
927 - <BOLD>index d0233a2..700886e 100644<RESET>
939 + <BOLD>index $before..$after 100644<RESET>
940 <BOLD>--- a/x<RESET>
941 <BOLD>+++ b/x<RESET>
942 <CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -934,9 +946,9 @@ test_expect_success 'ws-error-highlight test setup' '
946 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
947 EOF
948
937 - cat >expect.all <<-\EOF &&
949 + cat >expect.all <<-EOF &&
950 <BOLD>diff --git a/x b/x<RESET>
939 - <BOLD>index d0233a2..700886e 100644<RESET>
951 + <BOLD>index $before..$after 100644<RESET>
952 <BOLD>--- a/x<RESET>
953 <BOLD>+++ b/x<RESET>
954 <CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -946,9 +958,9 @@ test_expect_success 'ws-error-highlight test setup' '
958 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
959 EOF
960
949 - cat >expect.none <<-\EOF
961 + cat >expect.none <<-EOF
962 <BOLD>diff --git a/x b/x<RESET>
951 - <BOLD>index d0233a2..700886e 100644<RESET>
963 + <BOLD>index $before..$after 100644<RESET>
964 <BOLD>--- a/x<RESET>
965 <BOLD>+++ b/x<RESET>
966 <CYAN>@@ -1,2 +1,3 @@<RESET>
@@ -1022,14 +1034,15 @@ test_expect_success 'detect moved code, complete file' '
1034 EOF
1035 git add test.c &&
1036 git commit -m "add main function" &&
1037 + file=$(git rev-parse --short HEAD:test.c) &&
1038 git mv test.c main.c &&
1039 test_config color.diff.oldMoved "normal red" &&
1040 test_config color.diff.newMoved "normal green" &&
1041 git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
1029 - cat >expected <<-\EOF &&
1042 + cat >expected <<-EOF &&
1043 <BOLD>diff --git a/main.c b/main.c<RESET>
1044 <BOLD>new file mode 100644<RESET>
1032 - <BOLD>index 0000000..a986c57<RESET>
1045 + <BOLD>index 0000000..$file<RESET>
1046 <BOLD>--- /dev/null<RESET>
1047 <BOLD>+++ b/main.c<RESET>
1048 <CYAN>@@ -0,0 +1,5 @@<RESET>
@@ -1040,7 +1053,7 @@ test_expect_success 'detect moved code, complete file' '
1053 <BGREEN>+<RESET><BGREEN>}<RESET>
1054 <BOLD>diff --git a/test.c b/test.c<RESET>
1055 <BOLD>deleted file mode 100644<RESET>
1043 - <BOLD>index a986c57..0000000<RESET>
1056 + <BOLD>index $file..0000000<RESET>
1057 <BOLD>--- a/test.c<RESET>
1058 <BOLD>+++ /dev/null<RESET>
1059 <CYAN>@@ -1,5 +0,0 @@<RESET>
@@ -1094,6 +1107,8 @@ test_expect_success 'detect malicious moved code, inside file' '
1107 EOF
1108 git add main.c test.c &&
1109 git commit -m "add main and test file" &&
1110 + before_main=$(git rev-parse --short HEAD:main.c) &&
1111 + before_test=$(git rev-parse --short HEAD:test.c) &&
1112 cat <<-\EOF >main.c &&
1113 #include<stdio.h>
1114 int stuff()
@@ -1126,10 +1141,12 @@ test_expect_success 'detect malicious moved code, inside file' '
1141 bar();
1142 }
1143 EOF
1144 + after_main=$(git rev-parse --short $(git hash-object main.c)) &&
1145 + after_test=$(git rev-parse --short $(git hash-object test.c)) &&
1146 git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
1130 - cat <<-\EOF >expected &&
1147 + cat <<-EOF >expected &&
1148 <BOLD>diff --git a/main.c b/main.c<RESET>
1132 - <BOLD>index 27a619c..7cf9336 100644<RESET>
1149 + <BOLD>index $before_main..$after_main 100644<RESET>
1150 <BOLD>--- a/main.c<RESET>
1151 <BOLD>+++ b/main.c<RESET>
1152 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
@@ -1147,7 +1164,7 @@ test_expect_success 'detect malicious moved code, inside file' '
1164 {<RESET>
1165 foo();<RESET>
1166 <BOLD>diff --git a/test.c b/test.c<RESET>
1150 - <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1167 + <BOLD>index $before_test..$after_test 100644<RESET>
1168 <BOLD>--- a/test.c<RESET>
1169 <BOLD>+++ b/test.c<RESET>
1170 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>
@@ -1176,9 +1193,9 @@ test_expect_success 'plain moved code, inside file' '
1193 test_config color.diff.newMovedAlternative "yellow" &&
1194 # needs previous test as setup
1195 git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
1179 - cat <<-\EOF >expected &&
1196 + cat <<-EOF >expected &&
1197 <BOLD>diff --git a/main.c b/main.c<RESET>
1181 - <BOLD>index 27a619c..7cf9336 100644<RESET>
1198 + <BOLD>index $before_main..$after_main 100644<RESET>
1199 <BOLD>--- a/main.c<RESET>
1200 <BOLD>+++ b/main.c<RESET>
1201 <CYAN>@@ -5,13 +5,6 @@<RESET> <RESET>printf("Hello ");<RESET>
@@ -1196,7 +1213,7 @@ test_expect_success 'plain moved code, inside file' '
1213 {<RESET>
1214 foo();<RESET>
1215 <BOLD>diff --git a/test.c b/test.c<RESET>
1199 - <BOLD>index 1dc1d85..2bedec9 100644<RESET>
1216 + <BOLD>index $before_test..$after_test 100644<RESET>
1217 <BOLD>--- a/test.c<RESET>
1218 <BOLD>+++ b/test.c<RESET>
1219 <CYAN>@@ -4,6 +4,13 @@<RESET> <RESET>int bar()<RESET>