xref: /freebsd/usr.bin/asa/tests/asa_test.sh (revision 911f0260390e18cf85f3dbf2c719b593efdc1e3c)
1#
2# Copyright (c) 2023 Klara, Inc.
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6
7a="The magic words are"
8b="Squeamish Ossifrage"
9
10atf_check_asa() {
11	atf_check -o file:"$2" asa "$1"
12	atf_check -o file:"$2" asa <"$1"
13	atf_check -o file:"$2" asa - <"$1"
14}
15
16atf_test_case space
17space_head() {
18	atf_set descr "First character on line is ' '"
19}
20space_body() {
21	printf " %s\n %s\n" "$a" "$b" >infile
22	printf "%s\n%s\n" "$a" "$b" >outfile
23	atf_check_asa infile outfile
24}
25
26atf_test_case zero
27zero_head() {
28	atf_set descr "First character on line is '0'"
29}
30zero_body() {
31	printf " %s\n0%s\n" "$a" "$b" >infile
32	printf "%s\n\n%s\n" "$a" "$b" >outfile
33	atf_check_asa infile outfile
34}
35
36atf_test_case one
37one_head() {
38	atf_set descr "First character on line is '1'"
39}
40one_body() {
41	printf " %s\n1%s\n" "$a" "$b" >infile
42	printf "%s\f%s\n" "$a" "$b" >outfile
43	atf_check_asa infile outfile
44}
45
46atf_test_case plus
47plus_head() {
48	atf_set descr "First character on line is '+'"
49}
50plus_body() {
51	printf " %s\n+%s\n" "$a" "$b" >infile
52	printf "%s\r%s\n" "$a" "$b" >outfile
53	atf_check_asa infile outfile
54}
55
56atf_test_case plus_top
57plus_top_head() {
58	atf_set descr "First character in input is '+'"
59}
60plus_top_body() {
61	printf "+%s\n+%s\n" "$a" "$b" >infile
62	printf "%s\r%s\n" "$a" "$b" >outfile
63	atf_check_asa infile outfile
64}
65
66atf_test_case stdout
67stdout_head() {
68	atf_set descr "Failure to write to stdout"
69}
70stdout_body() {
71	(
72		trap "" PIPE
73		echo " $a $b" | asa 2>stderr
74		echo $? >result
75	) | true
76	atf_check -o inline:"1\n" cat result
77	atf_check -o match:"stdout" cat stderr
78}
79
80atf_test_case dashdash
81dashdash_head() {
82	atf_set descr "Use -- to end options"
83}
84dashdash_body() {
85	echo " $a $b" >-infile
86	atf_check -s not-exit:0 -e match:"illegal option" asa -infile
87	atf_check -o inline:"$a $b\n" asa -- -infile
88}
89
90atf_init_test_cases()
91{
92	atf_add_test_case space
93	atf_add_test_case zero
94	atf_add_test_case one
95	atf_add_test_case plus
96	atf_add_test_case plus_top
97	atf_add_test_case stdout
98	atf_add_test_case dashdash
99}
100