Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/usr.bin/column/tests/column.sh
34860 views
1
# SPDX-License-Identifier: ISC
2
#
3
# Copyright (c) 2025 Lexi Winter
4
#
5
# Permission to use, copy, modify, and distribute this software for any
6
# purpose with or without fee is hereby granted, provided that the above
7
# copyright notice and this permission notice appear in all copies.
8
#
9
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17
atf_test_case "basic"
18
basic_head()
19
{
20
atf_set descr "Basic column(1) with default options"
21
}
22
23
basic_body()
24
{
25
cat >input.1 <<END
26
this is the first input file
27
it has multiple lines
28
END
29
30
cat >input.2 <<END
31
here lies the second input file
32
some lines
33
34
are empty
35
END
36
37
cat >input.3 <<END
38
third of the input files am i
39
and i have
40
more
41
lines
42
than before
43
END
44
45
cat >expected <<END
46
this is the first input file are empty lines
47
it has multiple lines third of the input files am i than before
48
here lies the second input file and i have
49
some lines more
50
END
51
52
atf_check -o save:output column -c120 input.1 input.2 input.3
53
atf_check diff expected output
54
}
55
56
atf_test_case "rows"
57
rows_head()
58
{
59
atf_set descr "column(1) with -x (row-wise) option"
60
}
61
62
rows_body()
63
{
64
cat >input.1 <<END
65
this is the first input file
66
it has multiple lines
67
END
68
69
cat >input.2 <<END
70
here lies the second input file
71
some lines
72
73
are empty
74
END
75
76
cat >input.3 <<END
77
third of the input files am i
78
and i have
79
more
80
lines
81
than before
82
END
83
84
cat >expected <<END
85
this is the first input file it has multiple lines here lies the second input file
86
some lines are empty third of the input files am i
87
and i have more lines
88
than before
89
END
90
91
atf_check -o save:output column -xc120 input.1 input.2 input.3
92
atf_check diff expected output
93
}
94
95
atf_test_case "basic_table"
96
basic_table_head()
97
{
98
atf_set descr "column(1) with -t (table) option"
99
}
100
101
basic_table_body()
102
{
103
cat >input.1 <<END
104
1 2 3 4
105
foo bar baz quux
106
END
107
108
cat >input.2 <<END
109
fie fi fo fum
110
END
111
112
cat >input.3 <<END
113
where did my
114
fields go
115
argh
116
END
117
118
cat >expected <<END
119
1 2 3 4
120
foo bar baz quux
121
fie fi fo fum
122
where did my
123
fields go
124
argh
125
END
126
127
atf_check -o save:output column -tc120 input.1 input.2 input.3
128
atf_check diff expected output
129
}
130
131
atf_test_case "colonic_table"
132
colonic_table_head()
133
{
134
atf_set descr "column(1) with -t (table) and -s options"
135
}
136
137
colonic_table_body()
138
{
139
cat >input <<END
140
one:two.three
141
four.five:six
142
seven.:eight.:nine
143
:ein
144
::zwei
145
drei..
146
vier:
147
:
148
149
END
150
151
cat >expected <<END
152
one two three
153
four five six
154
seven eight nine
155
ein
156
zwei
157
drei
158
vier
159
END
160
161
atf_check -o save:output column -tc120 -s:. input
162
atf_check diff expected output
163
}
164
165
atf_test_case "ncols"
166
ncols_head()
167
{
168
atf_set descr "column(1) with -t (table) and -s and -l options"
169
}
170
171
ncols_body()
172
{
173
cat >input <<END
174
now we have five columns
175
here there are four
176
now only three
177
just two
178
one
179
END
180
181
cat >expected <<END
182
now we have five columns
183
here there are four
184
now only three
185
just two
186
one
187
END
188
189
atf_check -o save:output column -tc120 -l3 input
190
atf_check diff expected output
191
}
192
193
atf_init_test_cases()
194
{
195
atf_add_test_case basic
196
atf_add_test_case rows
197
atf_add_test_case basic_table
198
atf_add_test_case colonic_table
199
atf_add_test_case ncols
200
}
201
202