1# $FreeBSD$ 2 3atf_test_case simple 4atf_test_case unified 5atf_test_case header 6atf_test_case header_ns 7atf_test_case ifdef 8atf_test_case group_format 9atf_test_case side_by_side 10atf_test_case brief_format 11atf_test_case b230049 12atf_test_case b252515 13atf_test_case Bflag 14atf_test_case Nflag 15atf_test_case tabsize 16atf_test_case conflicting_format 17atf_test_case label 18atf_test_case report_identical 19 20simple_body() 21{ 22 atf_check -o file:$(atf_get_srcdir)/simple.out -s eq:1 \ 23 diff "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in" 24 25 atf_check -o file:$(atf_get_srcdir)/simple_e.out -s eq:1 \ 26 diff -e "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in" 27 28 atf_check -o file:$(atf_get_srcdir)/simple_u.out -s eq:1 \ 29 diff -u -L input1 -L input2 "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in" 30 31 atf_check -o file:$(atf_get_srcdir)/simple_n.out -s eq:1 \ 32 diff -n "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in" 33 34 atf_check -o inline:"Files $(atf_get_srcdir)/input1.in and $(atf_get_srcdir)/input2.in differ\n" -s eq:1 \ 35 diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input2.in" 36 37 atf_check \ 38 diff -q "$(atf_get_srcdir)/input1.in" "$(atf_get_srcdir)/input1.in" 39 40 atf_check -o file:$(atf_get_srcdir)/simple_i.out -s eq:1 \ 41 diff -i "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" 42 43 atf_check -o file:$(atf_get_srcdir)/simple_w.out -s eq:1 \ 44 diff -w "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" 45 46 atf_check -o file:$(atf_get_srcdir)/simple_b.out -s eq:1 \ 47 diff -b "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" 48 49 atf_check -o file:$(atf_get_srcdir)/simple_p.out -s eq:1 \ 50 diff --label input_c1.in --label input_c2.in -p "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" 51} 52 53unified_body() 54{ 55 atf_check -o file:$(atf_get_srcdir)/unified_p.out -s eq:1 \ 56 diff -up -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" 57 atf_check -o file:$(atf_get_srcdir)/unified_9999.out -s eq:1 \ 58 diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" 59} 60 61b230049_body() 62{ 63 printf 'a\nb\r\nc\n' > b230049_a.in 64 printf 'a\r\nb\r\nc\r\n' > b230049_b.in 65 atf_check -o empty -s eq:0 \ 66 diff -up --strip-trailing-cr -L b230049_a.in -L b230049_b.in \ 67 b230049_a.in b230049_b.in 68} 69 70b252515_body() 71{ 72 printf 'a b\n' > b252515_a.in 73 printf 'a b\n' > b252515_b.in 74 atf_check -o empty -s eq:0 \ 75 diff -qw b252515_a.in b252515_b.in 76} 77 78header_body() 79{ 80 export TZ=UTC 81 : > empty 82 echo hello > hello 83 touch -d 2015-04-03T01:02:03 empty 84 touch -d 2016-12-22T11:22:33 hello 85 atf_check -o "file:$(atf_get_srcdir)/header.out" -s eq:1 \ 86 diff -u empty hello 87} 88 89header_ns_body() 90{ 91 export TZ=UTC 92 : > empty 93 echo hello > hello 94 touch -d 2015-04-03T01:02:03.123456789 empty 95 touch -d 2016-12-22T11:22:33.987654321 hello 96 atf_check -o "file:$(atf_get_srcdir)/header_ns.out" -s eq:1 \ 97 diff -u empty hello 98} 99 100ifdef_body() 101{ 102 atf_check -o file:$(atf_get_srcdir)/ifdef.out -s eq:1 \ 103 diff -D PLOP "$(atf_get_srcdir)/input_c1.in" \ 104 "$(atf_get_srcdir)/input_c2.in" 105} 106 107group_format_body() 108{ 109 atf_check -o file:$(atf_get_srcdir)/group-format.out -s eq:1 \ 110 diff --changed-group-format='<<<<<<< (local) 111%<======= 112%>>>>>>>> (stock) 113' "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in" 114} 115 116side_by_side_body() 117{ 118 atf_check -o save:A printf "A\nB\nC\n" 119 atf_check -o save:B printf "D\nB\nE\n" 120 121 exp_output=$(printf "A[[:space:]]+|[[:space:]]+D\nB[[:space:]]+B\nC[[:space:]]+|[[:space:]]+E") 122 exp_output_suppressed=$(printf "A[[:space:]]+|[[:space:]]+D\nC[[:space:]]+|[[:space:]]+E") 123 124 atf_check -o match:"$exp_output" -s exit:1 \ 125 diff --side-by-side A B 126 atf_check -o match:"$exp_output" -s exit:1 \ 127 diff -y A B 128 atf_check -o match:"$exp_output_suppressed" -s exit:1 \ 129 diff -y --suppress-common-lines A B 130 atf_check -o match:"$exp_output_suppressed" -s exit:1 \ 131 diff -W 65 -y --suppress-common-lines A B 132} 133 134brief_format_body() 135{ 136 atf_check mkdir A B 137 138 atf_check -x "echo 1 > A/test-file" 139 atf_check -x "echo 2 > B/test-file" 140 141 atf_check cp -Rf A C 142 atf_check cp -Rf A D 143 144 atf_check -x "echo 3 > D/another-test-file" 145 146 atf_check \ 147 -s exit:1 \ 148 -o inline:"Files A/test-file and B/test-file differ\n" \ 149 diff -rq A B 150 151 atf_check diff -rq A C 152 153 atf_check \ 154 -s exit:1 \ 155 -o inline:"Only in D: another-test-file\n" \ 156 diff -rq A D 157 158 atf_check \ 159 -s exit:1 \ 160 -o inline:"Files A/another-test-file and D/another-test-file differ\n" \ 161 diff -Nrq A D 162} 163 164Bflag_body() 165{ 166 atf_check -x 'printf "A\nB\n" > A' 167 atf_check -x 'printf "A\n\nB\n" > B' 168 atf_check -x 'printf "A\n \nB\n" > C' 169 atf_check -x 'printf "A\nC\nB\n" > D' 170 atf_check -x 'printf "A\nB\nC\nD\nE\nF\nG\nH" > E' 171 atf_check -x 'printf "A\n\nB\nC\nD\nE\nF\nX\nH" > F' 172 173 atf_check -s exit:0 -o inline:"" diff -B A B 174 atf_check -s exit:1 -o file:"$(atf_get_srcdir)/Bflag_C.out" diff -B A C 175 atf_check -s exit:1 -o file:"$(atf_get_srcdir)/Bflag_D.out" diff -B A D 176 atf_check -s exit:1 -o file:"$(atf_get_srcdir)/Bflag_F.out" diff -B E F 177} 178 179Nflag_body() 180{ 181 atf_check -x 'printf "foo" > A' 182 183 atf_check -s exit:1 -o ignore -e ignore diff -N A NOFILE 184 atf_check -s exit:1 -o ignore -e ignore diff -N NOFILE A 185 atf_check -s exit:2 -o ignore -e ignore diff -N NOFILE1 NOFILE2 186} 187 188tabsize_body() 189{ 190 printf "\tA\n" > A 191 printf "\tB\n" > B 192 193 atf_check -s exit:1 \ 194 -o inline:"1c1\n< A\n---\n> B\n" \ 195 diff -t --tabsize 1 A B 196} 197 198conflicting_format_body() 199{ 200 printf "\tA\n" > A 201 printf "\tB\n" > B 202 203 atf_check -s exit:2 -e ignore diff -c -u A B 204 atf_check -s exit:2 -e ignore diff -e -f A B 205 atf_check -s exit:2 -e ignore diff -y -q A B 206 atf_check -s exit:2 -e ignore diff -q -u A B 207 atf_check -s exit:2 -e ignore diff -q -c A B 208 atf_check -s exit:2 -e ignore diff --normal -c A B 209 atf_check -s exit:2 -e ignore diff -c --normal A B 210 211 atf_check -s exit:1 -o ignore -e ignore diff -u -u A B 212 atf_check -s exit:1 -o ignore -e ignore diff -e -e A B 213 atf_check -s exit:1 -o ignore -e ignore diff -y -y A B 214 atf_check -s exit:1 -o ignore -e ignore diff -q -q A B 215 atf_check -s exit:1 -o ignore -e ignore diff -c -c A B 216 atf_check -s exit:1 -o ignore -e ignore diff --normal --normal A B 217} 218 219label_body() 220{ 221 printf "\tA\n" > A 222 223 atf_check -o inline:"Files hello and world are identical\n" \ 224 -s exit:0 diff --label hello --label world -s A A 225 226 atf_check -o inline:"Binary files hello and world differ\n" \ 227 -s exit:1 diff --label hello --label world `which diff` `which ls` 228} 229 230report_identical_body() 231{ 232 printf "\tA\n" > A 233 printf "\tB\n" > B 234 chmod -r B 235 atf_check -s exit:2 -e inline:"diff: B: Permission denied\n" \ 236 -o empty diff -s A B 237} 238 239atf_init_test_cases() 240{ 241 atf_add_test_case simple 242 atf_add_test_case unified 243 atf_add_test_case header 244 atf_add_test_case header_ns 245 atf_add_test_case ifdef 246 atf_add_test_case group_format 247 atf_add_test_case side_by_side 248 atf_add_test_case brief_format 249 atf_add_test_case b230049 250 atf_add_test_case b252515 251 atf_add_test_case Bflag 252 atf_add_test_case Nflag 253 atf_add_test_case tabsize 254 atf_add_test_case conflicting_format 255 atf_add_test_case label 256 atf_add_test_case report_identical 257} 258