git: 6f2b1b56ac3d - main - column(1): add tests
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 07 May 2025 09:52:40 UTC
The branch main has been updated by ivy:
URL: https://cgit.FreeBSD.org/src/commit/?id=6f2b1b56ac3dd154bd98f5a7ea075abcb4356560
commit 6f2b1b56ac3dd154bd98f5a7ea075abcb4356560
Author: Lexi Winter <ivy@FreeBSD.org>
AuthorDate: 2025-05-07 09:27:20 +0000
Commit: Lexi Winter <ivy@FreeBSD.org>
CommitDate: 2025-05-07 09:27:20 +0000
column(1): add tests
Reviewed by: des
Approved by: des (mentor)
Differential Revision: https://reviews.freebsd.org/D49911
---
etc/mtree/BSD.tests.dist | 2 +
usr.bin/column/Makefile | 5 ++
usr.bin/column/tests/Makefile | 3 +
usr.bin/column/tests/column.sh | 170 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+)
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index bb62c44403d2..bfd21607ed4d 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -1087,6 +1087,8 @@
..
col
..
+ column
+ ..
comm
..
compress
diff --git a/usr.bin/column/Makefile b/usr.bin/column/Makefile
index b0b88c086b41..5ead3de91932 100644
--- a/usr.bin/column/Makefile
+++ b/usr.bin/column/Makefile
@@ -1,3 +1,8 @@
+.include <src.opts.mk>
+
PROG= column
+HAS_TESTS=
+SUBDIR.${MK_TESTS}= tests
+
.include <bsd.prog.mk>
diff --git a/usr.bin/column/tests/Makefile b/usr.bin/column/tests/Makefile
new file mode 100644
index 000000000000..40a7767f0dc0
--- /dev/null
+++ b/usr.bin/column/tests/Makefile
@@ -0,0 +1,3 @@
+ATF_TESTS_SH= column
+
+.include <bsd.test.mk>
diff --git a/usr.bin/column/tests/column.sh b/usr.bin/column/tests/column.sh
new file mode 100644
index 000000000000..c7c6502098d4
--- /dev/null
+++ b/usr.bin/column/tests/column.sh
@@ -0,0 +1,170 @@
+# SPDX-License-Identifier: ISC
+#
+# Copyright (c) 2025 Lexi Winter
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+atf_test_case "basic"
+basic_head()
+{
+ atf_set descr "Basic column(1) with default options"
+}
+
+basic_body()
+{
+ cat >input.1 <<END
+this is the first input file
+it has multiple lines
+END
+
+ cat >input.2 <<END
+here lies the second input file
+some lines
+
+are empty
+END
+
+ cat >input.3 <<END
+third of the input files am i
+and i have
+more
+lines
+than before
+END
+
+ cat >expected <<END
+this is the first input file are empty lines
+it has multiple lines third of the input files am i than before
+here lies the second input file and i have
+some lines more
+END
+
+ atf_check -o save:output column -c120 input.1 input.2 input.3
+ atf_check diff expected output
+}
+
+atf_test_case "rows"
+rows_head()
+{
+ atf_set descr "column(1) with -x (row-wise) option"
+}
+
+rows_body()
+{
+ cat >input.1 <<END
+this is the first input file
+it has multiple lines
+END
+
+ cat >input.2 <<END
+here lies the second input file
+some lines
+
+are empty
+END
+
+ cat >input.3 <<END
+third of the input files am i
+and i have
+more
+lines
+than before
+END
+
+ cat >expected <<END
+this is the first input file it has multiple lines here lies the second input file
+some lines are empty third of the input files am i
+and i have more lines
+than before
+END
+
+ atf_check -o save:output column -xc120 input.1 input.2 input.3
+ atf_check diff expected output
+}
+
+atf_test_case "basic_table"
+basic_table_head()
+{
+ atf_set descr "column(1) with -t (table) option"
+}
+
+basic_table_body()
+{
+ cat >input.1 <<END
+1 2 3 4
+foo bar baz quux
+END
+
+ cat >input.2 <<END
+fie fi fo fum
+END
+
+ cat >input.3 <<END
+where did my
+fields go
+argh
+END
+
+ cat >expected <<END
+1 2 3 4
+foo bar baz quux
+fie fi fo fum
+where did my
+fields go
+argh
+END
+
+ atf_check -o save:output column -tc120 input.1 input.2 input.3
+ atf_check diff expected output
+}
+
+atf_test_case "colonic_table"
+colonic_table_head()
+{
+ atf_set descr "column(1) with -t (table) and -s options"
+}
+
+colonic_table_body()
+{
+ cat >input <<END
+one:two.three
+four.five:six
+seven.:eight.:nine
+:ein
+::zwei
+drei..
+vier:
+
+END
+
+ cat >expected <<END
+one two three
+four five six
+seven eight nine
+ein
+zwei
+drei
+vier
+END
+
+ atf_check -o save:output column -tc120 -s:. input
+ atf_check diff expected output
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case basic
+ atf_add_test_case rows
+ atf_add_test_case basic_table
+ atf_add_test_case colonic_table
+}