opt_v.c revision 1.11
11.11Srillig/* $NetBSD: opt_v.c,v 1.11 2023/05/11 19:01:35 rillig Exp $ */
21.1Srillig
31.2Srillig/*
41.2Srillig * Tests for the options '-v' and '-nv'.
51.2Srillig *
61.2Srillig * The option '-v' enables verbose mode. It outputs some information about
71.2Srillig * what's going on under the hood, especially when lines are broken. It also
81.2Srillig * outputs a few statistics about line counts and comments at the end.
91.2Srillig *
101.2Srillig * The option '-nv' disables verbose mode. Only errors and warnings are output
111.2Srillig * in this mode, but no progress messages.
121.2Srillig */
131.2Srillig
141.8Srillig//indent input
151.1Srillig/*
161.6Srillig * A block comment.
171.1Srillig */
181.1Srilligvoid
191.1Srilligexample(void)
201.1Srillig{
211.1Srillig	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
221.1Srillig}
231.1Srillig
241.6Srillig/* $ The below comment is neither counted nor formatted. */
251.1Srillig#define macro1 /* prefix */ suffix
261.1Srillig
271.6Srillig/* $ The below comment is formatted and counted. */
281.1Srillig#define macro2 prefix /* suffix */
291.8Srillig//indent end
301.1Srillig
311.8Srillig//indent run -v
321.1Srillig/*
331.6Srillig * A block comment.
341.1Srillig */
351.1Srilligvoid
361.1Srilligexample(void)
371.1Srillig{
381.1Srillig	printf("A very long message template with %d arguments: %s, %s, %s", 3, "first", "second", "third");
391.1Srillig}
401.1Srillig
411.1Srillig#define macro1 /* prefix */ suffix
421.1Srillig
431.11Srillig#define macro2 prefix /* suffix */
441.11SrilligThere were 12 output lines and 1 comments
451.11Srillig(Lines with comments)/(Lines with code):  0.429
461.8Srillig//indent end
471.1Srillig
481.5Srillig
491.8Srillig//indent input
501.1Srilligvoid
511.1Srilligexample(void)
521.1Srillig{
531.1Srillig	int sum1 = 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21;
541.1Srillig	int sum2 = (1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21);
551.1Srillig}
561.8Srillig//indent end
571.1Srillig
581.8Srillig//indent run -nv
591.1Srilligvoid
601.1Srilligexample(void)
611.1Srillig{
621.1Srillig/* $ XXX: The following lines are too long and should thus be broken. */
631.1Srillig/* $ XXX: If they are broken, -nv does NOT output 'Line broken'. */
641.1Srillig	int		sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21;
651.1Srillig	int		sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21);
661.1Srillig}
671.8Srillig//indent end
681.3Srillig
691.3Srillig
701.8Srillig//indent input
711.3Srillig/* Demonstrates line number counting in verbose mode. */
721.3Srillig
731.3Srilligint *function(void)
741.9Srillig{
751.9Srillig}
761.8Srillig//indent end
771.3Srillig
781.8Srillig//indent run -v
791.3Srillig/* Demonstrates line number counting in verbose mode. */
801.3Srillig
811.3Srilligint *
821.3Srilligfunction(void)
831.3Srillig{
841.3Srillig}
851.10SrilligThere were 6 output lines and 1 comments
861.3Srillig(Lines with comments)/(Lines with code):  0.250
871.8Srillig//indent end
881.3Srillig/* In the above output, the '5' means 5 non-empty lines. */
891.3Srillig
901.3Srillig/*
911.3Srillig * XXX: It's rather strange that -v writes to stdout, even in filter mode.
921.3Srillig * This output belongs on stderr instead.
931.3Srillig */
941.4Srillig
951.4Srillig
961.4Srillig/*
971.4Srillig * Test line counting in preprocessor directives.
981.4Srillig */
991.8Srillig//indent input
1001.4Srillig#if 0
1011.4Srilligint line = 1;
1021.4Srilligint line = 2;
1031.4Srilligint line = 3;
1041.4Srillig#else
1051.4Srilligint line = 5;
1061.4Srillig#endif
1071.8Srillig//indent end
1081.4Srillig
1091.8Srillig//indent run -v -di0
1101.4Srillig#if 0
1111.4Srilligint line = 1;
1121.4Srilligint line = 2;
1131.4Srilligint line = 3;
1141.4Srillig#else
1151.4Srilligint line = 5;
1161.4Srillig#endif
1171.4SrilligThere were 3 output lines and 0 comments
1181.4Srillig(Lines with comments)/(Lines with code):  0.000
1191.8Srillig//indent end
1201.4Srillig/*
1211.4Srillig * FIXME: The lines within the conditional compilation directives must be
1221.4Srillig * counted as well. TODO: Move stats out of parser_state.
1231.4Srillig */
124