git: b7412da2e122 - main - asa: Add some unit tests.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 15 Jun 2023 19:28:03 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=b7412da2e122d9274341ef840c6918409bc523b3
commit b7412da2e122d9274341ef840c6918409bc523b3
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-06-15 19:23:26 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-06-15 19:24:59 +0000
asa: Add some unit tests.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D40564
---
etc/mtree/BSD.tests.dist | 2 +
usr.bin/asa/Makefile | 5 ++-
usr.bin/asa/tests/Makefile | 4 ++
usr.bin/asa/tests/asa_test.sh | 99 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 108 insertions(+), 2 deletions(-)
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index 8b9d0ac6bccd..d23ea1ac5b03 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -902,6 +902,8 @@
usr.bin
apply
..
+ asa
+ ..
awk
bugs-fixed
..
diff --git a/usr.bin/asa/Makefile b/usr.bin/asa/Makefile
index c2a221ae027b..a29db0f31781 100644
--- a/usr.bin/asa/Makefile
+++ b/usr.bin/asa/Makefile
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.2 1995/03/25 18:04:51 glass Exp $
-# $FreeBSD$
+.include <src.opts.mk>
PROG= asa
+HAS_TESTS=
+SUBDIR.${MK_TESTS}= tests
.include <bsd.prog.mk>
diff --git a/usr.bin/asa/tests/Makefile b/usr.bin/asa/tests/Makefile
new file mode 100644
index 000000000000..c8c0cde1b3a2
--- /dev/null
+++ b/usr.bin/asa/tests/Makefile
@@ -0,0 +1,4 @@
+PACKAGE= tests
+ATF_TESTS_SH= asa_test
+
+.include <bsd.test.mk>
diff --git a/usr.bin/asa/tests/asa_test.sh b/usr.bin/asa/tests/asa_test.sh
new file mode 100644
index 000000000000..429342d530e4
--- /dev/null
+++ b/usr.bin/asa/tests/asa_test.sh
@@ -0,0 +1,99 @@
+#
+# Copyright (c) 2023 Klara, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+a="The magic words are"
+b="Squeamish Ossifrage"
+
+atf_check_asa() {
+ atf_check -o file:"$2" asa "$1"
+ atf_check -o file:"$2" asa <"$1"
+ atf_check -o file:"$2" asa - <"$1"
+}
+
+atf_test_case space
+space_head() {
+ atf_set descr "First character on line is ' '"
+}
+space_body() {
+ printf " %s\n %s\n" "$a" "$b" >infile
+ printf "%s\n%s\n" "$a" "$b" >outfile
+ atf_check_asa infile outfile
+}
+
+atf_test_case zero
+zero_head() {
+ atf_set descr "First character on line is '0'"
+}
+zero_body() {
+ printf " %s\n0%s\n" "$a" "$b" >infile
+ printf "%s\n\n%s\n" "$a" "$b" >outfile
+ atf_check_asa infile outfile
+}
+
+atf_test_case one
+one_head() {
+ atf_set descr "First character on line is '1'"
+}
+one_body() {
+ printf " %s\n1%s\n" "$a" "$b" >infile
+ printf "%s\f%s\n" "$a" "$b" >outfile
+ atf_check_asa infile outfile
+}
+
+atf_test_case plus
+plus_head() {
+ atf_set descr "First character on line is '+'"
+}
+plus_body() {
+ printf " %s\n+%s\n" "$a" "$b" >infile
+ printf "%s\r%s\n" "$a" "$b" >outfile
+ atf_check_asa infile outfile
+}
+
+atf_test_case plus_top
+plus_top_head() {
+ atf_set descr "First character in input is '+'"
+}
+plus_top_body() {
+ printf "+%s\n+%s\n" "$a" "$b" >infile
+ printf "%s\r%s\n" "$a" "$b" >outfile
+ atf_check_asa infile outfile
+}
+
+atf_test_case stdout
+stdout_head() {
+ atf_set descr "Failure to write to stdout"
+}
+stdout_body() {
+ (
+ trap "" PIPE
+ echo " $a $b" | asa 2>stderr
+ echo $? >result
+ ) | true
+ atf_check -o inline:"1\n" cat result
+ atf_check -o match:"stdout" cat stderr
+}
+
+atf_test_case dashdash
+dashdash_head() {
+ atf_set descr "Use -- to end options"
+}
+dashdash_body() {
+ echo " $a $b" >-infile
+ atf_check -s not-exit:0 -e match:"illegal option" asa -infile
+ atf_check -o inline:"$a $b\n" asa -- -infile
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case space
+ atf_add_test_case zero
+ atf_add_test_case one
+ atf_add_test_case plus
+ atf_add_test_case plus_top
+ atf_add_test_case stdout
+ atf_add_test_case dashdash
+}