Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/usr.bin/asa/tests/asa_test.sh
34865 views
1
#
2
# Copyright (c) 2023 Klara, Inc.
3
#
4
# SPDX-License-Identifier: BSD-2-Clause
5
#
6
7
a="The magic words are"
8
b="Squeamish Ossifrage"
9
10
atf_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
16
atf_test_case space
17
space_head() {
18
atf_set descr "First character on line is ' '"
19
}
20
space_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
26
atf_test_case zero
27
zero_head() {
28
atf_set descr "First character on line is '0'"
29
}
30
zero_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
36
atf_test_case one
37
one_head() {
38
atf_set descr "First character on line is '1'"
39
}
40
one_body() {
41
printf "1%s\n1%s\n" "$a" "$b" >infile
42
printf "\f%s\n\f%s\n" "$a" "$b" >outfile
43
atf_check_asa infile outfile
44
}
45
46
atf_test_case plus
47
plus_head() {
48
atf_set descr "First character on line is '+'"
49
}
50
plus_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
56
atf_test_case plus_top
57
plus_top_head() {
58
atf_set descr "First character in input is '+'"
59
}
60
plus_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
66
atf_test_case stdout
67
stdout_head() {
68
atf_set descr "Failure to write to stdout"
69
}
70
stdout_body() {
71
(
72
trap "" PIPE
73
sleep 1
74
echo " $a $b" | asa 2>stderr
75
echo $? >result
76
) | true
77
atf_check -o inline:"1\n" cat result
78
atf_check -o match:"stdout" cat stderr
79
}
80
81
atf_test_case dashdash
82
dashdash_head() {
83
atf_set descr "Use -- to end options"
84
}
85
dashdash_body() {
86
echo " $a $b" >-infile
87
atf_check -s not-exit:0 -e match:"illegal option" asa -infile
88
atf_check -o inline:"$a $b\n" asa -- -infile
89
}
90
91
atf_test_case unterminated
92
unterminated_head() {
93
atf_set descr "Unterminated input"
94
}
95
unterminated_body() {
96
printf " %s\n %s" "$a" "$b" >infile
97
printf "%s\n%s" "$a" "$b" >outfile
98
atf_check_asa infile outfile
99
}
100
101
atf_init_test_cases()
102
{
103
atf_add_test_case space
104
atf_add_test_case zero
105
atf_add_test_case one
106
atf_add_test_case plus
107
atf_add_test_case plus_top
108
atf_add_test_case stdout
109
atf_add_test_case dashdash
110
atf_add_test_case unterminated
111
}
112
113