2 # Copyright (c) 2024 Klara, Inc.
4 # SPDX-License-Identifier: BSD-2-Clause
8 atf_check uniq "$@" input actual
9 atf_check diff -u actual expected
10 atf_check uniq "$@" - actual <input
11 atf_check diff -u actual expected
12 atf_check -o file:expected uniq "$@" input
13 atf_check -o file:expected uniq "$@" <input
14 atf_check -o file:expected uniq "$@" - <input
19 atf_set descr "basic test without options"
22 printf "a\na\nb\nb\na\na\n" >input
23 printf "a\nb\na\n" >expected
29 atf_set descr "basic test showing counts"
32 printf "a\na\nb\nb\nb\na\na\na\na\n" >input
33 printf " 2 a\n 3 b\n 4 a\n" >expected
35 atf_check_uniq --count
38 atf_test_case repeated
40 atf_set descr "print repeated lines only"
43 printf "a\na\nb\na\na\n" >input
44 printf "a\na\n" >expected
46 atf_check_uniq --repeated
49 atf_test_case count_repeated
50 count_repeated_head() {
51 atf_set descr "count and print repeated lines only"
53 count_repeated_body() {
54 printf "a\na\nb\nb\na\n" >input
55 printf " 2 a\n 2 b\n" >expected
56 atf_check_uniq --count --repeated
59 atf_test_case all_repeated
61 atf_set descr "print every instance of repeated lines"
64 printf "a\na\nb\na\na\n" >input
65 printf "a\na\na\na\n" >expected
67 atf_check_uniq --all-repeated
70 atf_test_case skip_fields
72 atf_set descr "skip fields"
75 printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input
76 printf "1 a\n3 b\n5 a\n" >expected
79 atf_check_uniq --skip-fields 1
82 atf_test_case skip_fields_tab
83 skip_fields_tab_head() {
84 atf_set descr "skip fields (with tabs)"
86 skip_fields_tab_body() {
87 printf "1\ta\n2\ta\n3\tb\n4\tb\n5\ta\n6\ta\n" >input
88 printf "1\ta\n3\tb\n5\ta\n" >expected
91 atf_check_uniq --skip-fields 1
94 atf_test_case ignore_case
96 atf_set descr "ignore case"
99 printf "a\nA\nb\nB\na\nA\n" >input
100 printf "a\nb\na\n" >expected
102 atf_check_uniq --ignore-case
105 atf_test_case skip_chars
107 atf_set descr "skip chars"
110 printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input
111 printf "1 a\n3 b\n5 a\n" >expected
114 atf_check_uniq --skip-chars 2
119 atf_set descr "print non-repeated lines only"
122 printf "a\na\nb\na\na\n" >input
123 printf "b\n" >expected
125 atf_check_uniq --unique
128 atf_test_case count_unique
129 count_unique_head() {
130 atf_set descr "print non-repeated lines with count"
132 count_unique_body() {
133 printf "a\na\nb\n" >input
134 printf " 1 b\n" >expected
135 atf_check_uniq --unique --count
136 atf_check_uniq --count --unique
139 atf_test_case interactive
141 atf_set descr "test interactive use"
144 sh -c 'yes | stdbuf -oL uniq >actual' &
148 atf_check -o inline:"y\n" cat actual
151 atf_test_case interactive_repeated
152 interactive_repeated_head() {
153 atf_set descr "test interactive use with -d"
155 interactive_repeated_body() {
156 sh -c 'yes | stdbuf -oL uniq -d >actual' &
160 atf_check -o inline:"y\n" cat actual
165 atf_set descr "error writing to stdout"
170 echo a | uniq 2>stderr
173 atf_check -o inline:"1\n" cat result
174 atf_check -o match:"stdout" cat stderr
177 atf_init_test_cases()
179 atf_add_test_case basic
180 atf_add_test_case count
181 atf_add_test_case repeated
182 atf_add_test_case count_repeated
183 atf_add_test_case all_repeated
184 atf_add_test_case skip_fields
185 atf_add_test_case skip_fields_tab
186 atf_add_test_case ignore_case
187 atf_add_test_case skip_chars
188 atf_add_test_case unique
189 atf_add_test_case count_unique
190 atf_add_test_case interactive
191 atf_add_test_case interactive_repeated
192 atf_add_test_case stdout