xref: /netbsd-src/tests/usr.bin/indent/opt_v.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /* $NetBSD: opt_v.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
2 
3 /*
4  * Tests for the options '-v' and '-nv'.
5  *
6  * The option '-v' enables verbose mode. It outputs some information about
7  * what's going on under the hood, especially when lines are broken. It also
8  * outputs a few statistics about line counts and comments at the end.
9  *
10  * The option '-nv' disables verbose mode. Only errors and warnings are output
11  * in this mode, but no progress messages.
12  */
13 
14 //indent input
15 /*
16  * A block comment.
17  */
18 void
19 example(void)
20 {
21 	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
22 }
23 
24 /* $ The below comment is neither counted nor formatted. */
25 #define macro1 /* prefix */ suffix
26 
27 /* $ The below comment is formatted and counted. */
28 #define macro2 prefix /* suffix */
29 //indent end
30 
31 //indent run -v
32 /*
33  * A block comment.
34  */
35 void
36 example(void)
37 {
38 	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
39 }
40 
41 #define macro1 /* prefix */ suffix
42 
43 #define macro2 prefix		/* suffix */
44 There were 10 output lines and 2 comments
45 (Lines with comments)/(Lines with code):  0.571
46 //indent end
47 
48 
49 //indent input
50 void
51 example(void)
52 {
53 	int sum1 = 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21;
54 	int sum2 = (1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21);
55 }
56 //indent end
57 
58 //indent run -nv
59 void
60 example(void)
61 {
62 /* $ XXX: The following lines are too long and should thus be broken. */
63 /* $ XXX: If they are broken, -nv does NOT output 'Line broken'. */
64 	int		sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21;
65 	int		sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21);
66 }
67 //indent end
68 
69 
70 //indent input
71 /* Demonstrates line number counting in verbose mode. */
72 
73 int *function(void)
74 {}
75 //indent end
76 
77 //indent run -v
78 /* Demonstrates line number counting in verbose mode. */
79 
80 int *
81 function(void)
82 {
83 }
84 There were 5 output lines and 1 comments
85 (Lines with comments)/(Lines with code):  0.250
86 //indent end
87 /* In the above output, the '5' means 5 non-empty lines. */
88 
89 /*
90  * XXX: It's rather strange that -v writes to stdout, even in filter mode.
91  * This output belongs on stderr instead.
92  */
93 
94 
95 /*
96  * Test line counting in preprocessor directives.
97  */
98 //indent input
99 #if 0
100 int line = 1;
101 int line = 2;
102 int line = 3;
103 #else
104 int line = 5;
105 #endif
106 //indent end
107 
108 //indent run -v -di0
109 #if 0
110 int line = 1;
111 int line = 2;
112 int line = 3;
113 #else
114 int line = 5;
115 #endif
116 There were 3 output lines and 0 comments
117 (Lines with comments)/(Lines with code):  0.000
118 //indent end
119 /*
120  * FIXME: The lines within the conditional compilation directives must be
121  * counted as well. TODO: Move stats out of parser_state.
122  */
123