xref: /netbsd-src/tests/usr.bin/indent/opt_bacc.c (revision 867d70fc718005c0918b8b8b2f9d7f2d52d0a0db)
1 /* $NetBSD: opt_bacc.c,v 1.10 2022/04/24 09:04:12 rillig Exp $ */
2 
3 /*
4  * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional
5  * compilation").
6  *
7  * The option '-bacc' forces a blank line around every conditional compilation
8  * block.  For example, in front of every #ifdef and after every #endif.
9  * Other blank lines surrounding such blocks are swallowed.
10  *
11  * The option '-nbacc' TODO.
12  */
13 
14 
15 /* Example code without surrounding blank lines. */
16 //indent input
17 int		a;
18 #if 0
19 int		b;
20 #endif
21 int		c;
22 //indent end
23 
24 /*
25  * XXX: As of 2021-11-19, the option -bacc has no effect on declarations since
26  * process_type resets out.blank_line_before unconditionally.
27  */
28 //indent run -bacc
29 int		a;
30 /* $ FIXME: expecting a blank line here */
31 #if 0
32 int		b;
33 #endif
34 /* $ FIXME: expecting a blank line here */
35 int		c;
36 //indent end
37 
38 /*
39  * With '-nbacc' the code is unchanged since there are no blank lines to
40  * remove.
41  */
42 //indent run-equals-input -nbacc
43 
44 
45 /* Example code containing blank lines. */
46 //indent input
47 int		space_a;
48 
49 #if 0
50 
51 int		space_b;
52 
53 #endif
54 
55 int		space_c;
56 //indent end
57 
58 //indent run -bacc
59 int		space_a;
60 /* $ FIXME: expecting a blank line here */
61 #if 0
62 
63 /* $ FIXME: expecting NO blank line here */
64 int		space_b;
65 #endif
66 
67 int		space_c;
68 //indent end
69 
70 /* The option '-nbacc' does not remove anything. */
71 //indent run-equals-input -nbacc
72 
73 
74 /*
75  * Preprocessing directives can also occur in function bodies.
76  */
77 //indent input
78 const char *
79 os_name(void)
80 {
81 #if defined(__NetBSD__) || defined(__FreeBSD__)
82 	return "BSD";
83 #else
84 	return "unknown";
85 #endif
86 }
87 //indent end
88 
89 //indent run -bacc
90 const char *
91 os_name(void)
92 {
93 /* $ FIXME: expecting a blank line here. */
94 #if defined(__NetBSD__) || defined(__FreeBSD__)
95 /* $ FIXME: expecting NO blank line here. */
96 
97 	return "BSD";
98 #else
99 /* $ FIXME: expecting NO blank line here. */
100 
101 	return "unknown";
102 #endif
103 /* $ FIXME: expecting a blank line here. */
104 }
105 //indent end
106 
107 //indent run-equals-input -nbacc
108 
109 
110 /*
111  * Test nested preprocessor directives.
112  */
113 //indent input
114 #if outer
115 #if inner
116 int decl;
117 #endif
118 #endif
119 //indent end
120 
121 //indent run -di0 -bacc
122 #if outer
123 
124 #if inner
125 int decl;
126 #endif
127 
128 #endif
129 //indent end
130 
131 //indent run-equals-input -di0 -nbacc
132 
133 
134 /*
135  * Test nested preprocessor directives that are interleaved with declarations.
136  */
137 //indent input
138 #ifdef outer
139 int outer_above;
140 #ifdef inner
141 int inner;
142 #endif
143 int outer_below;
144 #endif
145 //indent end
146 
147 //indent run-equals-input -di0 -bacc
148 
149 //indent run-equals-input -di0 -nbacc
150