xref: /freebsd/usr.bin/unifdef/tests/unifdef_test.sh (revision 63f537551380d2dab29fa402ad1269feae17e594)
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#if FOO
14#endif /*
15*/
16EOF
17	atf_check -o file:f unifdef <f
18}
19
20atf_test_case redefine
21redefine_head() {
22	atf_set descr "redefine the same symbol"
23}
24redefine_body() {
25	cat >file <<EOF
26#if FOO
27a
28#else
29b
30#endif
31EOF
32	atf_check -s exit:1 -o inline:"a\n" unifdef -DFOO <file
33	atf_check -s exit:1 -o inline:"a\n" unifdef -UFOO -DFOO <file
34	atf_check -s exit:1 -o inline:"a\n" unifdef -DFOO=0 -DFOO <file
35	atf_check -s exit:1 -o inline:"b\n" unifdef -UFOO <file
36	atf_check -s exit:1 -o inline:"b\n" unifdef -DFOO -UFOO <file
37	atf_check -s exit:1 -o inline:"b\n" unifdef -DFOO -DFOO=0 <file
38}
39
40atf_init_test_cases() {
41	atf_add_test_case hash_comment
42	atf_add_test_case redefine
43}
44