xref: /openbsd-src/regress/usr.bin/column/column.sh (revision 78c0a9b23d73cd024541256952df121f7844e058)
132621cf4Sschwarze#!/bin/sh
232621cf4Sschwarze#
332621cf4Sschwarze# Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
432621cf4Sschwarze#
532621cf4Sschwarze# Permission to use, copy, modify, and distribute this software for any
632621cf4Sschwarze# purpose with or without fee is hereby granted, provided that the above
732621cf4Sschwarze# copyright notice and this permission notice appear in all copies.
832621cf4Sschwarze#
932621cf4Sschwarze# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1032621cf4Sschwarze# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1132621cf4Sschwarze# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1232621cf4Sschwarze# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1332621cf4Sschwarze# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1432621cf4Sschwarze# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1532621cf4Sschwarze# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1632621cf4Sschwarze
1732621cf4Sschwarzefail=0
1832621cf4Sschwarze
1932621cf4Sschwarzetc1()
2032621cf4Sschwarze{
2132621cf4Sschwarze	expected=$(echo -n "$3")
22*78c0a9b2Sschwarze	result=$(echo -n "$1" | column $2)
2332621cf4Sschwarze	if [ "X$result" != "X$expected" ]; then
2432621cf4Sschwarze		fail=$((fail+1))
2532621cf4Sschwarze		echo "argument: '$2'"
2632621cf4Sschwarze		echo "input:    '$1'"
2732621cf4Sschwarze		echo "expected: '$expected'"
2832621cf4Sschwarze		echo "result:   '$result'"
2932621cf4Sschwarze	fi
3032621cf4Sschwarze}
3132621cf4Sschwarze
3232621cf4Sschwarzetc()
3332621cf4Sschwarze{
3432621cf4Sschwarze	input=$1
3532621cf4Sschwarze	shift
3632621cf4Sschwarze	while [ $# -gt 1 ]; do
3732621cf4Sschwarze		tc1 "$input" "$1" "$2"
3832621cf4Sschwarze		shift 2
3932621cf4Sschwarze	done
4032621cf4Sschwarze}
4132621cf4Sschwarze
4232621cf4Sschwarzetc "1\n2\n\n3\n \t \n4" \
4332621cf4Sschwarze	"-c 7" "1\n2\n3\n4\n" \
4432621cf4Sschwarze	"-c 15" "1\n2\n3\n4\n" \
4532621cf4Sschwarze	"-c 16" "1\t3\n2\t4\n" \
4632621cf4Sschwarze	"-xc 7" "1\n2\n3\n4\n" \
4732621cf4Sschwarze	"-xc 16" "1\t2\n3\t4\n"
4832621cf4Sschwarzetc "one\ntwo\nthree\nfour\nfive\nsix\n  seven\neight\n" \
4932621cf4Sschwarze	"-c 23" "one\tfive\ntwo\tsix\nthree\t  seven\nfour\teight\n" \
5032621cf4Sschwarze	"-xc 23" "one\ttwo\nthree\tfour\nfive\tsix\n  seven\teight\n" \
5132621cf4Sschwarze	"-c 24" "one\tfour\t  seven\ntwo\tfive\teight\nthree\tsix\n" \
5232621cf4Sschwarze	"-xc 24" "one\ttwo\tthree\nfour\tfive\tsix\n  seven\teight\n"
5332621cf4Sschwarzetc "eleven\ntwelve\nthirteen\n" \
5432621cf4Sschwarze	"-c 31" "eleven\ntwelve\nthirteen\n" \
5532621cf4Sschwarze	"-c 32" "eleven\t\tthirteen\ntwelve\n" \
5632621cf4Sschwarze	"-xc 32" "eleven\t\ttwelve\nthirteen\n"
5732621cf4Sschwarzetc1 ".,word.,\n\t \t\n\nx.word\n" "-t -s .," "word\nx     word\n"
5832621cf4Sschwarzetc1 "1 2   3\n4  5\n" "-t" "1  2  3\n4  5\n"
5932621cf4Sschwarzetc1 "abc\tbc\tc\nab\tabc\tbc\na\tab\tabc\n" \
6032621cf4Sschwarze	"-t" "abc  bc   c\nab   abc  bc\na    ab   abc\n"
6132621cf4Sschwarze
6232621cf4Sschwarze[ $fail -eq 0 ] && exit 0
6332621cf4Sschwarzeecho "column: $fail tests failed"
6432621cf4Sschwarzeexit 1
65