opt_v.c revision 1.11
1/* $NetBSD: opt_v.c,v 1.11 2023/05/11 19:01:35 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 */
18void
19example(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 */
35void
36example(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 */
44There were 12 output lines and 1 comments
45(Lines with comments)/(Lines with code):  0.429
46//indent end
47
48
49//indent input
50void
51example(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
59void
60example(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
73int *function(void)
74{
75}
76//indent end
77
78//indent run -v
79/* Demonstrates line number counting in verbose mode. */
80
81int *
82function(void)
83{
84}
85There were 6 output lines and 1 comments
86(Lines with comments)/(Lines with code):  0.250
87//indent end
88/* In the above output, the '5' means 5 non-empty lines. */
89
90/*
91 * XXX: It's rather strange that -v writes to stdout, even in filter mode.
92 * This output belongs on stderr instead.
93 */
94
95
96/*
97 * Test line counting in preprocessor directives.
98 */
99//indent input
100#if 0
101int line = 1;
102int line = 2;
103int line = 3;
104#else
105int line = 5;
106#endif
107//indent end
108
109//indent run -v -di0
110#if 0
111int line = 1;
112int line = 2;
113int line = 3;
114#else
115int line = 5;
116#endif
117There were 3 output lines and 0 comments
118(Lines with comments)/(Lines with code):  0.000
119//indent end
120/*
121 * FIXME: The lines within the conditional compilation directives must be
122 * counted as well. TODO: Move stats out of parser_state.
123 */
124