opt_v.c revision 1.3
1/* $NetBSD: opt_v.c,v 1.3 2021/10/22 19:27:53 rillig Exp $ */
2/* $FreeBSD$ */
3
4/*
5 * Tests for the options '-v' and '-nv'.
6 *
7 * The option '-v' enables verbose mode. It outputs some information about
8 * what's going on under the hood, especially when lines are broken. It also
9 * outputs a few statistics about line counts and comments at the end.
10 *
11 * The option '-nv' disables verbose mode. Only errors and warnings are output
12 * in this mode, but no progress messages.
13 */
14
15#indent input
16/*
17 * A long comment.
18 */
19void
20example(void)
21{
22	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
23}
24
25/* $ This comment is neither counted nor formatted. */
26#define macro1 /* prefix */ suffix
27
28/* $ This comment is formatted and counted. */
29#define macro2 prefix /* suffix */
30#indent end
31
32#indent run -v
33/*
34 * A long comment.
35 */
36void
37example(void)
38{
39	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
40}
41
42#define macro1 /* prefix */ suffix
43
44#define macro2 prefix		/* suffix */
45There were 10 output lines and 2 comments
46(Lines with comments)/(Lines with code):  0.571
47#indent end
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#indent end
76
77#indent run -v
78/* Demonstrates line number counting in verbose mode. */
79
80int *
81function(void)
82{
83}
84There 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