xref: /freebsd/usr.bin/unifdef/tests/unifdef_test.sh (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1#
2# Copyright (c) 2023 Klara, Inc.
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6
7atf_test_case hash_comment
8hash_comment_head() {
9	atf_set descr "multiline comment follows directive"
10}
11hash_comment_body() {
12	cat >f <<EOF
13
14*/
15EOF
16	atf_check -o file:f unifdef <f
17}
18
19atf_test_case redefine
20redefine_head() {
21	atf_set descr "redefine the same symbol"
22}
23redefine_body() {
24	cat >file <<EOF
25#if FOO
26a
27#else
28b
29#endif
30EOF
31	atf_check -s exit:1 -o inline:"a\n" unifdef -DFOO <file
32	atf_check -s exit:1 -o inline:"a\n" unifdef -UFOO -DFOO <file
33	atf_check -s exit:1 -o inline:"a\n" unifdef -DFOO=0 -DFOO <file
34	atf_check -s exit:1 -o inline:"b\n" unifdef -UFOO <file
35	atf_check -s exit:1 -o inline:"b\n" unifdef -DFOO -UFOO <file
36	atf_check -s exit:1 -o inline:"b\n" unifdef -DFOO -DFOO=0 <file
37}
38
39atf_init_test_cases() {
40	atf_add_test_case hash_comment
41	atf_add_test_case redefine
42}
43