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